Browse Source

Fix a bug with storage settings

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 years ago
parent
commit
833c7f5773

+ 2 - 4
src/main/java/com/owncloud/android/MainApp.java

@@ -103,8 +103,6 @@ public class MainApp extends MultiDexApplication {
 
     private static boolean mOnlyOnDevice = false;
 
-    private static final String KEY_LAST_SEEN_VERSION_CODE = "lastSeenVersionCode";
-
     private SharedPreferences appPrefs;
     @SuppressWarnings("unused")
     private boolean mBound;
@@ -219,11 +217,11 @@ public class MainApp extends MultiDexApplication {
 
     private void fixStoragePath() {
         if (!PreferenceManager.getStoragePathFix(this) &&
-                appPrefs.getInt(KEY_LAST_SEEN_VERSION_CODE, 0) != 0) {
+                appPrefs.getInt(WhatsNewActivity.KEY_LAST_SEEN_VERSION_CODE, 0) != 0) {
             String storagePath = appPrefs.getString(Preferences.PreferenceKeys.STORAGE_PATH, "");
             if (TextUtils.isEmpty(storagePath)) {
                 storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
-                StoragePoint[] storagePoints = DataStorageProvider.getInstance().getAvailableStoragePoints();
+                StoragePoint[] storagePoints = DataStorageProvider.getInstance().getLegacyAvailableStoragePoints();
                 for(StoragePoint storagePoint : storagePoints) {
                     if (storagePoint.getPath().startsWith(storagePath)) {
                         storagePath = storagePoint.getPath();

+ 24 - 0
src/main/java/com/owncloud/android/datastorage/DataStorageProvider.java

@@ -21,6 +21,7 @@
 
 package com.owncloud.android.datastorage;
 
+import android.os.Build;
 import android.os.Environment;
 
 import com.owncloud.android.MainApp;
@@ -31,6 +32,7 @@ import com.owncloud.android.datastorage.providers.MountCommandStoragePointProvid
 import com.owncloud.android.datastorage.providers.SystemDefaultStoragePointProvider;
 import com.owncloud.android.datastorage.providers.VDCStoragePointProvider;
 
+import java.io.File;
 import java.util.Vector;
 
 /**
@@ -57,6 +59,28 @@ public class DataStorageProvider {
 
     private DataStorageProvider() {}
 
+    public StoragePoint[] getLegacyAvailableStoragePoints() {
+        if (mCachedStoragePoints.size() != 0) {
+            return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);
+        }
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            for (File f : MainApp.getAppContext().getExternalMediaDirs()) {
+                if (f != null) {
+                    mCachedStoragePoints.add(new StoragePoint(f.getAbsolutePath(), f.getAbsolutePath()));
+                }
+            }
+        } else {
+            for (IStoragePointProvider p : mStorageProviders) {
+                if (p.canProvideStoragePoints()) {
+                    mCachedStoragePoints.addAll(p.getAvailableStoragePoint());
+                }
+            }
+        }
+
+        return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);
+    }
+
     public StoragePoint[] getAvailableStoragePoints() {
         if (mCachedStoragePoints.size() != 0) {
             return mCachedStoragePoints.toArray(new StoragePoint[mCachedStoragePoints.size()]);

+ 1 - 1
src/main/java/com/owncloud/android/ui/activity/WhatsNewActivity.java

@@ -62,7 +62,7 @@ import com.owncloud.android.utils.ThemeUtils;
  */
 public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPageChangeListener {
 
-    private static final String KEY_LAST_SEEN_VERSION_CODE = "lastSeenVersionCode";
+    public static final String KEY_LAST_SEEN_VERSION_CODE = "lastSeenVersionCode";
 
     private static final String SCREEN_NAME = "What's new";