feat(ui): refine navigation and sleep timer
This commit is contained in:
@@ -87,6 +87,21 @@ class EstadoRadio extends ChangeNotifier {
|
||||
String? _ultimoTagBusqueda;
|
||||
String? _errorCarga;
|
||||
static const _keyEmisoraPreferida = 'emisora_preferida_uuid_v1';
|
||||
static const _keyTimerSuenoPresets = 'timer_sueno_presets_segundos_v1';
|
||||
static const _timerSuenoPresetsDefecto = <int>[
|
||||
180,
|
||||
300,
|
||||
600,
|
||||
900,
|
||||
1800,
|
||||
3600,
|
||||
5400,
|
||||
7200,
|
||||
10800,
|
||||
];
|
||||
List<int> _timerSuenoPresetsSegundos = List<int>.from(
|
||||
_timerSuenoPresetsDefecto,
|
||||
);
|
||||
|
||||
List<Emisora> get populares => _populares;
|
||||
List<Emisora> get tendencias => _tendencias;
|
||||
@@ -110,6 +125,8 @@ class EstadoRadio extends ChangeNotifier {
|
||||
PresetEcualizador get presetPrincipalEcualizador => _presetPrincipal;
|
||||
bool get ecualizadorActivo => _ecualizadorActivo;
|
||||
bool get ecualizadorDisponible => audio.ecualizadorDisponible;
|
||||
List<int> get timerSuenoPresetsSegundos =>
|
||||
List<int>.unmodifiable(_timerSuenoPresetsSegundos);
|
||||
|
||||
bool get emisoraActualEsFavorita {
|
||||
final actual = emisoraActual;
|
||||
@@ -171,6 +188,7 @@ class EstadoRadio extends ChangeNotifier {
|
||||
await grabacion.inicializar();
|
||||
await _cargarEcualizadorPersistido();
|
||||
await _cargarEmisoraPreferida();
|
||||
await _cargarTimerSuenoPresets();
|
||||
await Future.wait([
|
||||
cargarPopulares(),
|
||||
cargarFavoritos(),
|
||||
@@ -260,6 +278,29 @@ class EstadoRadio extends ChangeNotifier {
|
||||
await reproducir(preferida);
|
||||
}
|
||||
|
||||
Future<void> _cargarTimerSuenoPresets() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final raw = prefs.getString(_keyTimerSuenoPresets);
|
||||
if (raw == null) return;
|
||||
final decoded = jsonDecode(raw);
|
||||
if (decoded is! List) return;
|
||||
final presets =
|
||||
decoded
|
||||
.whereType<num>()
|
||||
.map((n) => n.toInt())
|
||||
.where((s) => s > 0)
|
||||
.toSet()
|
||||
.toList()
|
||||
..sort();
|
||||
if (presets.isNotEmpty) {
|
||||
_timerSuenoPresetsSegundos = presets.take(12).toList();
|
||||
}
|
||||
} catch (_) {
|
||||
_timerSuenoPresetsSegundos = List<int>.from(_timerSuenoPresetsDefecto);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _cargarEmisoraPreferida() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_emisoraPreferidaUuid = prefs.getString(_keyEmisoraPreferida);
|
||||
@@ -749,11 +790,56 @@ class EstadoRadio extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void iniciarTimerDuracion(Duration duracion) {
|
||||
timer.iniciarDuracion(duracion);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void cancelarTimer() {
|
||||
unawaited(timer.cancelar());
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> guardarTimerSuenoPresetsSegundos(List<int> segundos) async {
|
||||
final normalizados =
|
||||
segundos
|
||||
.where((s) => s > 0)
|
||||
.map((s) => s.clamp(1, const Duration(hours: 23).inSeconds))
|
||||
.toSet()
|
||||
.toList()
|
||||
..sort();
|
||||
_timerSuenoPresetsSegundos =
|
||||
normalizados.isEmpty
|
||||
? List<int>.from(_timerSuenoPresetsDefecto)
|
||||
: normalizados.take(12).toList();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(
|
||||
_keyTimerSuenoPresets,
|
||||
jsonEncode(_timerSuenoPresetsSegundos),
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> agregarTimerSuenoPreset(Duration duracion) async {
|
||||
await guardarTimerSuenoPresetsSegundos([
|
||||
..._timerSuenoPresetsSegundos,
|
||||
duracion.inSeconds,
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> eliminarTimerSuenoPreset(int segundos) async {
|
||||
await guardarTimerSuenoPresetsSegundos(
|
||||
_timerSuenoPresetsSegundos.where((s) => s != segundos).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> restaurarTimerSuenoPresets() async {
|
||||
_timerSuenoPresetsSegundos = List<int>.from(_timerSuenoPresetsDefecto);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(_keyTimerSuenoPresets);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_suscripcionEstadoAudio?.cancel();
|
||||
|
||||
Reference in New Issue
Block a user