Skip to content

armgit / ente

Public Imported from GitHub
0

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

Extract photos backup settings

Neeraj Gupta666bd7de9bf4
diff --git a/mobile/apps/photos/lib/core/backup_settings.dart b/mobile/apps/photos/lib/core/backup_settings.dart
new file mode 100644
index 0000000000..9a1e2eeb7f
--- /dev/null
+++ b/mobile/apps/photos/lib/core/backup_settings.dart
@@ -0,0 +1,35 @@
+import "package:shared_preferences/shared_preferences.dart";
+
+class BackupSettings {
+ BackupSettings(this._preferences);
+
+ static const _keyShouldBackupOverMobileData =
+ "should_backup_over_mobile_data";
+ static const _keyShouldBackupVideos = "should_backup_videos";
+
+ final SharedPreferences _preferences;
+
+ bool shouldBackupOverMobileData() {
+ if (_preferences.containsKey(_keyShouldBackupOverMobileData)) {
+ return _preferences.getBool(_keyShouldBackupOverMobileData)!;
+ } else {
+ return false;
+ }
+ }
+
+ Future<void> setBackupOverMobileData(bool value) async {
+ await _preferences.setBool(_keyShouldBackupOverMobileData, value);
+ }
+
+ bool shouldBackupVideos() {
+ if (_preferences.containsKey(_keyShouldBackupVideos)) {
+ return _preferences.getBool(_keyShouldBackupVideos)!;
+ } else {
+ return true;
+ }
+ }
+
+ Future<void> setShouldBackupVideos(bool value) async {
+ await _preferences.setBool(_keyShouldBackupVideos, value);
+ }
+}
diff --git a/mobile/apps/photos/lib/core/configuration.dart b/mobile/apps/photos/lib/core/configuration.dart
index bae0a7f21b..b724c38873 100644
--- a/mobile/apps/photos/lib/core/configuration.dart
+++ b/mobile/apps/photos/lib/core/configuration.dart
@@ -56,11 +56,8 @@ class Configuration {
static final Configuration instance = Configuration._privateConstructor();
static const emailKey = "email";
- static const foldersToBackUpKey = "folders_to_back_up";
static const keyAttributesKey = "key_attributes";
static const keyKey = "key";
- static const keyShouldBackupOverMobileData = "should_backup_over_mobile_data";
- static const keyShouldBackupVideos = "should_backup_videos";
static const keyShowSystemLockScreen = "should_show_lock_screen";
static const lastTempFolderClearTimeKey = "last_temp_folder_clear_time";
static const secretKeyKey = "secret_key";
@@ -557,14 +554,6 @@ class Configuration {
await _preferences.setInt(userIDKey, userID);
}
- Set<String> getPathsToBackUp() {
- if (_preferences.containsKey(foldersToBackUpKey)) {
- return _preferences.getStringList(foldersToBackUpKey)!.toSet();
- } else {
- return <String>{};
- }
- }
-
Future<void> setKeyAttributes(KeyAttributes attributes) async {
await _preferences.setString(keyAttributesKey, attributes.toJson());
}
@@ -636,38 +625,6 @@ class Configuration {
return isLoggedIn() && _key != null;
}
- bool shouldBackupOverMobileData() {
- if (_preferences.containsKey(keyShouldBackupOverMobileData)) {
- return _preferences.getBool(keyShouldBackupOverMobileData)!;
- } else {
- return false;
- }
- }
-
- Future<void> setBackupOverMobileData(bool value) async {
- await _preferences.setBool(keyShouldBackupOverMobileData, value);
- if (value) {
- SyncService.instance.sync().ignore();
- }
- }
-
- bool shouldBackupVideos() {
- if (_preferences.containsKey(keyShouldBackupVideos)) {
- return _preferences.getBool(keyShouldBackupVideos)!;
- } else {
- return true;
- }
- }
-
- Future<void> setShouldBackupVideos(bool value) async {
- await _preferences.setBool(keyShouldBackupVideos, value);
- if (value) {
- SyncService.instance.sync().ignore();
- } else {
- SyncService.instance.onVideoBackupPaused();
- }
- }
-
Future<bool> shouldShowLockScreen() async {
final bool isPin = await LockScreenSettings.instance.isPinSet();
final bool isPass = await LockScreenSettings.instance.isPasswordSet();
diff --git a/mobile/apps/photos/lib/service_locator.dart b/mobile/apps/photos/lib/service_locator.dart
index 94dc3e3a2b..e9e697d862 100644
--- a/mobile/apps/photos/lib/service_locator.dart
+++ b/mobile/apps/photos/lib/service_locator.dart
@@ -2,6 +2,7 @@ import "package:dio/dio.dart";
import "package:ente_cast/ente_cast.dart";
import "package:ente_feature_flag/ente_feature_flag.dart";
import "package:package_info_plus/package_info_plus.dart";
+import "package:photos/core/backup_settings.dart";
import "package:photos/core/network/endpoint_config.dart";
import "package:photos/gateways/billing/billing_gateway.dart";
import "package:photos/gateways/collections/collection_files_gateway.dart";
@@ -98,6 +99,12 @@ LocalSettings get localSettings {
return _localSettings!;
}
+BackupSettings? _backupSettings;
+BackupSettings get backupSettings {
+ _backupSettings ??= BackupSettings(ServiceLocator.instance.prefs);
+ return _backupSettings!;
+}
+
/// Whether the app is currently showing the no-account local gallery experience.
///
/// This does not mean the device is offline. It means the active gallery mode is
diff --git a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
index 762a5cd614..8bd0f3dabf 100644
--- a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
+++ b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
@@ -234,7 +234,7 @@ class RemoteSyncService {
Future<bool> whiteListVideoForUpload(EnteFile file) async {
if (file.fileType == FileType.video &&
- !_config.shouldBackupVideos() &&
+ !backupSettings.shouldBackupVideos() &&
file.localID != null) {
final List<String> whitelistedIDs =
_prefs.getStringList(_ignoreBackUpSettingsForIDs_) ?? <String>[];
@@ -649,7 +649,7 @@ class RemoteSyncService {
return originalFiles;
}
final bool shouldRemoveVideos =
- !_config.shouldBackupVideos() || bgWithoutResumableUpload;
+ !backupSettings.shouldBackupVideos() || bgWithoutResumableUpload;
final ignoredIDs = await IgnoredFilesService.instance.idToIgnoreReasonMap;
bool shouldSkipUploadFunc(EnteFile file) {
return IgnoredFilesService.instance.shouldSkipUpload(ignoredIDs, file);
diff --git a/mobile/apps/photos/lib/ui/settings/backup/backup_settings_screen.dart b/mobile/apps/photos/lib/ui/settings/backup/backup_settings_screen.dart
index d701eab08b..35d9517e0a 100644
--- a/mobile/apps/photos/lib/ui/settings/backup/backup_settings_screen.dart
+++ b/mobile/apps/photos/lib/ui/settings/backup/backup_settings_screen.dart
@@ -4,7 +4,6 @@ import "package:ente_components/ente_components.dart";
import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:flutter/material.dart";
import "package:photo_manager/photo_manager.dart";
-import "package:photos/core/configuration.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
import "package:photos/service_locator.dart";
@@ -33,21 +32,32 @@ class BackupSettingsScreen extends StatelessWidget {
_toggleItem(
context,
title: l10n.backupOverMobileData,
- value: () => Configuration.instance.shouldBackupOverMobileData(),
+ value: () => backupSettings.shouldBackupOverMobileData(),
onChanged: () async {
- await Configuration.instance.setBackupOverMobileData(
- !Configuration.instance.shouldBackupOverMobileData(),
+ final shouldBackupOverMobileData = !backupSettings
+ .shouldBackupOverMobileData();
+ await backupSettings.setBackupOverMobileData(
+ shouldBackupOverMobileData,
);
+ if (shouldBackupOverMobileData) {
+ SyncService.instance.sync().ignore();
+ }
},
),
const SizedBox(height: 8),
_toggleItem(
context,
title: l10n.backupVideos,
- value: () => Configuration.instance.shouldBackupVideos(),
- onChanged: () => Configuration.instance.setShouldBackupVideos(
- !Configuration.instance.shouldBackupVideos(),
- ),
+ value: () => backupSettings.shouldBackupVideos(),
+ onChanged: () async {
+ final shouldBackupVideos = !backupSettings.shouldBackupVideos();
+ await backupSettings.setShouldBackupVideos(shouldBackupVideos);
+ if (shouldBackupVideos) {
+ SyncService.instance.sync().ignore();
+ } else {
+ SyncService.instance.onVideoBackupPaused();
+ }
+ },
),
if (flagService.enableOnlyBackupFuturePhotos) ...[
const SizedBox(height: 8),
diff --git a/mobile/apps/photos/lib/utils/network_util.dart b/mobile/apps/photos/lib/utils/network_util.dart
index 66f3b419ae..fca32e1029 100644
--- a/mobile/apps/photos/lib/utils/network_util.dart
+++ b/mobile/apps/photos/lib/utils/network_util.dart
@@ -1,5 +1,5 @@
import "package:connectivity_plus/connectivity_plus.dart";
-import "package:photos/core/configuration.dart";
+import "package:photos/service_locator.dart";
Future<bool> canUseHighBandwidth() async {
// Connections will contain a list of currently active connections.
@@ -7,12 +7,11 @@ Future<bool> canUseHighBandwidth() async {
final List<ConnectivityResult> connections = await (Connectivity()
.checkConnectivity());
bool canUploadUnderCurrentNetworkConditions = true;
- if (!Configuration.instance.shouldBackupOverMobileData()) {
+ if (!backupSettings.shouldBackupOverMobileData()) {
if (connections.any((element) => element == ConnectivityResult.mobile)) {
canUploadUnderCurrentNetworkConditions = false;
}
}
- final canDownloadOverMobileData = Configuration.instance
- .shouldBackupOverMobileData();
+ final canDownloadOverMobileData = backupSettings.shouldBackupOverMobileData();
return canUploadUnderCurrentNetworkConditions || canDownloadOverMobileData;
}