From 4a706a958edbfd56595f636407887f9dc5af089c Mon Sep 17 00:00:00 2001 From: Dr-Blank <64108942+Dr-Blank@users.noreply.github.com> Date: Wed, 2 Oct 2024 08:44:58 -0400 Subject: [PATCH] refactor: update alwaysAutoTurnOnTimer default value and improve icon usage in settings --- lib/settings/models/app_settings.dart | 2 +- lib/settings/models/app_settings.freezed.dart | 2 +- lib/settings/models/app_settings.g.dart | 2 +- lib/settings/view/app_settings_page.dart | 5 ++- .../view/auto_sleep_timer_settings_page.dart | 44 +++++++++++++++---- pubspec.lock | 8 ++++ pubspec.yaml | 1 + 7 files changed, 51 insertions(+), 13 deletions(-) diff --git a/lib/settings/models/app_settings.dart b/lib/settings/models/app_settings.dart index 5e79b3e..0de013e 100644 --- a/lib/settings/models/app_settings.dart +++ b/lib/settings/models/app_settings.dart @@ -110,7 +110,7 @@ class SleepTimerSettings with _$SleepTimerSettings { @Default(false) bool autoTurnOnTimer, /// always auto turn on timer settings or during specific times - @Default(true) bool alwaysAutoTurnOnTimer, + @Default(false) bool alwaysAutoTurnOnTimer, /// auto timer settings, only used if [alwaysAutoTurnOnTimer] is false /// diff --git a/lib/settings/models/app_settings.freezed.dart b/lib/settings/models/app_settings.freezed.dart index fd578fb..6b5d8c0 100644 --- a/lib/settings/models/app_settings.freezed.dart +++ b/lib/settings/models/app_settings.freezed.dart @@ -1627,7 +1627,7 @@ class _$SleepTimerSettingsImpl implements _SleepTimerSettings { 120: Duration(minutes: 2) }, this.autoTurnOnTimer = false, - this.alwaysAutoTurnOnTimer = true, + this.alwaysAutoTurnOnTimer = false, this.autoTurnOnTime = const Duration(hours: 22, minutes: 0), this.autoTurnOffTime = const Duration(hours: 6, minutes: 0)}) : _presetDurations = presetDurations, diff --git a/lib/settings/models/app_settings.g.dart b/lib/settings/models/app_settings.g.dart index 207ac43..7d236c4 100644 --- a/lib/settings/models/app_settings.g.dart +++ b/lib/settings/models/app_settings.g.dart @@ -179,7 +179,7 @@ _$SleepTimerSettingsImpl _$$SleepTimerSettingsImplFromJson( 120: Duration(minutes: 2) }, autoTurnOnTimer: json['autoTurnOnTimer'] as bool? ?? false, - alwaysAutoTurnOnTimer: json['alwaysAutoTurnOnTimer'] as bool? ?? true, + alwaysAutoTurnOnTimer: json['alwaysAutoTurnOnTimer'] as bool? ?? false, autoTurnOnTime: json['autoTurnOnTime'] == null ? const Duration(hours: 22, minutes: 0) : Duration(microseconds: (json['autoTurnOnTime'] as num).toInt()), diff --git a/lib/settings/view/app_settings_page.dart b/lib/settings/view/app_settings_page.dart index c10b150..77afaae 100644 --- a/lib/settings/view/app_settings_page.dart +++ b/lib/settings/view/app_settings_page.dart @@ -6,6 +6,7 @@ import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_settings_ui/flutter_settings_ui.dart'; import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:material_symbols_icons/symbols.dart'; import 'package:vaani/api/authenticated_user_provider.dart'; import 'package:vaani/api/server_provider.dart'; import 'package:vaani/router/router.dart'; @@ -91,8 +92,8 @@ class AppSettingsPage 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, fill: 1) + : const Icon(Symbols.timer_off, fill: 1), onPressed: (context) { context.pushNamed(Routes.autoSleepTimerSettings.name); }, diff --git a/lib/settings/view/auto_sleep_timer_settings_page.dart b/lib/settings/view/auto_sleep_timer_settings_page.dart index 85f922f..fe7d4b3 100644 --- a/lib/settings/view/auto_sleep_timer_settings_page.dart +++ b/lib/settings/view/auto_sleep_timer_settings_page.dart @@ -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'; @@ -15,6 +16,11 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget { final appSettings = ref.watch(appSettingsProvider); 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,8 +37,8 @@ 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.sleepTimerSettings( @@ -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', ), @@ -63,16 +70,18 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget { ); } }, - 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( @@ -87,12 +96,31 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget { ); } }, - 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, + ), ], ), ], diff --git a/pubspec.lock b/pubspec.lock index 0436fc6..e675e19 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -814,6 +814,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.11.1" + material_symbols_icons: + dependency: "direct main" + description: + name: material_symbols_icons + sha256: "66416c4e30bd363508e12669634fc4f3250b83b69e862de67f4f9c480cf42414" + url: "https://pub.dev" + source: hosted + version: "4.2785.1" media_kit: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 123f6f7..aaab763 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -70,6 +70,7 @@ dependencies: list_wheel_scroll_view_nls: ^0.0.3 logging: ^1.2.0 lottie: ^3.1.0 + material_symbols_icons: ^4.2785.1 media_kit_libs_linux: any media_kit_libs_windows_audio: any miniplayer: