mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-02-04 00:19:35 +00:00
feat: add shake detection functionality (#36)
* feat: add shake detection functionality and integrate vibration support * feat: add shake detector settings page
This commit is contained in:
parent
2e3b1de529
commit
b229c4f2f5
25 changed files with 1423 additions and 158 deletions
|
|
@ -19,7 +19,7 @@ class SleepTimer {
|
|||
|
||||
set duration(Duration value) {
|
||||
_duration = value;
|
||||
reset();
|
||||
clearCountDownTimer();
|
||||
}
|
||||
|
||||
/// The player to be paused
|
||||
|
|
@ -40,7 +40,7 @@ class SleepTimer {
|
|||
player.playbackEventStream.listen((event) {
|
||||
if (event.processingState == ProcessingState.completed ||
|
||||
event.processingState == ProcessingState.idle) {
|
||||
reset();
|
||||
clearCountDownTimer();
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -49,9 +49,9 @@ class SleepTimer {
|
|||
_subscriptions.add(
|
||||
player.playerStateStream.listen((state) {
|
||||
if (state.playing && timer == null) {
|
||||
startTimer();
|
||||
startCountDown();
|
||||
} else if (!state.playing) {
|
||||
reset();
|
||||
clearCountDownTimer();
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -59,8 +59,8 @@ class SleepTimer {
|
|||
_logger.fine('created with duration: $duration');
|
||||
}
|
||||
|
||||
/// resets the timer
|
||||
void reset() {
|
||||
/// resets the timer and stops it
|
||||
void clearCountDownTimer() {
|
||||
if (timer != null) {
|
||||
timer!.cancel();
|
||||
_logger.fine(
|
||||
|
|
@ -70,15 +70,25 @@ class SleepTimer {
|
|||
}
|
||||
}
|
||||
|
||||
/// refills the timer with the default duration and starts it if the player is playing
|
||||
/// if the player is not playing, the timer is stopped
|
||||
void restartTimer() {
|
||||
clearCountDownTimer();
|
||||
if (player.playing) {
|
||||
startCountDown();
|
||||
}
|
||||
_logger.fine('restarted timer');
|
||||
}
|
||||
|
||||
/// starts the timer with the given duration or the default duration
|
||||
void startTimer([
|
||||
void startCountDown([
|
||||
Duration? forDuration,
|
||||
]) {
|
||||
reset();
|
||||
clearCountDownTimer();
|
||||
duration = forDuration ?? duration;
|
||||
timer = Timer(duration, () {
|
||||
player.pause();
|
||||
reset();
|
||||
clearCountDownTimer();
|
||||
_logger.fine('paused player after $duration');
|
||||
});
|
||||
startedAt = DateTime.now();
|
||||
|
|
@ -103,7 +113,7 @@ class SleepTimer {
|
|||
|
||||
/// dispose the timer
|
||||
void dispose() {
|
||||
reset();
|
||||
clearCountDownTimer();
|
||||
for (var sub in _subscriptions) {
|
||||
sub.cancel();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:vaani/features/player/providers/audiobook_player.dart';
|
||||
import 'package:vaani/features/sleep_timer/core/sleep_timer.dart'
|
||||
as core;
|
||||
import 'package:vaani/features/sleep_timer/core/sleep_timer.dart' as core;
|
||||
import 'package:vaani/settings/app_settings_provider.dart';
|
||||
import 'package:vaani/shared/extensions/time_of_day.dart';
|
||||
|
||||
|
|
@ -48,9 +47,16 @@ class SleepTimer extends _$SleepTimer {
|
|||
);
|
||||
ref.onDispose(timer.dispose);
|
||||
state = timer;
|
||||
state!.startCountDown();
|
||||
}
|
||||
}
|
||||
|
||||
void restartTimer() {
|
||||
state?.restartTimer();
|
||||
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void cancelTimer() {
|
||||
state?.dispose();
|
||||
state = null;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ part of 'sleep_timer_provider.dart';
|
|||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$sleepTimerHash() => r'ad77e82c1b513bbc62815c64ce1ed403f92fc055';
|
||||
String _$sleepTimerHash() => r'9d9f20267da91e5483151b58b7d4d7c0762c3ca7';
|
||||
|
||||
/// See also [SleepTimer].
|
||||
@ProviderFor(SleepTimer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue