aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-07-21 12:00:47 -0700
committerScott Jackson <daneren2005@gmail.com>2013-07-21 12:00:47 -0700
commit8dbb7aa01530b55a4a0b751b22098585578c5838 (patch)
tree668b272133795b8d0efbfa8c809137a4209de2f3
parentb063f48d564e26a061caf82ce76e44439ce59160 (diff)
downloaddsub-8dbb7aa01530b55a4a0b751b22098585578c5838.tar.gz
dsub-8dbb7aa01530b55a4a0b751b22098585578c5838.tar.bz2
dsub-8dbb7aa01530b55a4a0b751b22098585578c5838.zip
Close #108 Add clear cache option in settings
-rw-r--r--subsonic-android/res/values/strings.xml2
-rw-r--r--subsonic-android/res/xml/settings.xml4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java30
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java4
4 files changed, 39 insertions, 1 deletions
diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml
index 65dfc9d1..0b2815ec 100644
--- a/subsonic-android/res/values/strings.xml
+++ b/subsonic-android/res/values/strings.xml
@@ -226,6 +226,8 @@
<string name="settings.cache_size">Cache size (MB)</string>
<string name="settings.cache_location">Cache location</string>
<string name="settings.cache_location_error">Invalid cache location. Using default.</string>
+ <string name="settings.cache_clear">Clear Cache</string>
+ <string name="settings.cache_clear_complete">Finished clearing cache</string>
<string name="settings.testing_connection">Testing connection...</string>
<string name="settings.testing_ok">Connection is OK</string>
<string name="settings.testing_unlicensed">Connection is OK. Server unlicensed.</string>
diff --git a/subsonic-android/res/xml/settings.xml b/subsonic-android/res/xml/settings.xml
index af2b567a..eb139b83 100644
--- a/subsonic-android/res/xml/settings.xml
+++ b/subsonic-android/res/xml/settings.xml
@@ -144,6 +144,10 @@
android:entryValues="@array/preloadCountValues"
android:entries="@array/preloadCountNames"/>
+ <Preference
+ android:key="clearCache"
+ android:title="@string/settings.cache_clear"
+ android:persistent="false"/>
</PreferenceCategory>
<PreferenceCategory
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
index 220b635d..589ff032 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
@@ -23,7 +23,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
-import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
@@ -43,6 +42,7 @@ import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ErrorDialog;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.ModalBackgroundTask;
+import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.Util;
import java.io.File;
@@ -111,6 +111,34 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
return false;
}
});
+ findPreference("clearCache").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ Util.confirmDialog(SettingsActivity.this, R.string.common_delete, "cache", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ new ModalBackgroundTask<Void>(SettingsActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ FileUtil.deleteMusicDirectory(SettingsActivity.this);
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ Util.toast(SettingsActivity.this, R.string.settings_cache_clear_complete);
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ Util.toast(SettingsActivity.this, getErrorMessage(error), false);
+ }
+ }.execute();
+ }
+ });
+ return false;
+ }
+ });
addServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java
index cf804f74..34bc82bd 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java
@@ -204,6 +204,10 @@ public class FileUtil {
File dir = new File(path);
return ensureDirectoryExistsAndIsReadWritable(dir) ? dir : getDefaultMusicDirectory();
}
+ public static boolean deleteMusicDirectory(Context context) {
+ File musicDirectory = FileUtil.getMusicDirectory(context);
+ return Util.recursiveDelete(musicDirectory);
+ }
public static boolean ensureDirectoryExistsAndIsReadWritable(File dir) {
if (dir == null) {