diff --git a/lib/features/sleep_timer/providers/sleep_timer_provider.dart b/lib/features/sleep_timer/providers/sleep_timer_provider.dart index d9db355..efcae37 100644 --- a/lib/features/sleep_timer/providers/sleep_timer_provider.dart +++ b/lib/features/sleep_timer/providers/sleep_timer_provider.dart @@ -11,20 +11,16 @@ part 'sleep_timer_provider.g.dart'; class SleepTimer extends _$SleepTimer { @override core.SleepTimer? build() { - final appSettings = ref.watch(appSettingsProvider); - final sleepTimerSettings = appSettings.playerSettings.sleepTimerSettings; - bool isEnabled = sleepTimerSettings.autoTurnOnTimer; - if (!isEnabled) { + final sleepTimerSettings = ref.watch(sleepTimerSettingsProvider); + if (!sleepTimerSettings.autoTurnOnTimer) { return null; } if ((!sleepTimerSettings.alwaysAutoTurnOnTimer) && - (sleepTimerSettings.autoTurnOnTime - .toTimeOfDay() - .isAfter(TimeOfDay.now()) && - sleepTimerSettings.autoTurnOffTime - .toTimeOfDay() - .isBefore(TimeOfDay.now()))) { + !shouldBuildRightNow( + sleepTimerSettings.autoTurnOnTime, + sleepTimerSettings.autoTurnOffTime, + )) { return null; } @@ -68,3 +64,9 @@ class SleepTimer extends _$SleepTimer { state = null; } } + +bool shouldBuildRightNow(Duration autoTurnOnTime, Duration autoTurnOffTime) { + final now = TimeOfDay.now(); + return autoTurnOnTime.toTimeOfDay().isBefore(now) && + autoTurnOffTime.toTimeOfDay().isAfter(now); +} diff --git a/lib/features/sleep_timer/providers/sleep_timer_provider.g.dart b/lib/features/sleep_timer/providers/sleep_timer_provider.g.dart index b0bfd9c..7daade0 100644 --- a/lib/features/sleep_timer/providers/sleep_timer_provider.g.dart +++ b/lib/features/sleep_timer/providers/sleep_timer_provider.g.dart @@ -6,7 +6,7 @@ part of 'sleep_timer_provider.dart'; // RiverpodGenerator // ************************************************************************** -String _$sleepTimerHash() => r'722bebfb7367acb84aacd98da66c5858b7e446cd'; +String _$sleepTimerHash() => r'2679454a217d0630a833d730557ab4e4feac2e56'; /// See also [SleepTimer]. @ProviderFor(SleepTimer) diff --git a/lib/features/sleep_timer/view/sleep_timer_button.dart b/lib/features/sleep_timer/view/sleep_timer_button.dart index 9b1a07d..6fce536 100644 --- a/lib/features/sleep_timer/view/sleep_timer_button.dart +++ b/lib/features/sleep_timer/view/sleep_timer_button.dart @@ -77,8 +77,7 @@ class SleepTimerBottomSheet extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final sleepTimer = ref.watch(sleepTimerProvider); - final sleepTimerSettings = - ref.watch(appSettingsProvider).playerSettings.sleepTimerSettings; + final sleepTimerSettings = ref.watch(sleepTimerSettingsProvider); final durationOptions = sleepTimerSettings.presetDurations; final minDuration = Duration.zero; diff --git a/lib/settings/app_settings_provider.dart b/lib/settings/app_settings_provider.dart index 662a043..6d61774 100644 --- a/lib/settings/app_settings_provider.dart +++ b/lib/settings/app_settings_provider.dart @@ -60,3 +60,19 @@ class AppSettings extends _$AppSettings { state = const model.AppSettings(); } } + +// SleepTimerSettings provider but only rebuilds when the sleep timer settings change +@Riverpod(keepAlive: true) +class SleepTimerSettings extends _$SleepTimerSettings { + @override + model.SleepTimerSettings build() { + final settings = ref.read(appSettingsProvider).sleepTimerSettings; + state = settings; + ref.listen(appSettingsProvider, (a, b) { + if (a?.sleepTimerSettings != b.sleepTimerSettings) { + state = b.sleepTimerSettings; + } + }); + return state; + } +} diff --git a/lib/settings/app_settings_provider.g.dart b/lib/settings/app_settings_provider.g.dart index 2f321ee..df95738 100644 --- a/lib/settings/app_settings_provider.g.dart +++ b/lib/settings/app_settings_provider.g.dart @@ -21,5 +21,22 @@ final appSettingsProvider = ); typedef _$AppSettings = Notifier; +String _$sleepTimerSettingsHash() => + r'85bb3d3fb292b9a3a5b771d86e5fc57718519c69'; + +/// See also [SleepTimerSettings]. +@ProviderFor(SleepTimerSettings) +final sleepTimerSettingsProvider = + NotifierProvider.internal( + SleepTimerSettings.new, + name: r'sleepTimerSettingsProvider', + debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') + ? null + : _$sleepTimerSettingsHash, + dependencies: null, + allTransitiveDependencies: null, +); + +typedef _$SleepTimerSettings = Notifier; // ignore_for_file: type=lint // ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member diff --git a/lib/settings/models/app_settings.dart b/lib/settings/models/app_settings.dart index a5ce0a0..5e79b3e 100644 --- a/lib/settings/models/app_settings.dart +++ b/lib/settings/models/app_settings.dart @@ -14,6 +14,7 @@ class AppSettings with _$AppSettings { const factory AppSettings({ @Default(ThemeSettings()) ThemeSettings themeSettings, @Default(PlayerSettings()) PlayerSettings playerSettings, + @Default(SleepTimerSettings()) SleepTimerSettings sleepTimerSettings, @Default(DownloadSettings()) DownloadSettings downloadSettings, @Default(NotificationSettings()) NotificationSettings notificationSettings, @Default(ShakeDetectionSettings()) @@ -49,7 +50,6 @@ class PlayerSettings with _$PlayerSettings { @Default(0.05) double speedIncrement, @Default(0.1) double minSpeed, @Default(4) double maxSpeed, - @Default(SleepTimerSettings()) SleepTimerSettings sleepTimerSettings, @Default(Duration(seconds: 10)) Duration minimumPositionForReporting, @Default(Duration(seconds: 10)) Duration playbackReportInterval, @Default(Duration(seconds: 15)) Duration markCompleteWhenTimeLeft, diff --git a/lib/settings/models/app_settings.freezed.dart b/lib/settings/models/app_settings.freezed.dart index b53c4ce..fd578fb 100644 --- a/lib/settings/models/app_settings.freezed.dart +++ b/lib/settings/models/app_settings.freezed.dart @@ -22,6 +22,8 @@ AppSettings _$AppSettingsFromJson(Map json) { mixin _$AppSettings { ThemeSettings get themeSettings => throw _privateConstructorUsedError; PlayerSettings get playerSettings => throw _privateConstructorUsedError; + SleepTimerSettings get sleepTimerSettings => + throw _privateConstructorUsedError; DownloadSettings get downloadSettings => throw _privateConstructorUsedError; NotificationSettings get notificationSettings => throw _privateConstructorUsedError; @@ -47,12 +49,14 @@ abstract class $AppSettingsCopyWith<$Res> { $Res call( {ThemeSettings themeSettings, PlayerSettings playerSettings, + SleepTimerSettings sleepTimerSettings, DownloadSettings downloadSettings, NotificationSettings notificationSettings, ShakeDetectionSettings shakeDetectionSettings}); $ThemeSettingsCopyWith<$Res> get themeSettings; $PlayerSettingsCopyWith<$Res> get playerSettings; + $SleepTimerSettingsCopyWith<$Res> get sleepTimerSettings; $DownloadSettingsCopyWith<$Res> get downloadSettings; $NotificationSettingsCopyWith<$Res> get notificationSettings; $ShakeDetectionSettingsCopyWith<$Res> get shakeDetectionSettings; @@ -75,6 +79,7 @@ class _$AppSettingsCopyWithImpl<$Res, $Val extends AppSettings> $Res call({ Object? themeSettings = null, Object? playerSettings = null, + Object? sleepTimerSettings = null, Object? downloadSettings = null, Object? notificationSettings = null, Object? shakeDetectionSettings = null, @@ -88,6 +93,10 @@ class _$AppSettingsCopyWithImpl<$Res, $Val extends AppSettings> ? _value.playerSettings : playerSettings // ignore: cast_nullable_to_non_nullable as PlayerSettings, + sleepTimerSettings: null == sleepTimerSettings + ? _value.sleepTimerSettings + : sleepTimerSettings // ignore: cast_nullable_to_non_nullable + as SleepTimerSettings, downloadSettings: null == downloadSettings ? _value.downloadSettings : downloadSettings // ignore: cast_nullable_to_non_nullable @@ -123,6 +132,17 @@ class _$AppSettingsCopyWithImpl<$Res, $Val extends AppSettings> }); } + /// Create a copy of AppSettings + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $SleepTimerSettingsCopyWith<$Res> get sleepTimerSettings { + return $SleepTimerSettingsCopyWith<$Res>(_value.sleepTimerSettings, + (value) { + return _then(_value.copyWith(sleepTimerSettings: value) as $Val); + }); + } + /// Create a copy of AppSettings /// with the given fields replaced by the non-null parameter values. @override @@ -167,6 +187,7 @@ abstract class _$$AppSettingsImplCopyWith<$Res> $Res call( {ThemeSettings themeSettings, PlayerSettings playerSettings, + SleepTimerSettings sleepTimerSettings, DownloadSettings downloadSettings, NotificationSettings notificationSettings, ShakeDetectionSettings shakeDetectionSettings}); @@ -176,6 +197,8 @@ abstract class _$$AppSettingsImplCopyWith<$Res> @override $PlayerSettingsCopyWith<$Res> get playerSettings; @override + $SleepTimerSettingsCopyWith<$Res> get sleepTimerSettings; + @override $DownloadSettingsCopyWith<$Res> get downloadSettings; @override $NotificationSettingsCopyWith<$Res> get notificationSettings; @@ -198,6 +221,7 @@ class __$$AppSettingsImplCopyWithImpl<$Res> $Res call({ Object? themeSettings = null, Object? playerSettings = null, + Object? sleepTimerSettings = null, Object? downloadSettings = null, Object? notificationSettings = null, Object? shakeDetectionSettings = null, @@ -211,6 +235,10 @@ class __$$AppSettingsImplCopyWithImpl<$Res> ? _value.playerSettings : playerSettings // ignore: cast_nullable_to_non_nullable as PlayerSettings, + sleepTimerSettings: null == sleepTimerSettings + ? _value.sleepTimerSettings + : sleepTimerSettings // ignore: cast_nullable_to_non_nullable + as SleepTimerSettings, downloadSettings: null == downloadSettings ? _value.downloadSettings : downloadSettings // ignore: cast_nullable_to_non_nullable @@ -233,6 +261,7 @@ class _$AppSettingsImpl implements _AppSettings { const _$AppSettingsImpl( {this.themeSettings = const ThemeSettings(), this.playerSettings = const PlayerSettings(), + this.sleepTimerSettings = const SleepTimerSettings(), this.downloadSettings = const DownloadSettings(), this.notificationSettings = const NotificationSettings(), this.shakeDetectionSettings = const ShakeDetectionSettings()}); @@ -248,6 +277,9 @@ class _$AppSettingsImpl implements _AppSettings { final PlayerSettings playerSettings; @override @JsonKey() + final SleepTimerSettings sleepTimerSettings; + @override + @JsonKey() final DownloadSettings downloadSettings; @override @JsonKey() @@ -258,7 +290,7 @@ class _$AppSettingsImpl implements _AppSettings { @override String toString() { - return 'AppSettings(themeSettings: $themeSettings, playerSettings: $playerSettings, downloadSettings: $downloadSettings, notificationSettings: $notificationSettings, shakeDetectionSettings: $shakeDetectionSettings)'; + return 'AppSettings(themeSettings: $themeSettings, playerSettings: $playerSettings, sleepTimerSettings: $sleepTimerSettings, downloadSettings: $downloadSettings, notificationSettings: $notificationSettings, shakeDetectionSettings: $shakeDetectionSettings)'; } @override @@ -270,6 +302,8 @@ class _$AppSettingsImpl implements _AppSettings { other.themeSettings == themeSettings) && (identical(other.playerSettings, playerSettings) || other.playerSettings == playerSettings) && + (identical(other.sleepTimerSettings, sleepTimerSettings) || + other.sleepTimerSettings == sleepTimerSettings) && (identical(other.downloadSettings, downloadSettings) || other.downloadSettings == downloadSettings) && (identical(other.notificationSettings, notificationSettings) || @@ -280,8 +314,14 @@ class _$AppSettingsImpl implements _AppSettings { @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash(runtimeType, themeSettings, playerSettings, - downloadSettings, notificationSettings, shakeDetectionSettings); + int get hashCode => Object.hash( + runtimeType, + themeSettings, + playerSettings, + sleepTimerSettings, + downloadSettings, + notificationSettings, + shakeDetectionSettings); /// Create a copy of AppSettings /// with the given fields replaced by the non-null parameter values. @@ -303,6 +343,7 @@ abstract class _AppSettings implements AppSettings { const factory _AppSettings( {final ThemeSettings themeSettings, final PlayerSettings playerSettings, + final SleepTimerSettings sleepTimerSettings, final DownloadSettings downloadSettings, final NotificationSettings notificationSettings, final ShakeDetectionSettings shakeDetectionSettings}) = _$AppSettingsImpl; @@ -315,6 +356,8 @@ abstract class _AppSettings implements AppSettings { @override PlayerSettings get playerSettings; @override + SleepTimerSettings get sleepTimerSettings; + @override DownloadSettings get downloadSettings; @override NotificationSettings get notificationSettings; @@ -552,8 +595,6 @@ mixin _$PlayerSettings { double get speedIncrement => throw _privateConstructorUsedError; double get minSpeed => throw _privateConstructorUsedError; double get maxSpeed => throw _privateConstructorUsedError; - SleepTimerSettings get sleepTimerSettings => - throw _privateConstructorUsedError; Duration get minimumPositionForReporting => throw _privateConstructorUsedError; Duration get playbackReportInterval => throw _privateConstructorUsedError; @@ -585,7 +626,6 @@ abstract class $PlayerSettingsCopyWith<$Res> { double speedIncrement, double minSpeed, double maxSpeed, - SleepTimerSettings sleepTimerSettings, Duration minimumPositionForReporting, Duration playbackReportInterval, Duration markCompleteWhenTimeLeft, @@ -593,7 +633,6 @@ abstract class $PlayerSettingsCopyWith<$Res> { $MinimizedPlayerSettingsCopyWith<$Res> get miniPlayerSettings; $ExpandedPlayerSettingsCopyWith<$Res> get expandedPlayerSettings; - $SleepTimerSettingsCopyWith<$Res> get sleepTimerSettings; } /// @nodoc @@ -619,7 +658,6 @@ class _$PlayerSettingsCopyWithImpl<$Res, $Val extends PlayerSettings> Object? speedIncrement = null, Object? minSpeed = null, Object? maxSpeed = null, - Object? sleepTimerSettings = null, Object? minimumPositionForReporting = null, Object? playbackReportInterval = null, Object? markCompleteWhenTimeLeft = null, @@ -658,10 +696,6 @@ class _$PlayerSettingsCopyWithImpl<$Res, $Val extends PlayerSettings> ? _value.maxSpeed : maxSpeed // ignore: cast_nullable_to_non_nullable as double, - sleepTimerSettings: null == sleepTimerSettings - ? _value.sleepTimerSettings - : sleepTimerSettings // ignore: cast_nullable_to_non_nullable - as SleepTimerSettings, minimumPositionForReporting: null == minimumPositionForReporting ? _value.minimumPositionForReporting : minimumPositionForReporting // ignore: cast_nullable_to_non_nullable @@ -702,17 +736,6 @@ class _$PlayerSettingsCopyWithImpl<$Res, $Val extends PlayerSettings> return _then(_value.copyWith(expandedPlayerSettings: value) as $Val); }); } - - /// Create a copy of PlayerSettings - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $SleepTimerSettingsCopyWith<$Res> get sleepTimerSettings { - return $SleepTimerSettingsCopyWith<$Res>(_value.sleepTimerSettings, - (value) { - return _then(_value.copyWith(sleepTimerSettings: value) as $Val); - }); - } } /// @nodoc @@ -732,7 +755,6 @@ abstract class _$$PlayerSettingsImplCopyWith<$Res> double speedIncrement, double minSpeed, double maxSpeed, - SleepTimerSettings sleepTimerSettings, Duration minimumPositionForReporting, Duration playbackReportInterval, Duration markCompleteWhenTimeLeft, @@ -742,8 +764,6 @@ abstract class _$$PlayerSettingsImplCopyWith<$Res> $MinimizedPlayerSettingsCopyWith<$Res> get miniPlayerSettings; @override $ExpandedPlayerSettingsCopyWith<$Res> get expandedPlayerSettings; - @override - $SleepTimerSettingsCopyWith<$Res> get sleepTimerSettings; } /// @nodoc @@ -767,7 +787,6 @@ class __$$PlayerSettingsImplCopyWithImpl<$Res> Object? speedIncrement = null, Object? minSpeed = null, Object? maxSpeed = null, - Object? sleepTimerSettings = null, Object? minimumPositionForReporting = null, Object? playbackReportInterval = null, Object? markCompleteWhenTimeLeft = null, @@ -806,10 +825,6 @@ class __$$PlayerSettingsImplCopyWithImpl<$Res> ? _value.maxSpeed : maxSpeed // ignore: cast_nullable_to_non_nullable as double, - sleepTimerSettings: null == sleepTimerSettings - ? _value.sleepTimerSettings - : sleepTimerSettings // ignore: cast_nullable_to_non_nullable - as SleepTimerSettings, minimumPositionForReporting: null == minimumPositionForReporting ? _value.minimumPositionForReporting : minimumPositionForReporting // ignore: cast_nullable_to_non_nullable @@ -842,7 +857,6 @@ class _$PlayerSettingsImpl implements _PlayerSettings { this.speedIncrement = 0.05, this.minSpeed = 0.1, this.maxSpeed = 4, - this.sleepTimerSettings = const SleepTimerSettings(), this.minimumPositionForReporting = const Duration(seconds: 10), this.playbackReportInterval = const Duration(seconds: 10), this.markCompleteWhenTimeLeft = const Duration(seconds: 15), @@ -884,9 +898,6 @@ class _$PlayerSettingsImpl implements _PlayerSettings { final double maxSpeed; @override @JsonKey() - final SleepTimerSettings sleepTimerSettings; - @override - @JsonKey() final Duration minimumPositionForReporting; @override @JsonKey() @@ -900,7 +911,7 @@ class _$PlayerSettingsImpl implements _PlayerSettings { @override String toString() { - return 'PlayerSettings(miniPlayerSettings: $miniPlayerSettings, expandedPlayerSettings: $expandedPlayerSettings, preferredDefaultVolume: $preferredDefaultVolume, preferredDefaultSpeed: $preferredDefaultSpeed, speedOptions: $speedOptions, speedIncrement: $speedIncrement, minSpeed: $minSpeed, maxSpeed: $maxSpeed, sleepTimerSettings: $sleepTimerSettings, minimumPositionForReporting: $minimumPositionForReporting, playbackReportInterval: $playbackReportInterval, markCompleteWhenTimeLeft: $markCompleteWhenTimeLeft, configurePlayerForEveryBook: $configurePlayerForEveryBook)'; + return 'PlayerSettings(miniPlayerSettings: $miniPlayerSettings, expandedPlayerSettings: $expandedPlayerSettings, preferredDefaultVolume: $preferredDefaultVolume, preferredDefaultSpeed: $preferredDefaultSpeed, speedOptions: $speedOptions, speedIncrement: $speedIncrement, minSpeed: $minSpeed, maxSpeed: $maxSpeed, minimumPositionForReporting: $minimumPositionForReporting, playbackReportInterval: $playbackReportInterval, markCompleteWhenTimeLeft: $markCompleteWhenTimeLeft, configurePlayerForEveryBook: $configurePlayerForEveryBook)'; } @override @@ -924,8 +935,6 @@ class _$PlayerSettingsImpl implements _PlayerSettings { other.minSpeed == minSpeed) && (identical(other.maxSpeed, maxSpeed) || other.maxSpeed == maxSpeed) && - (identical(other.sleepTimerSettings, sleepTimerSettings) || - other.sleepTimerSettings == sleepTimerSettings) && (identical(other.minimumPositionForReporting, minimumPositionForReporting) || other.minimumPositionForReporting == @@ -953,7 +962,6 @@ class _$PlayerSettingsImpl implements _PlayerSettings { speedIncrement, minSpeed, maxSpeed, - sleepTimerSettings, minimumPositionForReporting, playbackReportInterval, markCompleteWhenTimeLeft, @@ -986,7 +994,6 @@ abstract class _PlayerSettings implements PlayerSettings { final double speedIncrement, final double minSpeed, final double maxSpeed, - final SleepTimerSettings sleepTimerSettings, final Duration minimumPositionForReporting, final Duration playbackReportInterval, final Duration markCompleteWhenTimeLeft, @@ -1012,8 +1019,6 @@ abstract class _PlayerSettings implements PlayerSettings { @override double get maxSpeed; @override - SleepTimerSettings get sleepTimerSettings; - @override Duration get minimumPositionForReporting; @override Duration get playbackReportInterval; diff --git a/lib/settings/models/app_settings.g.dart b/lib/settings/models/app_settings.g.dart index 0dfb5e9..207ac43 100644 --- a/lib/settings/models/app_settings.g.dart +++ b/lib/settings/models/app_settings.g.dart @@ -16,6 +16,10 @@ _$AppSettingsImpl _$$AppSettingsImplFromJson(Map json) => ? const PlayerSettings() : PlayerSettings.fromJson( json['playerSettings'] as Map), + sleepTimerSettings: json['sleepTimerSettings'] == null + ? const SleepTimerSettings() + : SleepTimerSettings.fromJson( + json['sleepTimerSettings'] as Map), downloadSettings: json['downloadSettings'] == null ? const DownloadSettings() : DownloadSettings.fromJson( @@ -34,6 +38,7 @@ Map _$$AppSettingsImplToJson(_$AppSettingsImpl instance) => { 'themeSettings': instance.themeSettings, 'playerSettings': instance.playerSettings, + 'sleepTimerSettings': instance.sleepTimerSettings, 'downloadSettings': instance.downloadSettings, 'notificationSettings': instance.notificationSettings, 'shakeDetectionSettings': instance.shakeDetectionSettings, @@ -77,10 +82,6 @@ _$PlayerSettingsImpl _$$PlayerSettingsImplFromJson(Map json) => speedIncrement: (json['speedIncrement'] as num?)?.toDouble() ?? 0.05, minSpeed: (json['minSpeed'] as num?)?.toDouble() ?? 0.1, maxSpeed: (json['maxSpeed'] as num?)?.toDouble() ?? 4, - sleepTimerSettings: json['sleepTimerSettings'] == null - ? const SleepTimerSettings() - : SleepTimerSettings.fromJson( - json['sleepTimerSettings'] as Map), minimumPositionForReporting: json['minimumPositionForReporting'] == null ? const Duration(seconds: 10) : Duration( @@ -109,7 +110,6 @@ Map _$$PlayerSettingsImplToJson( 'speedIncrement': instance.speedIncrement, 'minSpeed': instance.minSpeed, 'maxSpeed': instance.maxSpeed, - 'sleepTimerSettings': instance.sleepTimerSettings, 'minimumPositionForReporting': instance.minimumPositionForReporting.inMicroseconds, 'playbackReportInterval': instance.playbackReportInterval.inMicroseconds, diff --git a/lib/settings/view/app_settings_page.dart b/lib/settings/view/app_settings_page.dart index 58754c6..c10b150 100644 --- a/lib/settings/view/app_settings_page.dart +++ b/lib/settings/view/app_settings_page.dart @@ -26,7 +26,7 @@ class AppSettingsPage extends HookConsumerWidget { final registeredServersAsList = registeredServers.toList(); final availableUsers = ref.watch(authenticatedUserProvider); final serverURIController = useTextEditingController(); - final sleepTimerSettings = appSettings.playerSettings.sleepTimerSettings; + final sleepTimerSettings = appSettings.sleepTimerSettings; return SimpleSettingsPage( title: const Text('App Settings'), @@ -99,7 +99,7 @@ class AppSettingsPage extends HookConsumerWidget { value: sleepTimerSettings.autoTurnOnTimer, onToggle: (value) { ref.read(appSettingsProvider.notifier).update( - appSettings.copyWith.playerSettings.sleepTimerSettings( + appSettings.copyWith.sleepTimerSettings( autoTurnOnTimer: value, ), ); diff --git a/lib/settings/view/auto_sleep_timer_settings_page.dart b/lib/settings/view/auto_sleep_timer_settings_page.dart index 29524a9..85f922f 100644 --- a/lib/settings/view/auto_sleep_timer_settings_page.dart +++ b/lib/settings/view/auto_sleep_timer_settings_page.dart @@ -13,7 +13,7 @@ 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; return SimpleSettingsPage( title: const Text('Auto Sleep Timer Settings'), @@ -35,7 +35,7 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget { : const Icon(Icons.timer_off), onToggle: (value) { ref.read(appSettingsProvider.notifier).update( - appSettings.copyWith.playerSettings.sleepTimerSettings( + appSettings.copyWith.sleepTimerSettings( autoTurnOnTimer: value, ), ); @@ -57,7 +57,7 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget { ); if (selected != null) { ref.read(appSettingsProvider.notifier).update( - appSettings.copyWith.playerSettings.sleepTimerSettings( + appSettings.copyWith.sleepTimerSettings( autoTurnOnTime: selected.toDuration(), ), ); @@ -81,7 +81,7 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget { ); if (selected != null) { ref.read(appSettingsProvider.notifier).update( - appSettings.copyWith.playerSettings.sleepTimerSettings( + appSettings.copyWith.sleepTimerSettings( autoTurnOffTime: selected.toDuration(), ), ); diff --git a/lib/shared/extensions/time_of_day.dart b/lib/shared/extensions/time_of_day.dart index 702c5b6..e378c3f 100644 --- a/lib/shared/extensions/time_of_day.dart +++ b/lib/shared/extensions/time_of_day.dart @@ -2,7 +2,10 @@ import 'package:flutter/material.dart'; extension ToTimeOfDay on Duration { TimeOfDay toTimeOfDay() { - return TimeOfDay(hour: inHours, minute: inMinutes % 60); + return TimeOfDay( + hour: inHours % 24, + minute: inMinutes % 60, + ); } }