mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
feature: Auto next-up preview, skip to next in queue. (#96)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
f72ae9e3ca
commit
66f2b6cd4e
13 changed files with 971 additions and 137 deletions
|
|
@ -1,19 +1,20 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:async/async.dart';
|
||||
import 'package:ficonsax/ficonsax.dart';
|
||||
import 'package:fladder/providers/settings/photo_view_settings_provider.dart';
|
||||
import 'package:fladder/util/simple_duration_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:square_progress_indicator/square_progress_indicator.dart';
|
||||
|
||||
import 'package:fladder/util/simple_duration_picker.dart';
|
||||
|
||||
class RestarableTimerController {
|
||||
late Duration _steps = const Duration(milliseconds: 32);
|
||||
RestartableTimer? _timer;
|
||||
late Duration _duration = const Duration(seconds: 1);
|
||||
late Function() _onTimeout;
|
||||
late Function()? _onTimeout;
|
||||
|
||||
late Duration _timeLeft = _duration;
|
||||
set setTimeLeft(Duration value) {
|
||||
|
|
@ -24,7 +25,7 @@ class RestarableTimerController {
|
|||
final StreamController<Duration> _timeLeftController = StreamController<Duration>.broadcast();
|
||||
final StreamController<bool> _isActiveController = StreamController<bool>.broadcast();
|
||||
|
||||
RestarableTimerController(Duration duration, Duration steps, Function() onTimeout) {
|
||||
RestarableTimerController(Duration duration, Duration steps, {Function()? onTimeout}) {
|
||||
_steps = steps;
|
||||
_duration = duration;
|
||||
_onTimeout = onTimeout;
|
||||
|
|
@ -50,7 +51,7 @@ class RestarableTimerController {
|
|||
() {
|
||||
if (_timeLeft < _steps) {
|
||||
setTimeLeft = _duration;
|
||||
_onTimeout.call();
|
||||
_onTimeout?.call();
|
||||
} else {
|
||||
setTimeLeft = _timeLeft - _steps;
|
||||
}
|
||||
|
|
@ -86,7 +87,8 @@ class RestarableTimerController {
|
|||
class ProgressFloatingButton extends ConsumerStatefulWidget {
|
||||
final RestarableTimerController? controller;
|
||||
final Function()? onTimeOut;
|
||||
const ProgressFloatingButton({this.controller, this.onTimeOut, super.key});
|
||||
final Function(Duration? newDuration)? onLongPress;
|
||||
const ProgressFloatingButton({this.controller, this.onTimeOut, this.onLongPress, super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ConsumerStatefulWidget> createState() => _ProgressFloatingButtonState();
|
||||
|
|
@ -106,7 +108,7 @@ class _ProgressFloatingButtonState extends ConsumerState<ProgressFloatingButton>
|
|||
RestarableTimerController(
|
||||
const Duration(seconds: 1),
|
||||
const Duration(milliseconds: 32),
|
||||
widget.onTimeOut ?? () {},
|
||||
onTimeout: widget.onTimeOut ?? () {},
|
||||
);
|
||||
subscriptions.addAll([
|
||||
timer.timeLeft.listen((event) => setState(() => timeLeft = event)),
|
||||
|
|
@ -132,18 +134,21 @@ class _ProgressFloatingButtonState extends ConsumerState<ProgressFloatingButton>
|
|||
timer.reset();
|
||||
});
|
||||
},
|
||||
onLongPress: () async {
|
||||
HapticFeedback.vibrate();
|
||||
final newTimer =
|
||||
await showSimpleDurationPicker(context: context, initialValue: timer._duration, showNever: false);
|
||||
if (newTimer != null) {
|
||||
setState(() {
|
||||
ref.read(photoViewSettingsProvider.notifier).update((state) => state.copyWith(timer: newTimer));
|
||||
timer.setDuration(newTimer);
|
||||
});
|
||||
}
|
||||
},
|
||||
onLongPress: widget.onLongPress != null
|
||||
? () async {
|
||||
HapticFeedback.vibrate();
|
||||
final newTimer =
|
||||
await showSimpleDurationPicker(context: context, initialValue: timer._duration, showNever: false);
|
||||
widget.onLongPress?.call(newTimer);
|
||||
if (newTimer != null) {
|
||||
setState(() {
|
||||
timer.setDuration(newTimer);
|
||||
});
|
||||
}
|
||||
}
|
||||
: null,
|
||||
child: FloatingActionButton(
|
||||
heroTag: null,
|
||||
onPressed: isActive ? timer.cancel : timer.play,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue