Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Refactor

ashilknab86c5129e54
diff --git a/mobile/lib/core/configuration.dart b/mobile/lib/core/configuration.dart
index 70db6c3d96..16a65d497f 100644
--- a/mobile/lib/core/configuration.dart
+++ b/mobile/lib/core/configuration.dart
@@ -71,7 +71,6 @@ class Configuration {
"has_selected_all_folders_for_backup";
static const anonymousUserIDKey = "anonymous_user_id";
static const endPointKey = "endpoint";
- static const shouldLoopVideoKey = "should_loop_video";
static final _logger = Logger("Configuration");
String? _cachedToken;
@@ -662,14 +661,6 @@ class Configuration {
await _preferences.setBool(hasSelectedAllFoldersForBackupKey, value);
}
- Future<void> setShouldLoopVideo(bool value) async {
- await _preferences.setBool(shouldLoopVideoKey, value);
- }
-
- bool shouldLoopVideo() {
- return _preferences.getBool(shouldLoopVideoKey) ?? true;
- }
-
Future<void> _migrateSecurityStorageToFirstUnlock() async {
final hasMigratedSecureStorage =
_preferences.getBool(hasMigratedSecureStorageKey) ?? false;
diff --git a/mobile/lib/ui/viewer/file/file_app_bar.dart b/mobile/lib/ui/viewer/file/file_app_bar.dart
index 8913790766..67b10bb9ad 100644
--- a/mobile/lib/ui/viewer/file/file_app_bar.dart
+++ b/mobile/lib/ui/viewer/file/file_app_bar.dart
@@ -6,7 +6,6 @@ import "package:flutter_svg/flutter_svg.dart";
import "package:local_auth/local_auth.dart";
import 'package:logging/logging.dart';
import 'package:media_extension/media_extension.dart';
-import "package:photos/core/configuration.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/guest_view_event.dart";
import "package:photos/generated/l10n.dart";
@@ -17,6 +16,7 @@ import 'package:photos/models/file/file_type.dart';
import 'package:photos/models/file/trash_file.dart';
import "package:photos/models/metadata/common_keys.dart";
import 'package:photos/models/selected_files.dart';
+import "package:photos/service_locator.dart";
import 'package:photos/services/collections_service.dart';
import 'package:photos/services/hidden_service.dart';
import "package:photos/services/local_authentication_service.dart";
@@ -44,8 +44,8 @@ class FileAppBar extends StatefulWidget {
this.height,
this.shouldShowActions, {
required this.enableFullScreenNotifier,
- Key? key,
- }) : super(key: key);
+ super.key,
+ });
@override
FileAppBarState createState() => FileAppBarState();
@@ -56,7 +56,7 @@ class FileAppBarState extends State<FileAppBar> {
final List<Widget> _actions = [];
late final StreamSubscription<GuestViewEvent> _guestViewEventSubscription;
bool isGuestView = false;
- bool shouldLoopVideo = Configuration.instance.shouldLoopVideo();
+ bool shouldLoopVideo = localSettings.shouldLoopVideo();
bool _reloadActions = false;
@override
@@ -390,7 +390,7 @@ class FileAppBarState extends State<FileAppBar> {
}
_onToggleLoopVideo() {
- Configuration.instance.setShouldLoopVideo(!shouldLoopVideo);
+ localSettings.setShouldLoopVideo(!shouldLoopVideo);
setState(() {
_reloadActions = true;
shouldLoopVideo = !shouldLoopVideo;
diff --git a/mobile/lib/ui/viewer/file/native_video_player_controls/seek_bar.dart b/mobile/lib/ui/viewer/file/native_video_player_controls/seek_bar.dart
index f57d772566..f37791d56e 100644
--- a/mobile/lib/ui/viewer/file/native_video_player_controls/seek_bar.dart
+++ b/mobile/lib/ui/viewer/file/native_video_player_controls/seek_bar.dart
@@ -2,7 +2,7 @@ import "dart:async";
import "package:flutter/material.dart";
import "package:native_video_player/native_video_player.dart";
-import "package:photos/core/configuration.dart";
+import "package:photos/service_locator.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/utils/debouncer.dart";
@@ -149,7 +149,7 @@ class _SeekBarState extends State<SeekBar> with SingleTickerProviderStateMixin {
setState(() {
_animationController.value = 0;
});
- if (!Configuration.instance.shouldLoopVideo()) {
+ if (!localSettings.shouldLoopVideo()) {
return;
}
}
diff --git a/mobile/lib/ui/viewer/file/video_widget_native.dart b/mobile/lib/ui/viewer/file/video_widget_native.dart
index 268bdec5e2..4281d405df 100644
--- a/mobile/lib/ui/viewer/file/video_widget_native.dart
+++ b/mobile/lib/ui/viewer/file/video_widget_native.dart
@@ -4,15 +4,14 @@ import "dart:io";
import "package:flutter/material.dart";
import "package:logging/logging.dart";
import "package:native_video_player/native_video_player.dart";
-import "package:photos/core/configuration.dart";
import "package:photos/core/constants.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/guest_view_event.dart";
import "package:photos/events/pause_video_event.dart";
-// import "package:photos/events/pause_video_event.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/models/file/extensions/file_props.dart";
import "package:photos/models/file/file.dart";
+import "package:photos/service_locator.dart";
import "package:photos/services/files_service.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
@@ -348,7 +347,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
}
void _onPlaybackEnded() {
- if (Configuration.instance.shouldLoopVideo()) {
+ if (localSettings.shouldLoopVideo()) {
_controller?.play();
}
}
diff --git a/mobile/lib/utils/local_settings.dart b/mobile/lib/utils/local_settings.dart
index cdf0b6ef63..cc657c369e 100644
--- a/mobile/lib/utils/local_settings.dart
+++ b/mobile/lib/utils/local_settings.dart
@@ -14,6 +14,7 @@ class LocalSettings {
static const kRateUsShownCount = "rate_us_shown_count";
static const kEnableMultiplePart = "ls.enable_multiple_part";
static const kRateUsPromptThreshold = 2;
+ static const shouldLoopVideoKey = "video.should_loop";
final SharedPreferences _prefs;
@@ -82,4 +83,12 @@ class LocalSettings {
await _prefs.setBool("remoteFetchEnabled", !remoteFetchEnabled);
}
//#endregion
+
+ Future<void> setShouldLoopVideo(bool value) async {
+ await _prefs.setBool(shouldLoopVideoKey, value);
+ }
+
+ bool shouldLoopVideo() {
+ return _prefs.getBool(shouldLoopVideoKey) ?? true;
+ }
}