mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-08 20:19:29 +00:00
feat: Add duration_picker dependency to pubspec.yaml
This commit is contained in:
parent
b98188d7fb
commit
fbd789f989
13 changed files with 558 additions and 49 deletions
|
|
@ -1,19 +1,59 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:whispering_pages/features/player/providers/audiobook_player.dart';
|
||||
import 'package:whispering_pages/features/sleep_timer/core/sleep_timer.dart';
|
||||
import 'package:whispering_pages/features/sleep_timer/core/sleep_timer.dart'
|
||||
as core;
|
||||
import 'package:whispering_pages/settings/app_settings_provider.dart';
|
||||
import 'package:whispering_pages/shared/extensions/time_of_day.dart';
|
||||
|
||||
part 'sleep_timer_provider.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
SleepTimer? sleepTimer(SleepTimerRef ref) {
|
||||
final appSettings = ref.watch(appSettingsProvider);
|
||||
final sleepTimerSettings = appSettings.playerSettings.sleepTimerSettings;
|
||||
var sleepTimer = SleepTimer(
|
||||
// duration: sleepTimerSettings.defaultDuration,
|
||||
duration: const Duration(seconds: 5),
|
||||
player: ref.watch(simpleAudiobookPlayerProvider),
|
||||
);
|
||||
ref.onDispose(sleepTimer.dispose);
|
||||
return sleepTimer;
|
||||
class SleepTimer extends _$SleepTimer {
|
||||
@override
|
||||
core.SleepTimer? build() {
|
||||
final appSettings = ref.watch(appSettingsProvider);
|
||||
final sleepTimerSettings = appSettings.playerSettings.sleepTimerSettings;
|
||||
bool isEnabled = sleepTimerSettings.autoTurnOnTimer;
|
||||
if (!isEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((!sleepTimerSettings.alwaysAutoTurnOnTimer) &&
|
||||
(sleepTimerSettings.autoTurnOnTime
|
||||
.toTimeOfDay()
|
||||
.isAfter(TimeOfDay.now()) &&
|
||||
sleepTimerSettings.autoTurnOffTime
|
||||
.toTimeOfDay()
|
||||
.isBefore(TimeOfDay.now()))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var sleepTimer = core.SleepTimer(
|
||||
// duration: sleepTimerSettings.defaultDuration,
|
||||
duration: const Duration(seconds: 5),
|
||||
player: ref.watch(simpleAudiobookPlayerProvider),
|
||||
);
|
||||
ref.onDispose(sleepTimer.dispose);
|
||||
return sleepTimer;
|
||||
}
|
||||
|
||||
void setTimer(Duration resultingDuration) {
|
||||
if (state != null) {
|
||||
state!.duration = resultingDuration;
|
||||
ref.notifyListeners();
|
||||
} else {
|
||||
final timer = core.SleepTimer(
|
||||
duration: resultingDuration,
|
||||
player: ref.watch(simpleAudiobookPlayerProvider),
|
||||
);
|
||||
ref.onDispose(timer.dispose);
|
||||
state = timer;
|
||||
}
|
||||
}
|
||||
|
||||
void cancelTimer() {
|
||||
state?.dispose();
|
||||
state = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue