cache resize
authortobiasKaminsky <tobias@kaminsky.me>
Mon, 12 Oct 2015 06:30:30 +0000 (08:30 +0200)
committertobiasKaminsky <tobias@kaminsky.me>
Mon, 12 Oct 2015 06:30:30 +0000 (08:30 +0200)
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 3d8726f..a8bb60a 100644 (file)
     <string name="file_list__footer__files_and_folder">%1$d files, 1 folder</string>
     <string name="file_list__footer__files_and_folders">%1$d files, %2$d folders</string>
     <string name="common_category">Common</string>
+    <string name="pref_cache_size">Cache size</string>
 
 </resources>
index e2e35de..7dfc63f 100644 (file)
@@ -55,7 +55,9 @@
     </PreferenceCategory>
 
        <PreferenceCategory android:title="@string/common_category" android:key="common_category">
-               <EditTextPreference android:title="Cache size (in MB)" android:key="pref_cache_size" android:digits="0123456789"/>
+               <EditTextPreference android:title="@string/pref_cache_size"
+                                                       android:key="pref_cache_size"
+                                                       android:digits="0123456789"/>
        </PreferenceCategory>
 
        <PreferenceCategory android:title="@string/prefs_category_more" android:key="more">
index f0ecf76..d1be900 100644 (file)
@@ -140,6 +140,20 @@ 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 class ThumbnailGenerationTask extends AsyncTask<Object, Void, Bitmap> {
         private final WeakReference<ImageView> mImageViewReference;
         private static Account mAccount;
index e1c5c10..16bee15 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,28 @@ public class Preferences extends PreferenceActivity
             
         }
 
+        final Preference pCacheSize = findPreference("pref_cache_size");
+        if (pCacheSize != null){
+            final SharedPreferences appPrefs =
+                    PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+            String savedSize = appPrefs.getString("pref_cache_size", "10");
+            pCacheSize.setSummary(savedSize + " Mb");
+            pCacheSize.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+                @Override
+                public boolean onPreferenceChange(Preference preference, Object newValue) {
+                    String temp = (String) newValue;
+                    Long size = Long.decode(temp);
+                    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 0f2536f..b5c0403 100644 (file)
@@ -193,4 +193,8 @@ public class DiskLruImageCache {
             e.printStackTrace();
         }
     }
+
+    public void setMaxSize(long maxSize){
+        mDiskCache.setMaxSize(maxSize);
+    }
 }
\ No newline at end of file