aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-06-22 10:09:16 -0700
committerScott Jackson <daneren2005@gmail.com>2013-06-22 10:09:16 -0700
commit6e14f332abb5e0128dc19ea4bbe86b8fe8c742ff (patch)
tree429d1bfaf91ad72e3be617df48cfc381bea5278f /subsonic-android/src
parent51e3c8143dddb8192b6c1aa035e70c462902b338 (diff)
downloaddsub-6e14f332abb5e0128dc19ea4bbe86b8fe8c742ff.tar.gz
dsub-6e14f332abb5e0128dc19ea4bbe86b8fe8c742ff.tar.bz2
dsub-6e14f332abb5e0128dc19ea4bbe86b8fe8c742ff.zip
Move to more abstract offline sync dialog that can support more syncs, added option for default action
Diffstat (limited to 'subsonic-android/src')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java90
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java10
3 files changed, 70 insertions, 31 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
index 45d6eb49..bf8cfdbb 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -14,6 +14,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
+import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
@@ -207,7 +208,7 @@ public class MainFragment extends SubsonicFragment {
if(isOffline) {
int count = Util.offlineScrobblesCount(context);
if(count > 0){
- showOfflineScrobblesDialog(count);
+ showOfflineSyncDialog(count);
}
}
}
@@ -228,36 +229,33 @@ public class MainFragment extends SubsonicFragment {
}
}
- private void showOfflineScrobblesDialog(final int count) {
+ private void showOfflineSyncDialog(final int scrobbleCount) {
+ String syncDefault = Util.getSyncDefault(context);
+ if(syncDefault != null) {
+ if("sync".equals(syncDefault)) {
+ syncOffline(scrobbleCount);
+ return;
+ } else if("delete".equals(syncDefault)) {
+ deleteOffline();
+ return;
+ }
+ }
+
+ View checkBoxView = context.getLayoutInflater().inflate(R.layout.sync_dialog, null);
+ final CheckBox checkBox = (CheckBox)checkBoxView.findViewById(R.id.sync_default);
+
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setIcon(android.R.drawable.ic_dialog_info)
- .setTitle(R.string.offline_scrobbles_dialog_title)
- .setMessage(R.string.offline_scrobbles_dialog_message)
+ .setTitle(R.string.offline_sync_dialog_title)
+ .setMessage(context.getResources().getString(R.string.offline_sync_dialog_message, scrobbleCount))
+ .setView(checkBoxView)
.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
- new SilentBackgroundTask<Integer>(context) {
- @Override
- protected Integer doInBackground() throws Throwable {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
- return musicService.processOfflineScrobbles(context, null);
- }
-
- @Override
- protected void done(Integer result) {
- if(result == count) {
- Util.toast(context, context.getResources().getString(R.string.offline_scrobbles_success, result));
- } else {
- Util.toast(context, context.getResources().getString(R.string.offline_scrobbles_partial, result, count));
- }
- }
-
- @Override
- protected void error(Throwable error) {
- String msg = context.getResources().getString(R.string.offline_scrobbles_error) + " " + getErrorMessage(error);
- Util.toast(context, msg);
- }
- }.execute();
+ if(checkBox.isChecked()) {
+ Util.setSyncDefault(context, "sync");
+ }
+ syncOffline(scrobbleCount);
}
}).setNeutralButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
@Override
@@ -267,15 +265,45 @@ public class MainFragment extends SubsonicFragment {
}).setNegativeButton(R.string.common_delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- SharedPreferences.Editor offline = Util.getOfflineSync(context).edit();
- offline.putInt(Constants.OFFLINE_SCROBBLE_COUNT, 0);
- offline.commit();
+ if(checkBox.isChecked()) {
+ Util.setSyncDefault(context, "delete");
+ }
+ deleteOffline();
}
});
builder.create().show();
- }
+ }
+
+ private void syncOffline(final int scrobbleCount) {
+ new SilentBackgroundTask<Integer>(context) {
+ @Override
+ protected Integer doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ return musicService.processOfflineScrobbles(context, null);
+ }
+
+ @Override
+ protected void done(Integer result) {
+ if(result == scrobbleCount) {
+ Util.toast(context, context.getResources().getString(R.string.offline_sync_success, result));
+ } else {
+ Util.toast(context, context.getResources().getString(R.string.offline_sync_partial, result, scrobbleCount));
+ }
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg = context.getResources().getString(R.string.offline_sync_error) + " " + getErrorMessage(error);
+ Util.toast(context, msg);
+ }
+ }.execute();
+ }
+ private void deleteOffline() {
+ SharedPreferences.Editor offline = Util.getOfflineSync(context).edit();
+ offline.putInt(Constants.OFFLINE_SCROBBLE_COUNT, 0);
+ offline.commit();
+ }
private void showAboutDialog() {
try {
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
index a2f43dcd..7c7f67a4 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
@@ -126,6 +126,7 @@ public final class Constants {
// Name of the preferences file.
public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences";
public static final String OFFLINE_SYNC_NAME = "github.daneren2005.dsub.offline";
+ public static final String OFFLINE_SYNC_DEFAULT = "syncDefaults";
// Number of free trial days for non-licensed servers.
public static final int FREE_TRIAL_DAYS = 30;
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index b7ff5604..b8cc9471 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -363,6 +363,16 @@ public final class Util {
return context.getSharedPreferences(Constants.OFFLINE_SYNC_NAME, 0);
}
+ public static String getSyncDefault(Context context) {
+ SharedPreferences prefs = Util.getOfflineSync(context);
+ return prefs.getString(Constants.OFFLINE_SYNC_DEFAULT, null);
+ }
+ public static void setSyncDefault(Context context, String defaultValue) {
+ SharedPreferences.Editor editor = Util.getOfflineSync(context).edit();
+ editor.putString(Constants.OFFLINE_SYNC_DEFAULT, defaultValue);
+ editor.commit();
+ }
+
public static int offlineScrobblesCount(Context context) {
SharedPreferences offline = getOfflineSync(context);
return offline.getInt(Constants.OFFLINE_SCROBBLE_COUNT, 0);