Pārlūkot izejas kodu

Improve delete

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 gadi atpakaļ
vecāks
revīzija
933cac4957

+ 8 - 0
src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java

@@ -601,4 +601,12 @@ public class UploadsStorageManager extends Observable {
 
         return result;
     }
+
+    public int removeAccountUploads(Account account) {
+        Log_OC.v(TAG, "Delete all uploads for account " + account.name);
+        return getDB().delete(
+                ProviderTableMeta.CONTENT_URI_UPLOADS,
+                ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?",
+                new String[]{account.name});
+    }
 }

+ 22 - 0
src/main/java/com/owncloud/android/jobs/AccountRemovalJob.java

@@ -34,12 +34,17 @@ import com.owncloud.android.MainApp;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.SyncedFolder;
+import com.owncloud.android.datamodel.SyncedFolderProvider;
+import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.ui.events.AccountRemovedEvent;
 import com.owncloud.android.utils.FileStorageUtils;
+import com.owncloud.android.utils.FilesSyncHelper;
 
 import org.greenrobot.eventbus.EventBus;
 
 import java.io.File;
+import java.util.List;
 
 import static android.content.Context.ACCOUNT_SERVICE;
 import static com.owncloud.android.ui.activity.ManageAccountsActivity.PENDING_FOR_REMOVAL;
@@ -78,6 +83,23 @@ public class AccountRemovalJob extends Job implements AccountManagerCallback<Boo
             ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
             arbitraryDataProvider.deleteKeyForAccount(account.name, PENDING_FOR_REMOVAL);
 
+            // remove synced folders set for account
+            SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver());
+            List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
+
+            for (SyncedFolder syncedFolder : syncedFolders) {
+                if (syncedFolder.getAccount().equals(account.name)) {
+                    arbitraryDataProvider.deleteKeyForAccount(FilesSyncHelper.GLOBAL,
+                            FilesSyncHelper.SYNCEDFOLDERINITIATED + syncedFolder.getId());
+                }
+            }
+
+            syncedFolderProvider.deleteSyncFoldersForAccount(account);
+
+            UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver(),
+                    context);
+            uploadsStorageManager.removeAccountUploads(account);
+
             return Result.SUCCESS;
         } else {
             return Result.FAILURE;