mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-07 03:29:29 +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
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -36,10 +32,16 @@ class SleepTimer extends _$SleepTimer {
|
|||
return sleepTimer;
|
||||
}
|
||||
|
||||
void setTimer(Duration resultingDuration) {
|
||||
void setTimer(Duration? resultingDuration, {bool notifyListeners = true}) {
|
||||
if (resultingDuration == null || resultingDuration.inSeconds == 0) {
|
||||
cancelTimer();
|
||||
return;
|
||||
}
|
||||
if (state != null) {
|
||||
state!.duration = resultingDuration;
|
||||
ref.notifyListeners();
|
||||
if (notifyListeners) {
|
||||
ref.notifyListeners();
|
||||
}
|
||||
} else {
|
||||
final timer = core.SleepTimer(
|
||||
duration: resultingDuration,
|
||||
|
|
@ -62,3 +64,11 @@ class SleepTimer extends _$SleepTimer {
|
|||
state = null;
|
||||
}
|
||||
}
|
||||
|
||||
bool shouldBuildRightNow(Duration autoTurnOnTime, Duration autoTurnOffTime) {
|
||||
final now = TimeOfDay.now();
|
||||
return now.isBetween(
|
||||
autoTurnOnTime.toTimeOfDay(),
|
||||
autoTurnOffTime.toTimeOfDay(),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue