diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-10-23 17:54:57 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-10-23 17:54:57 -0700 |
commit | 85d147265a5f85840f25bb4163f5f9899095ae24 (patch) | |
tree | 2180e0c2fde17a1a51f0d72f1a8b145446ddf32f /subsonic-android/src/github/daneren2005 | |
parent | 728fc5b1573217ee5d216d057c4f42c34d13e582 (diff) | |
download | dsub-85d147265a5f85840f25bb4163f5f9899095ae24.tar.gz dsub-85d147265a5f85840f25bb4163f5f9899095ae24.tar.bz2 dsub-85d147265a5f85840f25bb4163f5f9899095ae24.zip |
Added loading task for certain actions #40
Diffstat (limited to 'subsonic-android/src/github/daneren2005')
3 files changed, 81 insertions, 3 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index 69a1fe68..82405f51 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -469,7 +469,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity { return; } - new TabActivityBackgroundTask<List<Playlist>>(this) { + new LoadingTask<List<Playlist>>(this, true) { @Override protected List<Playlist> doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this); diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java index 028966a1..9aa13070 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java @@ -188,7 +188,7 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - new TabActivityBackgroundTask<Void>(SelectPlaylistActivity.this) { + new LoadingTask<Void>(SelectPlaylistActivity.this, false) { @Override protected Void doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); @@ -246,7 +246,7 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - new TabActivityBackgroundTask<Void>(SelectPlaylistActivity.this) { + new LoadingTask<Void>(SelectPlaylistActivity.this, false) { @Override protected Void doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java b/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java new file mode 100644 index 00000000..0875742f --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java @@ -0,0 +1,78 @@ +package github.daneren2005.dsub.util;
+
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
+import github.daneren2005.dsub.activity.SubsonicTabActivity;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public abstract class LoadingTask<T> extends BackgroundTask<T> {
+
+ private final SubsonicTabActivity tabActivity;
+ private final boolean cancellable;
+ private boolean cancelled = false;
+
+ public LoadingTask(SubsonicTabActivity activity, final boolean cancellable) {
+ super(activity);
+ tabActivity = activity;
+ this.cancellable = cancellable;
+ }
+
+ @Override
+ public void execute() {
+ final ProgressDialog loading = ProgressDialog.show(tabActivity, "", "Loading. Please Wait...", true, cancellable, new DialogInterface.OnCancelListener() {
+ public void onCancel(DialogInterface dialog) {
+ cancelled = true;
+ }
+
+ });
+
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ final T result = doInBackground();
+ if (isCancelled()) {
+ return;
+ }
+
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ loading.cancel();
+ done(result);
+ }
+ });
+ } catch (final Throwable t) {
+ if (isCancelled()) {
+ return;
+ }
+
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ loading.cancel();
+ error(t);
+ }
+ });
+ }
+ }
+ }.start();
+ }
+
+ private boolean isCancelled() {
+ return tabActivity.isDestroyed() || cancelled;
+ }
+
+ @Override
+ public void updateProgress(final String message) {
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+
+ }
+ });
+ }
+}
|