Andy Scherzinger 8 年之前
父節點
當前提交
dd9b0b8adc

+ 29 - 6
src/com/owncloud/android/db/PreferenceManager.java

@@ -38,6 +38,7 @@ public abstract class PreferenceManager {
     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_URL = "prefs_upload_file_extension_url";
     private static final String AUTO_PREF__UPLOADER_BEHAVIOR = "prefs_uploader_behaviour";
+    private static final String AUTO_PREF__GRID_COLUMNS = "grid_columns";
     private static final String PREF__INSTANT_UPLOADING = "instant_uploading";
     private static final String PREF__INSTANT_VIDEO_UPLOADING = "instant_video_uploading";
     private static final String PREF__INSTANT_UPLOAD_PATH_USE_SUBFOLDERS = "instant_upload_path_use_subfolders";
@@ -205,22 +206,44 @@ public abstract class PreferenceManager {
         saveIntPreference(context, AUTO_PREF__UPLOADER_BEHAVIOR, uploaderBehaviour);
     }
 
+    /**
+     * Gets the grid columns which the user has set last.
+     *
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @return grid columns     grid columns
+     */
+    public static float getGridColumns(Context context) {
+        return getDefaultSharedPreferences(context).getFloat(AUTO_PREF__GRID_COLUMNS, -1.0f);
+    }
+
+    /**
+     * Saves the grid columns which the user has set last.
+     *
+     * @param context   Caller {@link Context}, used to access to shared preferences manager.
+     * @param gridColumns the uploader behavior
+     */
+    public static void setGridColumns(Context context, float gridColumns) {
+        saveFloatPreference(context, AUTO_PREF__GRID_COLUMNS, gridColumns);
+    }
+
     public static void saveBooleanPreference(Context context, String key, boolean value) {
         SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
-        appPreferences.putBoolean(key, value);
-        appPreferences.apply();
+        appPreferences.putBoolean(key, value).apply();
     }
 
     private static void saveStringPreference(Context context, String key, String value) {
         SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
-        appPreferences.putString(key, value);
-        appPreferences.apply();
+        appPreferences.putString(key, value).apply();
     }
 
     private static void saveIntPreference(Context context, String key, int value) {
         SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
-        appPreferences.putInt(key, value);
-        appPreferences.apply();
+        appPreferences.putInt(key, value).apply();
+    }
+
+    public static void saveFloatPreference(Context context, String key, float value) {
+        SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
+        appPreferences.putFloat(key, value).apply();
     }
 
     public static SharedPreferences getDefaultSharedPreferences(Context context) {

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

@@ -20,10 +20,7 @@
 
 package com.owncloud.android.ui.fragment;
 
-import android.content.SharedPreferences;
-import android.os.Build;
 import android.os.Bundle;
-import android.preference.PreferenceManager;
 import android.support.annotation.DrawableRes;
 import android.support.annotation.StringRes;
 import android.support.v4.app.Fragment;
@@ -52,6 +49,7 @@ import com.getbase.floatingactionbutton.FloatingActionButton;
 import com.getbase.floatingactionbutton.FloatingActionsMenu;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
+import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.ExtendedListView;
 import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
@@ -78,11 +76,9 @@ public class ExtendedListFragment extends Fragment
     public static final float minColumnSize = 2.0f;
     public static final float maxColumnSize = 10.0f;
 
-    private ScaleGestureDetector SGD = null;
-
     private ScaleGestureDetector mScaleGestureDetector = null;
-    private SwipeRefreshLayout mRefreshListLayout;
-    private SwipeRefreshLayout mRefreshGridLayout;
+    protected SwipeRefreshLayout mRefreshListLayout;
+    protected SwipeRefreshLayout mRefreshGridLayout;
     protected SwipeRefreshLayout mRefreshEmptyLayout;
     protected LinearLayout mEmptyListContainer;
     protected TextView mEmptyListMessage;
@@ -309,9 +305,7 @@ public class ExtendedListFragment extends Fragment
             mHeightCell = 0;
         }
 
-        SharedPreferences appPreferences = PreferenceManager
-                .getDefaultSharedPreferences(getContext());
-        mScale = appPreferences.getFloat(GRID_COLUMNS, -1.0f);
+        mScale = PreferenceManager.getGridColumns(getContext());
     }    
     
     
@@ -327,9 +321,7 @@ public class ExtendedListFragment extends Fragment
         savedInstanceState.putInt(KEY_HEIGHT_CELL, mHeightCell);
         savedInstanceState.putString(KEY_EMPTY_LIST_MESSAGE, getEmptyViewText());
 
-        SharedPreferences.Editor editor = PreferenceManager
-                .getDefaultSharedPreferences(getContext()).edit();
-        editor.putFloat(GRID_COLUMNS, mScale).apply();
+        PreferenceManager.setGridColumns(getContext(), mScale);
     }
 
     /**