Explorar o código

Add and remove from favorites silently

Vishnu Mohandas %!s(int64=4) %!d(string=hai) anos
pai
achega
7b721e596b

+ 2 - 2
lib/services/collections_service.dart

@@ -264,7 +264,7 @@ class CollectionsService {
         .then((value) async {
         .then((value) async {
       await _filesDB.insertMultiple(files);
       await _filesDB.insertMultiple(files);
       Bus.instance.fire(CollectionUpdatedEvent(collectionID: collectionID));
       Bus.instance.fire(CollectionUpdatedEvent(collectionID: collectionID));
-      SyncService.instance.syncWithRemote();
+      SyncService.instance.syncWithRemote(silently: true);
     });
     });
   }
   }
 
 
@@ -285,7 +285,7 @@ class CollectionsService {
     );
     );
     await _filesDB.removeFromCollection(collectionID, params["fileIDs"]);
     await _filesDB.removeFromCollection(collectionID, params["fileIDs"]);
     Bus.instance.fire(CollectionUpdatedEvent(collectionID: collectionID));
     Bus.instance.fire(CollectionUpdatedEvent(collectionID: collectionID));
-    SyncService.instance.syncWithRemote();
+    SyncService.instance.syncWithRemote(silently: true);
   }
   }
 
 
   Future<Collection> createAndCacheCollection(Collection collection) async {
   Future<Collection> createAndCacheCollection(Collection collection) async {

+ 3 - 6
lib/services/sync_service.dart

@@ -175,12 +175,12 @@ class SyncService {
     await _prefs.setInt(_dbUpdationTimeKey, toTime);
     await _prefs.setInt(_dbUpdationTimeKey, toTime);
   }
   }
 
 
-  Future<void> syncWithRemote() async {
+  Future<void> syncWithRemote({bool silently = false}) async {
     if (!Configuration.instance.hasConfiguredAccount()) {
     if (!Configuration.instance.hasConfiguredAccount()) {
       return Future.error("Account not configured yet");
       return Future.error("Account not configured yet");
     }
     }
     final updatedCollections = await _collectionsService.sync();
     final updatedCollections = await _collectionsService.sync();
-    if (updatedCollections.isNotEmpty) {
+    if (updatedCollections.isNotEmpty && !silently) {
       Bus.instance.fire(SyncStatusUpdate(SyncStatus.applying_remote_diff));
       Bus.instance.fire(SyncStatusUpdate(SyncStatus.applying_remote_diff));
     }
     }
     for (final collection in updatedCollections) {
     for (final collection in updatedCollections) {
@@ -189,10 +189,7 @@ class SyncService {
     await deleteFilesOnServer();
     await deleteFilesOnServer();
     bool hasUploadedFiles = await _uploadDiff();
     bool hasUploadedFiles = await _uploadDiff();
     if (hasUploadedFiles) {
     if (hasUploadedFiles) {
-      final updatedCollections = await _collectionsService.sync();
-      for (final collection in updatedCollections) {
-        await _fetchEncryptedFilesDiff(collection.id);
-      }
+      syncWithRemote(silently: true);
     }
     }
   }
   }
 
 

+ 11 - 15
lib/ui/detail_page.dart

@@ -196,34 +196,30 @@ class _DetailPageState extends State<DetailPage> {
         final isLiked = !oldValue;
         final isLiked = !oldValue;
         bool hasError = false;
         bool hasError = false;
         if (isLiked) {
         if (isLiked) {
-          final dialog =
-              createProgressDialog(context, "Adding to favorites...");
-          await dialog.show();
+          final shouldBlockUser = file.uploadedFileID == null;
+          var dialog;
+          if (shouldBlockUser) {
+            dialog = createProgressDialog(context, "Adding to favorites...");
+            await dialog.show();
+          }
           try {
           try {
             await FavoritesService.instance.addToFavorites(file);
             await FavoritesService.instance.addToFavorites(file);
-            showToast("Added to favorites.");
           } catch (e, s) {
           } catch (e, s) {
             _logger.severe(e, s);
             _logger.severe(e, s);
-            await dialog.hide();
             hasError = true;
             hasError = true;
-            showGenericErrorDialog(context);
+            showToast("Sorry, could not add this to favorites!");
           } finally {
           } finally {
-            await dialog.hide();
+            if (shouldBlockUser) {
+              await dialog.hide();
+            }
           }
           }
         } else {
         } else {
-          final dialog =
-              createProgressDialog(context, "Removing from favorites...");
-          await dialog.show();
           try {
           try {
             await FavoritesService.instance.removeFromFavorites(file);
             await FavoritesService.instance.removeFromFavorites(file);
-            showToast("Removed from favorites.");
           } catch (e, s) {
           } catch (e, s) {
             _logger.severe(e, s);
             _logger.severe(e, s);
-            await dialog.hide();
             hasError = true;
             hasError = true;
-            showGenericErrorDialog(context);
-          } finally {
-            await dialog.hide();
+            showToast("Sorry, could not remove this from favorites!");
           }
           }
         }
         }
         return hasError ? oldValue : isLiked;
         return hasError ? oldValue : isLiked;