diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-07-21 12:00:47 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-07-21 12:00:47 -0700 |
commit | 8dbb7aa01530b55a4a0b751b22098585578c5838 (patch) | |
tree | 668b272133795b8d0efbfa8c809137a4209de2f3 /subsonic-android/src | |
parent | b063f48d564e26a061caf82ce76e44439ce59160 (diff) | |
download | dsub-8dbb7aa01530b55a4a0b751b22098585578c5838.tar.gz dsub-8dbb7aa01530b55a4a0b751b22098585578c5838.tar.bz2 dsub-8dbb7aa01530b55a4a0b751b22098585578c5838.zip |
Close #108 Add clear cache option in settings
Diffstat (limited to 'subsonic-android/src')
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java | 30 | ||||
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java | 4 |
2 files changed, 33 insertions, 1 deletions
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) { |