Browse Source

Implement migration path

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 năm trước cách đây
mục cha
commit
dcde2d6a80

+ 20 - 0
src/main/java/com/owncloud/android/MainApp.java

@@ -128,6 +128,8 @@ public class MainApp extends MultiDexApplication {
             PreferenceManager.setAutoUploadSplitEntries(this, true);
         }
 
+        initiateExistingAutoUploadEntries();
+
         new JobRequest.Builder(FilesSyncJob.TAG)
                 .setPeriodic(900000L, 300000L)
                 .setUpdateCurrent(true)
@@ -333,6 +335,24 @@ public class MainApp extends MultiDexApplication {
         }
     }
 
+    private void initiateExistingAutoUploadEntries() {
+        new Thread(() -> {
+            if (!PreferenceManager.getAutoUploadInit(getAppContext())) {
+                SyncedFolderProvider syncedFolderProvider =
+                        new SyncedFolderProvider(MainApp.getAppContext().getContentResolver());
+
+                for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
+                    if (syncedFolder.isEnabled()) {
+                        FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolder);
+                    }
+                }
+
+                PreferenceManager.setAutoUploadInit(getAppContext(), true);
+            }
+
+        }).start();
+    }
+
     private void cleanOldEntries() {
         // previous versions of application created broken entries in the SyncedFolderProvider
         // database, and this cleans all that and leaves 1 (newest) entry per synced folder

+ 9 - 0
src/main/java/com/owncloud/android/db/PreferenceManager.java

@@ -49,6 +49,7 @@ public abstract class PreferenceManager {
     private static final String PREF__AUTO_UPLOAD_UPDATE_PATH = "autoUploadPathUpdate";
     private static final String PREF__PUSH_TOKEN = "pushToken";
     private static final String PREF__AUTO_UPLOAD_SPLIT_OUT = "autoUploadEntriesSplitOut";
+    private static final String PREF__AUTO_UPLOAD_INIT = "autoUploadInit";
 
     public static void setPushToken(Context context, String pushToken) {
         saveStringPreferenceNow(context, PREF__PUSH_TOKEN, pushToken);
@@ -199,6 +200,10 @@ public abstract class PreferenceManager {
         saveBooleanPreference(context, AUTO_PREF__SORT_ASCENDING, ascending);
     }
 
+    public static boolean getAutoUploadInit(Context context) {
+        return getDefaultSharedPreferences(context).getBoolean(PREF__AUTO_UPLOAD_INIT, false);
+    }
+
     /**
      * Gets the legacy cleaning flag last set.
      *
@@ -240,6 +245,10 @@ public abstract class PreferenceManager {
         saveBooleanPreference(context, PREF__LEGACY_CLEAN, legacyClean);
     }
 
+    public static void setAutoUploadInit(Context context, boolean autoUploadInit) {
+        saveBooleanPreference(context, PREF__AUTO_UPLOAD_INIT, autoUploadInit);
+    }
+
     /**
      * Saves the legacy cleaning flag which the user has set last.
      *

+ 0 - 2
src/main/java/com/owncloud/android/utils/FilesSyncHelper.java

@@ -187,8 +187,6 @@ public class FilesSyncHelper {
         FileUploader.UploadRequester uploadRequester = new FileUploader.UploadRequester();
 
         boolean accountExists;
-        boolean fileExists;
-
 
         UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver(), context);
         OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();