refactor: update alwaysAutoTurnOnTimer default value and improve icon usage in settings

This commit is contained in:
Dr-Blank 2024-10-02 08:44:58 -04:00
parent 4abd944a0c
commit 4a706a958e
No known key found for this signature in database
GPG key ID: 7452CC63F210A266
7 changed files with 51 additions and 13 deletions

View file

@ -110,7 +110,7 @@ class SleepTimerSettings with _$SleepTimerSettings {
@Default(false) bool autoTurnOnTimer, @Default(false) bool autoTurnOnTimer,
/// always auto turn on timer settings or during specific times /// 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 /// auto timer settings, only used if [alwaysAutoTurnOnTimer] is false
/// ///

View file

@ -1627,7 +1627,7 @@ class _$SleepTimerSettingsImpl implements _SleepTimerSettings {
120: Duration(minutes: 2) 120: Duration(minutes: 2)
}, },
this.autoTurnOnTimer = false, this.autoTurnOnTimer = false,
this.alwaysAutoTurnOnTimer = true, this.alwaysAutoTurnOnTimer = false,
this.autoTurnOnTime = const Duration(hours: 22, minutes: 0), this.autoTurnOnTime = const Duration(hours: 22, minutes: 0),
this.autoTurnOffTime = const Duration(hours: 6, minutes: 0)}) this.autoTurnOffTime = const Duration(hours: 6, minutes: 0)})
: _presetDurations = presetDurations, : _presetDurations = presetDurations,

View file

@ -179,7 +179,7 @@ _$SleepTimerSettingsImpl _$$SleepTimerSettingsImplFromJson(
120: Duration(minutes: 2) 120: Duration(minutes: 2)
}, },
autoTurnOnTimer: json['autoTurnOnTimer'] as bool? ?? false, autoTurnOnTimer: json['autoTurnOnTimer'] as bool? ?? false,
alwaysAutoTurnOnTimer: json['alwaysAutoTurnOnTimer'] as bool? ?? true, alwaysAutoTurnOnTimer: json['alwaysAutoTurnOnTimer'] as bool? ?? false,
autoTurnOnTime: json['autoTurnOnTime'] == null autoTurnOnTime: json['autoTurnOnTime'] == null
? const Duration(hours: 22, minutes: 0) ? const Duration(hours: 22, minutes: 0)
: Duration(microseconds: (json['autoTurnOnTime'] as num).toInt()), : Duration(microseconds: (json['autoTurnOnTime'] as num).toInt()),

View file

@ -6,6 +6,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_settings_ui/flutter_settings_ui.dart'; import 'package:flutter_settings_ui/flutter_settings_ui.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.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/authenticated_user_provider.dart';
import 'package:vaani/api/server_provider.dart'; import 'package:vaani/api/server_provider.dart';
import 'package:vaani/router/router.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', 'Automatically turn on the sleep timer based on the time of day',
), ),
leading: sleepTimerSettings.autoTurnOnTimer leading: sleepTimerSettings.autoTurnOnTimer
? const Icon(Icons.timer) ? const Icon(Symbols.time_auto, fill: 1)
: const Icon(Icons.timer_off), : const Icon(Symbols.timer_off, fill: 1),
onPressed: (context) { onPressed: (context) {
context.pushNamed(Routes.autoSleepTimerSettings.name); context.pushNamed(Routes.autoSleepTimerSettings.name);
}, },

View file

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_settings_ui/flutter_settings_ui.dart'; import 'package:flutter_settings_ui/flutter_settings_ui.dart';
import 'package:hooks_riverpod/hooks_riverpod.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/app_settings_provider.dart';
import 'package:vaani/settings/view/simple_settings_page.dart'; import 'package:vaani/settings/view/simple_settings_page.dart';
import 'package:vaani/shared/extensions/time_of_day.dart'; import 'package:vaani/shared/extensions/time_of_day.dart';
@ -15,6 +16,11 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget {
final appSettings = ref.watch(appSettingsProvider); final appSettings = ref.watch(appSettingsProvider);
final sleepTimerSettings = appSettings.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( return SimpleSettingsPage(
title: const Text('Auto Sleep Timer Settings'), title: const Text('Auto Sleep Timer Settings'),
sections: [ sections: [
@ -31,8 +37,8 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget {
'Automatically turn on the sleep timer based on the time of day', 'Automatically turn on the sleep timer based on the time of day',
), ),
leading: sleepTimerSettings.autoTurnOnTimer leading: sleepTimerSettings.autoTurnOnTimer
? const Icon(Icons.timer) ? const Icon(Symbols.time_auto)
: const Icon(Icons.timer_off), : const Icon(Symbols.timer_off),
onToggle: (value) { onToggle: (value) {
ref.read(appSettingsProvider.notifier).update( ref.read(appSettingsProvider.notifier).update(
appSettings.copyWith.sleepTimerSettings( appSettings.copyWith.sleepTimerSettings(
@ -44,8 +50,9 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget {
), ),
// auto turn on time settings, enabled only when autoTurnOnTimer is enabled // auto turn on time settings, enabled only when autoTurnOnTimer is enabled
SettingsTile.navigation( SettingsTile.navigation(
enabled: sleepTimerSettings.autoTurnOnTimer, enabled: enabled,
title: const Text('Auto Turn On Time'), leading: const Icon(Symbols.timer_play),
title: const Text('From'),
description: const Text( description: const Text(
'Turn on the sleep timer at the specified time', '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), sleepTimerSettings.autoTurnOnTime.toTimeOfDay().format(context),
style: TextStyle(color: selectedValueColor),
), ),
), ),
SettingsTile.navigation( SettingsTile.navigation(
title: const Text('Auto Turn Off Time'), enabled: enabled,
leading: const Icon(Symbols.timer_pause),
title: const Text('Until'),
description: const Text( description: const Text(
'Turn off the sleep timer at the specified time', 'Turn off the sleep timer at the specified time',
), ),
enabled: sleepTimerSettings.autoTurnOnTimer,
onPressed: (context) async { onPressed: (context) async {
// navigate to the time picker // navigate to the time picker
final selected = await showTimePicker( final selected = await showTimePicker(
@ -87,12 +96,31 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget {
); );
} }
}, },
value: Text( trailing: Text(
sleepTimerSettings.autoTurnOffTime sleepTimerSettings.autoTurnOffTime
.toTimeOfDay() .toTimeOfDay()
.format(context), .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,
),
], ],
), ),
], ],

View file

@ -814,6 +814,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.11.1" 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: media_kit:
dependency: transitive dependency: transitive
description: description:

View file

@ -70,6 +70,7 @@ dependencies:
list_wheel_scroll_view_nls: ^0.0.3 list_wheel_scroll_view_nls: ^0.0.3
logging: ^1.2.0 logging: ^1.2.0
lottie: ^3.1.0 lottie: ^3.1.0
material_symbols_icons: ^4.2785.1
media_kit_libs_linux: any media_kit_libs_linux: any
media_kit_libs_windows_audio: any media_kit_libs_windows_audio: any
miniplayer: miniplayer: