Browse Source

prevent crash when grid column is -1

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 5 years ago
parent
commit
02eaa886ae

+ 8 - 1
src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java

@@ -47,6 +47,7 @@ public final class AppPreferencesImpl implements AppPreferences {
      */
     public static final String AUTO_PREF__LAST_SEEN_VERSION_CODE = "lastSeenVersionCode";
     public static final String STORAGE_PATH = "storage_path";
+    public static final float DEFAULT_GRID_COLUMN = 4.0f;
     private static final String AUTO_PREF__LAST_UPLOAD_PATH = "last_upload_path";
     private static final String AUTO_PREF__UPLOAD_FROM_LOCAL_LAST_PATH = "upload_from_local_last_path";
     private static final String AUTO_PREF__UPLOAD_FILE_EXTENSION_MAP_URL = "prefs_upload_file_extension_map_url";
@@ -351,7 +352,13 @@ public final class AppPreferencesImpl implements AppPreferences {
      */
     @Override
     public float getGridColumns() {
-        return preferences.getFloat(AUTO_PREF__GRID_COLUMNS, 4.0f);
+        float columns = preferences.getFloat(AUTO_PREF__GRID_COLUMNS, DEFAULT_GRID_COLUMN);
+
+        if (columns < 0) {
+            return DEFAULT_GRID_COLUMN;
+        } else {
+            return columns;
+        }
     }
 
     /**

+ 5 - 3
src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -56,6 +56,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.preferences.AppPreferences;
+import com.nextcloud.client.preferences.AppPreferencesImpl;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.lib.common.utils.Log_OC;
@@ -136,7 +137,7 @@ public class ExtendedListFragment extends Fragment implements
     protected SearchView searchView;
     private Handler handler = new Handler(Looper.getMainLooper());
 
-    private float mScale = -1f;
+    private float mScale = AppPreferencesImpl.DEFAULT_GRID_COLUMN;
 
     @Parcel
     public enum SearchType {
@@ -454,8 +455,6 @@ public class ExtendedListFragment extends Fragment implements
             mTops = new ArrayList<>();
             mHeightCell = 0;
         }
-
-        mScale = preferences.getGridColumns();
     }
 
 
@@ -474,6 +473,9 @@ public class ExtendedListFragment extends Fragment implements
     }
 
     public int getColumnsCount() {
+        if (mScale == -1) {
+            return Math.round(AppPreferencesImpl.DEFAULT_GRID_COLUMN);
+        }
         return Math.round(mScale);
     }