mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Save and restore video player settings
This commit is contained in:
parent
34ee7bbe19
commit
5468658bc2
2 changed files with 35 additions and 6 deletions
|
@ -283,6 +283,20 @@ class Pref {
|
|||
Future<bool> setSeedColor(int value) => _set<int>(
|
||||
PrefKey.seedColor, value, (key, value) => provider.setInt(key, value));
|
||||
|
||||
bool? isVideoPlayerMute() => provider.getBool(PrefKey.isVideoPlayerMute);
|
||||
bool isVideoPlayerMuteOr([bool def = false]) => isVideoPlayerMute() ?? def;
|
||||
Future<bool> setVideoPlayerMute(bool value) => _set<bool>(
|
||||
PrefKey.isVideoPlayerMute,
|
||||
value,
|
||||
(key, value) => provider.setBool(key, value));
|
||||
|
||||
bool? isVideoPlayerLoop() => provider.getBool(PrefKey.isVideoPlayerLoop);
|
||||
bool isVideoPlayerLoopOr([bool def = false]) => isVideoPlayerLoop() ?? def;
|
||||
Future<bool> setVideoPlayerLoop(bool value) => _set<bool>(
|
||||
PrefKey.isVideoPlayerLoop,
|
||||
value,
|
||||
(key, value) => provider.setBool(key, value));
|
||||
|
||||
Future<bool> _set<T>(PrefKey key, T value,
|
||||
Future<bool> Function(PrefKey key, T value) setFn) async {
|
||||
if (await setFn(key, value)) {
|
||||
|
@ -597,6 +611,8 @@ enum PrefKey {
|
|||
hasShownSaveEditResultDialog,
|
||||
isSlideshowReverse,
|
||||
seedColor,
|
||||
isVideoPlayerMute,
|
||||
isVideoPlayerLoop,
|
||||
|
||||
// account pref
|
||||
isEnableFaceRecognitionApp,
|
||||
|
@ -676,6 +692,10 @@ extension on PrefKey {
|
|||
return "isSlideshowReverse";
|
||||
case PrefKey.seedColor:
|
||||
return "seedColor";
|
||||
case PrefKey.isVideoPlayerMute:
|
||||
return "isVideoPlayerMute";
|
||||
case PrefKey.isVideoPlayerLoop:
|
||||
return "isVideoPlayerLoop";
|
||||
|
||||
// account pref
|
||||
case PrefKey.isEnableFaceRecognitionApp:
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kiwi/kiwi.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api.dart';
|
||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||
import 'package:nc_photos/app_localizations.dart';
|
||||
import 'package:nc_photos/di_container.dart';
|
||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||
import 'package:nc_photos/k.dart' as k;
|
||||
|
@ -106,6 +110,9 @@ class _VideoViewerState extends State<VideoViewer>
|
|||
},
|
||||
);
|
||||
await _controller.initialize();
|
||||
final c = KiwiContainer().resolve<DiContainer>();
|
||||
unawaited(_controller.setVolume(c.pref.isVideoPlayerMuteOr() ? 0 : 1));
|
||||
unawaited(_controller.setLooping(c.pref.isVideoPlayerLoopOr()));
|
||||
widget.onLoaded?.call();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_key.currentContext != null) {
|
||||
|
@ -283,13 +290,12 @@ class _VideoViewerState extends State<VideoViewer>
|
|||
}
|
||||
|
||||
void _onVolumnPressed() {
|
||||
final willMute = _controller.value.volume != 0;
|
||||
setState(() {
|
||||
if (_controller.value.volume == 0) {
|
||||
_controller.setVolume(1);
|
||||
} else {
|
||||
_controller.setVolume(0);
|
||||
}
|
||||
_controller.setVolume(willMute ? 0 : 1);
|
||||
});
|
||||
final c = KiwiContainer().resolve<DiContainer>();
|
||||
c.pref.setVideoPlayerMute(willMute);
|
||||
}
|
||||
|
||||
void _play() {
|
||||
|
@ -338,9 +344,12 @@ class _LoopToggleState extends State<_LoopToggle> {
|
|||
child: InkWell(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(32)),
|
||||
onTap: () {
|
||||
final willLoop = !widget.controller.value.isLooping;
|
||||
setState(() {
|
||||
widget.controller.setLooping(!widget.controller.value.isLooping);
|
||||
widget.controller.setLooping(willLoop);
|
||||
});
|
||||
final c = KiwiContainer().resolve<DiContainer>();
|
||||
c.pref.setVideoPlayerLoop(willLoop);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(4),
|
||||
|
|
Loading…
Reference in a new issue