mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-15 07:29:30 +00:00
ui: better sleep timer ui in player and fix auto turn on settings (#43)
* refactor: enhance sleep timer functionality and improve duration formatting * refactor: update sleep timer settings handling * refactor: update cancel icon for sleep timer button * refactor: implement isBetween method for TimeOfDay and simplify sleep timer logic * refactor: update alwaysAutoTurnOnTimer default value and improve icon usage in settings * refactor: remove unused IconButton and update sleep timer preset durations
This commit is contained in:
parent
933bfc5750
commit
12100ffbcd
18 changed files with 755 additions and 383 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:vaani/settings/app_settings_provider.dart';
|
||||
import 'package:vaani/settings/view/simple_settings_page.dart';
|
||||
import 'package:vaani/shared/extensions/time_of_day.dart';
|
||||
|
|
@ -13,8 +14,13 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget {
|
|||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final appSettings = ref.watch(appSettingsProvider);
|
||||
final sleepTimerSettings = appSettings.playerSettings.sleepTimerSettings;
|
||||
final sleepTimerSettings = appSettings.sleepTimerSettings;
|
||||
|
||||
var enabled = sleepTimerSettings.autoTurnOnTimer &&
|
||||
!sleepTimerSettings.alwaysAutoTurnOnTimer;
|
||||
final selectedValueColor = enabled
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).disabledColor;
|
||||
return SimpleSettingsPage(
|
||||
title: const Text('Auto Sleep Timer Settings'),
|
||||
sections: [
|
||||
|
|
@ -31,11 +37,11 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget {
|
|||
'Automatically turn on the sleep timer based on the time of day',
|
||||
),
|
||||
leading: sleepTimerSettings.autoTurnOnTimer
|
||||
? const Icon(Icons.timer)
|
||||
: const Icon(Icons.timer_off),
|
||||
? const Icon(Symbols.time_auto)
|
||||
: const Icon(Symbols.timer_off),
|
||||
onToggle: (value) {
|
||||
ref.read(appSettingsProvider.notifier).update(
|
||||
appSettings.copyWith.playerSettings.sleepTimerSettings(
|
||||
appSettings.copyWith.sleepTimerSettings(
|
||||
autoTurnOnTimer: value,
|
||||
),
|
||||
);
|
||||
|
|
@ -44,8 +50,9 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget {
|
|||
),
|
||||
// auto turn on time settings, enabled only when autoTurnOnTimer is enabled
|
||||
SettingsTile.navigation(
|
||||
enabled: sleepTimerSettings.autoTurnOnTimer,
|
||||
title: const Text('Auto Turn On Time'),
|
||||
enabled: enabled,
|
||||
leading: const Icon(Symbols.timer_play),
|
||||
title: const Text('From'),
|
||||
description: const Text(
|
||||
'Turn on the sleep timer at the specified time',
|
||||
),
|
||||
|
|
@ -57,22 +64,24 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget {
|
|||
);
|
||||
if (selected != null) {
|
||||
ref.read(appSettingsProvider.notifier).update(
|
||||
appSettings.copyWith.playerSettings.sleepTimerSettings(
|
||||
appSettings.copyWith.sleepTimerSettings(
|
||||
autoTurnOnTime: selected.toDuration(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
value: Text(
|
||||
trailing: Text(
|
||||
sleepTimerSettings.autoTurnOnTime.toTimeOfDay().format(context),
|
||||
style: TextStyle(color: selectedValueColor),
|
||||
),
|
||||
),
|
||||
SettingsTile.navigation(
|
||||
title: const Text('Auto Turn Off Time'),
|
||||
enabled: enabled,
|
||||
leading: const Icon(Symbols.timer_pause),
|
||||
title: const Text('Until'),
|
||||
description: const Text(
|
||||
'Turn off the sleep timer at the specified time',
|
||||
),
|
||||
enabled: sleepTimerSettings.autoTurnOnTimer,
|
||||
onPressed: (context) async {
|
||||
// navigate to the time picker
|
||||
final selected = await showTimePicker(
|
||||
|
|
@ -81,18 +90,37 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget {
|
|||
);
|
||||
if (selected != null) {
|
||||
ref.read(appSettingsProvider.notifier).update(
|
||||
appSettings.copyWith.playerSettings.sleepTimerSettings(
|
||||
appSettings.copyWith.sleepTimerSettings(
|
||||
autoTurnOffTime: selected.toDuration(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
value: Text(
|
||||
trailing: Text(
|
||||
sleepTimerSettings.autoTurnOffTime
|
||||
.toTimeOfDay()
|
||||
.format(context),
|
||||
style: TextStyle(color: selectedValueColor),
|
||||
),
|
||||
),
|
||||
|
||||
// switch tile for always auto turn on timer no matter what
|
||||
SettingsTile.switchTile(
|
||||
leading: const Icon(Symbols.all_inclusive),
|
||||
title: const Text('Always Auto Turn On Timer'),
|
||||
description: const Text(
|
||||
'Always turn on the sleep timer, no matter what',
|
||||
),
|
||||
onToggle: (value) {
|
||||
ref.read(appSettingsProvider.notifier).update(
|
||||
appSettings.copyWith.sleepTimerSettings(
|
||||
alwaysAutoTurnOnTimer: value,
|
||||
),
|
||||
);
|
||||
},
|
||||
enabled: sleepTimerSettings.autoTurnOnTimer,
|
||||
initialValue: sleepTimerSettings.alwaysAutoTurnOnTimer,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue