瀏覽代碼

Add option to disable backing up of videos

vishnukvmd 4 年之前
父節點
當前提交
ec0d4037aa

+ 18 - 0
lib/core/configuration.dart

@@ -34,6 +34,7 @@ class Configuration {
   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 keyShouldHideFromRecents = "should_hide_from_recents";
   static const keyShouldShowLockScreen = "should_show_lock_screen";
   static const keyHasSkippedBackupFolderSelection =
@@ -419,6 +420,23 @@ class Configuration {
     }
   }
 
+  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();
+    } else {
+      SyncService.instance.onVideoBackupPaused();
+    }
+  }
+
   bool shouldShowLockScreen() {
     if (_preferences.containsKey(keyShouldShowLockScreen)) {
       return _preferences.getBool(keyShouldShowLockScreen);

+ 1 - 2
lib/services/remote_sync_service.dart

@@ -1,7 +1,6 @@
 import 'dart:async';
 import 'dart:io';
 
-import 'package:flutter/foundation.dart';
 import 'package:logging/logging.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/errors.dart';
@@ -88,7 +87,7 @@ class RemoteSyncService {
       filesToBeUploaded =
           await _db.getFilesToBeUploadedWithinFolders(foldersToBackUp);
     }
-    if (kDebugMode) {
+    if (!Configuration.instance.shouldBackupVideos()) {
       filesToBeUploaded
           .removeWhere((element) => element.fileType == FileType.video);
     }

+ 7 - 0
lib/services/sync_service.dart

@@ -16,6 +16,7 @@ import 'package:photos/events/subscription_purchased_event.dart';
 import 'package:photos/events/sync_status_update_event.dart';
 import 'package:photos/events/trigger_logout_event.dart';
 import 'package:photos/models/backup_status.dart';
+import 'package:photos/models/file_type.dart';
 import 'package:photos/services/local_sync_service.dart';
 import 'package:photos/services/notification_service.dart';
 import 'package:photos/services/remote_sync_service.dart';
@@ -169,6 +170,12 @@ class SyncService {
     }, UserCancelledUploadError());
   }
 
+  void onVideoBackupPaused() {
+    _uploader.removeFromQueueWhere((file) {
+      return file.fileType == FileType.video;
+    }, UserCancelledUploadError());
+  }
+
   Future<void> deleteFilesOnServer(List<int> fileIDs) async {
     return await _dio.post(
       Configuration.instance.getHttpEndpoint() + "/files/delete",

+ 44 - 21
lib/ui/settings/backup_section_widget.dart

@@ -44,6 +44,35 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
             child: SettingsTextItem(
                 text: "backed up folders", icon: Icons.navigate_next),
           ),
+          Platform.isIOS
+              ? Padding(padding: EdgeInsets.all(2))
+              : Padding(padding: EdgeInsets.all(0)),
+          Divider(height: 4),
+          Platform.isIOS
+              ? Padding(padding: EdgeInsets.all(2))
+              : Padding(padding: EdgeInsets.all(2)),
+          GestureDetector(
+            behavior: HitTestBehavior.translucent,
+            onTap: () async {
+              final dialog = createProgressDialog(context, "calculating...");
+              await dialog.show();
+              final status = await SyncService.instance.getBackupStatus();
+              await dialog.hide();
+              if (status.localIDs.isEmpty) {
+                showErrorDialog(context, "✨ all clear",
+                    "you've no files on this device that can be deleted");
+              } else {
+                bool result = await routeToPage(context, FreeSpacePage(status));
+                if (result == true) {
+                  _showSpaceFreedDialog(status);
+                }
+              }
+            },
+            child: SettingsTextItem(
+              text: "free up space",
+              icon: Icons.navigate_next,
+            ),
+          ),
           Platform.isIOS
               ? Padding(padding: EdgeInsets.all(2))
               : Padding(padding: EdgeInsets.all(2)),
@@ -73,27 +102,21 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
           Divider(height: 4),
           Platform.isIOS
               ? Padding(padding: EdgeInsets.all(2))
-              : Padding(padding: EdgeInsets.all(2)),
-          GestureDetector(
-            behavior: HitTestBehavior.translucent,
-            onTap: () async {
-              final dialog = createProgressDialog(context, "calculating...");
-              await dialog.show();
-              final status = await SyncService.instance.getBackupStatus();
-              await dialog.hide();
-              if (status.localIDs.isEmpty) {
-                showErrorDialog(context, "✨ all clear",
-                    "you've no files on this device that can be deleted");
-              } else {
-                bool result = await routeToPage(context, FreeSpacePage(status));
-                if (result == true) {
-                  _showSpaceFreedDialog(status);
-                }
-              }
-            },
-            child: SettingsTextItem(
-              text: "free up space",
-              icon: Icons.navigate_next,
+              : Padding(padding: EdgeInsets.all(4)),
+          Container(
+            height: 36,
+            child: Row(
+              mainAxisAlignment: MainAxisAlignment.spaceBetween,
+              children: [
+                Text("backup videos"),
+                Switch(
+                  value: Configuration.instance.shouldBackupVideos(),
+                  onChanged: (value) async {
+                    Configuration.instance.setShouldBackupVideos(value);
+                    setState(() {});
+                  },
+                ),
+              ],
             ),
           ),
         ],