Merge pull request #4621 from nextcloud/gridCrash

prevent crash when grid column is -1
This commit is contained in:
Andy Scherzinger 2019-10-08 09:43:15 +02:00 committed by GitHub
commit 1b6b909a8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -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 AUTO_PREF__LAST_SEEN_VERSION_CODE = "lastSeenVersionCode";
public static final String STORAGE_PATH = "storage_path"; 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__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_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"; 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 @Override
public float getGridColumns() { 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;
}
} }
/** /**

View file

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