Merge remote-tracking branch 'remotes/upstream/resizeCache' into beta
authortobiasKaminsky <tobias@kaminsky.me>
Thu, 29 Oct 2015 17:37:28 +0000 (18:37 +0100)
committertobiasKaminsky <tobias@kaminsky.me>
Thu, 29 Oct 2015 17:37:28 +0000 (18:37 +0100)
CHANGELOG.md
res/values/strings.xml
res/xml/preferences.xml
src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java
src/com/owncloud/android/ui/activity/Preferences.java
src/com/owncloud/android/ui/adapter/DiskLruImageCache.java

index 88183ad..4783e30 100644 (file)
@@ -3,6 +3,7 @@
 - PR [#1100](https://github.com/owncloud/android/pull/1100) "Material FAB with speed dial implementation" merged
 - PR [#1209](https://github.com/owncloud/android/pull/1209) "Material buttons - before in #1090" merged
 - PR [#1205](https://github.com/owncloud/android/pull/1205) "Switch between online and offline files" merged
+- PR [#1195](https://github.com/owncloud/android/pull/1195) "Resize Cache" merged
 
 
 # 2015-10-26
index efc87f4..7f88cd7 100644 (file)
     <string name="file_list__footer__files_and_folders">%1$d files, %2$d folders</string>
     <string name="action_switch_grid_view">Switch to grid view</string>
     <string name="action_switch_list_view">Switch to list view</string>
+    <string name="common_category">Common</string>
+    <string name="pref_cache_size">Cache size</string>
+
 </resources>
index 5c853fe..842579b 100644 (file)
                <Preference             android:key="log_history"
                                android:title="@string/prefs_log_title_history"
                                android:summary="@string/prefs_log_summary_history"/ -->
-               <Preference android:title="@string/prefs_help" android:key="help" />
-               <Preference android:title="@string/prefs_recommend" android:key="recommend" />
-               <Preference android:title="@string/prefs_feedback" android:key="feedback" />
-               <Preference android:title="@string/prefs_imprint" android:key="imprint" />
+                        
+    </PreferenceCategory>
+
+       <PreferenceCategory android:title="@string/common_category" android:key="common_category">
+               <EditTextPreference android:title="@string/pref_cache_size"
+                                                       android:key="pref_cache_size"
+                                                       android:digits="0123456789"/>
+       </PreferenceCategory>
 
-               <Preference             android:id="@+id/about_app"
-                       android:title="@string/about_title"
-                       android:key="about_app" />
+       <PreferenceCategory android:title="@string/prefs_category_more" android:key="more">
+    <Preference android:title="@string/prefs_help" android:key="help" />
+    <Preference android:title="@string/prefs_recommend" android:key="recommend" />
+    <Preference android:title="@string/prefs_feedback" android:key="feedback" />
+    <Preference android:title="@string/prefs_imprint" android:key="imprint" />
+                        
+       <Preference             android:id="@+id/about_app" 
+                                       android:title="@string/about_title" 
+                                       android:key="about_app" />
        </PreferenceCategory>
 
 
index e849695..3586fd5 100644 (file)
@@ -147,6 +147,28 @@ public class ThumbnailsCacheManager {
         return null;
     }
 
+    /**
+     * Sets max size of cache
+     * @param maxSize in MB
+     * @return
+     */
+    public static boolean setMaxSize(long maxSize){
+        if (mThumbnailCache != null){
+            mThumbnailCache.setMaxSize(maxSize * 1024 * 1024);
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public static long getMaxSize(){
+        if (mThumbnailCache != null) {
+            return mThumbnailCache.getMaxSize();
+        } else {
+            return -1l;
+        }
+    }
+
     public static class ThumbnailGenerationTask extends AsyncTask<Object, Void, Bitmap> {
         private final WeakReference<ImageView> mImageViewReference;
         private WeakReference<ProgressBar> mProgressWheelRef;
index d980b97..2ffcc86 100644 (file)
@@ -70,6 +70,7 @@ import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.db.DbHandler;
 import com.owncloud.android.files.FileOperationsHelper;
 import com.owncloud.android.files.services.FileDownloader;
@@ -237,6 +238,27 @@ public class Preferences extends PreferenceActivity
             
         }
 
+        final Preference pCacheSize = findPreference("pref_cache_size");
+        if (pCacheSize != null){
+            final SharedPreferences appPrefs =
+                    PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+            Long cacheSize = ThumbnailsCacheManager.getMaxSize();
+            pCacheSize.setSummary(cacheSize + " Mb");
+            pCacheSize.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+                @Override
+                public boolean onPreferenceChange(Preference preference, Object newValue) {
+                    Long size = Long.decode((String) newValue);
+                    if (ThumbnailsCacheManager.setMaxSize(size)){
+                        appPrefs.edit().putString("pref_cache_size", size.toString());
+                        pCacheSize.setSummary(size + " MB");
+                        return true;
+                    } else {
+                        return false;
+                    }
+                }
+            });
+        }
+
         PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
         
         boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
index ab80aef..5a53a86 100644 (file)
@@ -193,4 +193,12 @@ public class DiskLruImageCache {
             e.printStackTrace();
         }
     }
+
+    public void setMaxSize(long maxSize){
+        mDiskCache.setMaxSize(maxSize);
+    }
+
+    public long getMaxSize(){
+        return mDiskCache.getMaxSize();
+    }
 }
\ No newline at end of file