瀏覽代碼

Clean update

Mario Danic 8 年之前
父節點
當前提交
7a1a84cb50

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

@@ -118,6 +118,7 @@ public class MainApp extends MultiDexApplication {
         }
 
         cleanOldEntries();
+        updateAutoUploadEntries();
 
         Log_OC.d("SyncedFolderObserverService", "Start service SyncedFolderObserverService");
         Intent i = new Intent(this, SyncedFolderObserverService.class);
@@ -269,6 +270,14 @@ public class MainApp extends MultiDexApplication {
         return userAgent;
     }
 
+    private void updateAutoUploadEntries() {
+        // updates entries to reflect their true paths
+        if (!PreferenceManager.getAutoUploadPathsUpdate(this)) {
+            SyncedFolderProvider syncedFolderProvider =
+                    new SyncedFolderProvider(MainApp.getAppContext().getContentResolver());
+            syncedFolderProvider.updateAutoUploadPaths(mContext);
+        }
+    }
     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

+ 34 - 2
src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java

@@ -31,6 +31,7 @@ import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.db.ProviderMeta;
 import com.owncloud.android.lib.common.utils.Log_OC;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Observable;
@@ -188,6 +189,35 @@ public class SyncedFolderProvider extends Observable {
 
     }
 
+    /**
+     * Try to figure out if a path exists for synced folder, and if not, go one folder back
+     * Otherwise, delete the entry
+     *
+     * @param context the context.
+     */
+    public void updateAutoUploadPaths(Context context) {
+        List<SyncedFolder> syncedFolders = getSyncedFolders();
+        for (int i = 0; i < syncedFolders.size(); i++) {
+            SyncedFolder syncedFolder = syncedFolders.get(i);
+            if (!new File(syncedFolder.getLocalPath()).exists()) {
+                String localPath = syncedFolder.getLocalPath();
+                if (localPath.endsWith("/")) {
+                    localPath = localPath.substring(0, localPath.lastIndexOf("/"));
+                }
+                localPath = localPath.substring(0, localPath.lastIndexOf("/"));
+                if (new File(localPath).exists()) {
+                    syncedFolders.get(i).setLocalPath(localPath);
+                    updateSyncFolder(syncedFolder);
+                } else {
+                }
+            }
+        }
+
+        if (context != null) {
+            PreferenceManager.setAutoUploadPathsUpdate(context, true);
+        }
+    }
+
     /**
      * delete any records of synchronized folders that are not within the given list of ids.
      *
@@ -293,7 +323,9 @@ public class SyncedFolderProvider extends Observable {
      * @param syncedFolder changed, synchronized folder
      */
     private void notifyFolderSyncObservers(SyncedFolder syncedFolder) {
-        MainApp.getSyncedFolderObserverService().restartObserver(syncedFolder);
-        Log_OC.d(TAG, "notifying folder sync data observers for changed/added: " + syncedFolder.getLocalPath());
+        if (syncedFolder != null) {
+            MainApp.getSyncedFolderObserverService().restartObserver(syncedFolder);
+            Log_OC.d(TAG, "notifying folder sync data observers for changed/added: " + syncedFolder.getLocalPath());
+        }
     }
 }

+ 25 - 1
src/main/java/com/owncloud/android/db/PreferenceManager.java

@@ -45,6 +45,8 @@ public abstract class PreferenceManager {
     private static final String PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI = "instant_video_upload_on_wifi";
     private static final String PREF__INSTANT_VIDEO_UPLOAD_PATH_USE_SUBFOLDERS = "instant_video_upload_path_use_subfolders";
     private static final String PREF__LEGACY_CLEAN = "legacyClean";
+    private static final String PREF__AUTO_UPLOAD_UPDATE_PATH = "autoUploadPathUpdate";
+
 
     public static boolean instantPictureUploadEnabled(Context context) {
         return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOADING, false);
@@ -189,12 +191,23 @@ public abstract class PreferenceManager {
      * Gets the legacy cleaning flag last set.
      *
      * @param context Caller {@link Context}, used to access to shared preferences manager.
-     * @return ascending order     the alegacy cleaning flag, default is false
+     * @return ascending order     the legacy cleaning flag, default is false
      */
     public static boolean getLegacyClean(Context context) {
         return getDefaultSharedPreferences(context).getBoolean(PREF__LEGACY_CLEAN, false);
     }
 
+    /**
+     * Gets the auto upload paths flag last set.
+     *
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @return ascending order     the legacy cleaning flag, default is false
+     */
+    public static boolean getAutoUploadPathsUpdate(Context context) {
+        return getDefaultSharedPreferences(context).getBoolean(PREF__AUTO_UPLOAD_UPDATE_PATH, false);
+    }
+
+
     /**
      * Saves the legacy cleaning flag which the user has set last.
      *
@@ -205,6 +218,17 @@ public abstract class PreferenceManager {
         saveBooleanPreference(context, PREF__LEGACY_CLEAN, legacyClean);
     }
 
+    /**
+     * Saves the legacy cleaning flag which the user has set last.
+     *
+     * @param context   Caller {@link Context}, used to access to shared preferences manager.
+     * @param pathUpdate flag if it is a auto upload path update
+     */
+    public static void setAutoUploadPathsUpdate(Context context, boolean pathUpdate) {
+        saveBooleanPreference(context, PREF__AUTO_UPLOAD_UPDATE_PATH, pathUpdate);
+    }
+
+
     /**
      * Gets the uploader behavior which the user has set last.
      *