Add clear image memory cache
This commit is contained in:
1 parent
f3f6957910
commit
e9f51e2b1f
7 files changed
+49
-10
No files matched your search
@@ -18,21 +18,26 @@ package com.hippo.ehviewer.ui.scene.preference;
|
||||
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.ehviewer.BuildConfig;
|
||||
import com.hippo.ehviewer.Constants;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.scene.preference.Preference;
|
||||
import com.hippo.scene.preference.PreferenceCategory;
|
||||
import com.hippo.scene.preference.PreferenceScene;
|
||||
import com.hippo.scene.preference.PreferenceSet;
|
||||
import com.hippo.scene.preference.SwitchPreference;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.Messenger;
|
||||
|
||||
public class AdvanceSettingsScene extends PreferenceScene implements Preference.OnValueChangeListener {
|
||||
public class AdvanceSettingsScene extends PreferenceScene implements
|
||||
Preference.OnValueChangeListener, Preference.OnClickListener {
|
||||
|
||||
private static final String KEY_SHOW_APPLICATION_STATS = "show_application_stats";
|
||||
private static final boolean DEFAULT_SHOW_APPLICATION_STATS = BuildConfig.DEBUG;
|
||||
|
||||
private static final String KEY_CLEAR_IMAGE_MEMORY_CACHE = "clear_image_memory_cache";
|
||||
|
||||
@Override
|
||||
protected void onCreate(boolean rebirth) {
|
||||
super.onCreate(rebirth);
|
||||
@@ -51,18 +56,26 @@ public class AdvanceSettingsScene extends PreferenceScene implements Preference.
|
||||
private PreferenceSet[] getPreferenceSet() {
|
||||
Resources resources = getStageActivity().getResources();
|
||||
|
||||
// Stats
|
||||
SwitchPreference statsPreference = new SwitchPreference(KEY_SHOW_APPLICATION_STATS,
|
||||
resources.getString(R.string.settings_show_application_stats_title),
|
||||
resources.getString(R.string.settings_show_application_stats_summary));
|
||||
statsPreference.setDefaultValue(DEFAULT_SHOW_APPLICATION_STATS);
|
||||
statsPreference.setOnValueChangeListener(this);
|
||||
|
||||
// Clear memory cache
|
||||
Conaco conaco = EhApplication.getConaco(getStageActivity());
|
||||
Preference clearMemoryCachePreference = new Preference(KEY_CLEAR_IMAGE_MEMORY_CACHE,
|
||||
resources.getString(R.string.settings_clear_image_memory_cache_title),
|
||||
String.format(resources.getString(R.string.settings_clear_image_memory_cache_summary),
|
||||
FileUtils.humanReadableByteCount(conaco.memoryCacheSize(), false)));
|
||||
clearMemoryCachePreference.setOnClickListener(this);
|
||||
|
||||
PreferenceSet preferenceSet = new PreferenceSet();
|
||||
preferenceSet.setPreferenceCategory(
|
||||
new PreferenceCategory(resources.getString(R.string.settings_advance)));
|
||||
|
||||
preferenceSet.setPreferenceList(new Preference[] {
|
||||
statsPreference
|
||||
statsPreference,
|
||||
clearMemoryCachePreference
|
||||
});
|
||||
|
||||
return new PreferenceSet[] {
|
||||
@@ -81,4 +94,21 @@ public class AdvanceSettingsScene extends PreferenceScene implements Preference.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(Preference preference) {
|
||||
String key = preference.getKey();
|
||||
switch (key) {
|
||||
case KEY_CLEAR_IMAGE_MEMORY_CACHE:
|
||||
Conaco conaco = EhApplication.getConaco(getStageActivity());
|
||||
conaco.clearMemoryCache();
|
||||
Runtime.getRuntime().gc();
|
||||
preference.setSummary(String.format(getStageActivity().getString(
|
||||
R.string.settings_clear_image_memory_cache_summary),
|
||||
FileUtils.humanReadableByteCount(conaco.memoryCacheSize(), false)));
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,12 +26,12 @@ import android.widget.FrameLayout;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
// TODO Need a better way to update it
|
||||
public class Preference extends PreferenceBase {
|
||||
|
||||
private int mPosition;
|
||||
|
||||
private @NonNull
|
||||
String mKey;
|
||||
private @NonNull String mKey;
|
||||
private String mTitle;
|
||||
private String mSummary;
|
||||
|
||||
@@ -57,6 +57,11 @@ public class Preference extends PreferenceBase {
|
||||
return mSummary;
|
||||
}
|
||||
|
||||
public void setSummary(String summary) {
|
||||
mSummary = summary;
|
||||
updateSummary(null);
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user