aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src/github
diff options
context:
space:
mode:
Diffstat (limited to 'subsonic-android/src/github')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java6
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java3
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java45
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/ModalBackgroundTask.java150
5 files changed, 38 insertions, 170 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
index 98454d4a..f5aea74a 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
@@ -39,9 +39,9 @@ import github.daneren2005.dsub.service.DownloadServiceImpl;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.view.ErrorDialog;
import github.daneren2005.dsub.util.FileUtil;
-import github.daneren2005.dsub.util.ModalBackgroundTask;
import github.daneren2005.dsub.util.Util;
import java.io.File;
@@ -116,7 +116,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
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) {
+ new LoadingTask<Void>(SettingsActivity.this, false) {
@Override
protected Void doInBackground() throws Throwable {
FileUtil.deleteMusicDirectory(SettingsActivity.this);
@@ -410,7 +410,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
}
private void testConnection(final int instance) {
- ModalBackgroundTask<Boolean> task = new ModalBackgroundTask<Boolean>(this, false) {
+ LoadingTask<Boolean> task = new LoadingTask<Boolean>(this) {
private int previousInstance;
@Override
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
index 1c8afbaa..9a48acd5 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -19,6 +19,7 @@ import github.daneren2005.dsub.R;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
+import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.view.MergeAdapter;
import github.daneren2005.dsub.util.Util;
import com.actionbarsherlock.view.Menu;
@@ -26,7 +27,6 @@ import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.MenuInflater;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
-import github.daneren2005.dsub.util.ModalBackgroundTask;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.view.ChangeLog;
import java.io.File;
@@ -326,7 +326,7 @@ public class MainFragment extends SubsonicFragment {
private void getLogs() {
try {
final String version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
- new ModalBackgroundTask<File>(context, false) {
+ new LoadingTask<File>(context) {
@Override
protected File doInBackground() throws Throwable {
updateProgress("Gathering Logs");
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index 9b16fdcb..9e8ec29c 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -61,7 +61,6 @@ import github.daneren2005.dsub.service.ServerTooOldException;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.ImageLoader;
-import github.daneren2005.dsub.util.ModalBackgroundTask;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.util.Util;
@@ -570,7 +569,7 @@ public class SubsonicFragment extends SherlockFragment {
downloadRecursively(id, name, false, save, append, autoplay, shuffle, background);
}
protected void downloadRecursively(final String id, final String name, final boolean isDirectory, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) {
- ModalBackgroundTask<List<MusicDirectory.Entry>> task = new ModalBackgroundTask<List<MusicDirectory.Entry>>(context, false) {
+ LoadingTask<List<MusicDirectory.Entry>> task = new LoadingTask<List<MusicDirectory.Entry>>(context) {
private static final int MAX_SONGS = 500;
@Override
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java b/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java
index 0b48a338..9ab5c86d 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java
@@ -1,7 +1,9 @@
package github.daneren2005.dsub.util;
+import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
+
import github.daneren2005.dsub.activity.SubsonicActivity;
/**
@@ -10,11 +12,18 @@ import github.daneren2005.dsub.activity.SubsonicActivity;
*/
public abstract class LoadingTask<T> extends BackgroundTask<T> {
- private final SubsonicActivity tabActivity;
+ private final Activity tabActivity;
+ private ProgressDialog loading;
+ private Thread thread;
private final boolean cancellable;
private boolean cancelled = false;
- public LoadingTask(SubsonicActivity activity, final boolean cancellable) {
+ public LoadingTask(Activity activity) {
+ super(activity);
+ tabActivity = activity;
+ this.cancellable = true;
+ }
+ public LoadingTask(Activity activity, final boolean cancellable) {
super(activity);
tabActivity = activity;
this.cancellable = cancellable;
@@ -22,14 +31,14 @@ public abstract class LoadingTask<T> extends BackgroundTask<T> {
@Override
public void execute() {
- final ProgressDialog loading = ProgressDialog.show(tabActivity, "", "Loading. Please Wait...", true, cancellable, new DialogInterface.OnCancelListener() {
+ loading = ProgressDialog.show(tabActivity, "", "Loading. Please Wait...", true, cancellable, new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
- cancelled = true;
+ cancel();
}
});
- new Thread() {
+ thread = new Thread() {
@Override
public void run() {
try {
@@ -59,20 +68,30 @@ public abstract class LoadingTask<T> extends BackgroundTask<T> {
});
}
}
- }.start();
+ };
+ thread.start();
}
+ protected void cancel() {
+ cancelled = true;
+ if (thread != null) {
+ thread.interrupt();
+ }
+ }
+
private boolean isCancelled() {
- return tabActivity.isDestroyed() || cancelled;
+ return (tabActivity instanceof SubsonicActivity && ((SubsonicActivity)tabActivity).isDestroyed()) || cancelled;
}
@Override
public void updateProgress(final String message) {
- getHandler().post(new Runnable() {
- @Override
- public void run() {
-
- }
- });
+ if(!cancelled) {
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ loading.setMessage(message);
+ }
+ });
+ }
}
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/ModalBackgroundTask.java b/subsonic-android/src/github/daneren2005/dsub/util/ModalBackgroundTask.java
deleted file mode 100644
index f0310780..00000000
--- a/subsonic-android/src/github/daneren2005/dsub/util/ModalBackgroundTask.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- This file is part of Subsonic.
-
- Subsonic is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Subsonic is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
-
- Copyright 2009 (C) Sindre Mehus
- */
-package github.daneren2005.dsub.util;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.util.Log;
-import github.daneren2005.dsub.R;
-import github.daneren2005.dsub.view.ErrorDialog;
-
-/**
- * @author Sindre Mehus
- */
-public abstract class ModalBackgroundTask<T> extends BackgroundTask<T> {
-
- private static final String TAG = ModalBackgroundTask.class.getSimpleName();
-
- private final AlertDialog progressDialog;
- private Thread thread;
- private final boolean finishActivityOnCancel;
- private boolean cancelled;
-
- public ModalBackgroundTask(Activity activity, boolean finishActivityOnCancel) {
- super(activity);
- this.finishActivityOnCancel = finishActivityOnCancel;
- progressDialog = createProgressDialog();
- }
-
- public ModalBackgroundTask(Activity activity) {
- this(activity, true);
- }
-
- private AlertDialog createProgressDialog() {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder.setIcon(android.R.drawable.ic_dialog_info);
- builder.setTitle(R.string.background_task_wait);
- builder.setMessage(R.string.background_task_loading);
- builder.setCancelable(true);
- builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface dialogInterface) {
- cancel();
- }
- });
- builder.setPositiveButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- cancel();
- }
- });
-
- return builder.create();
- }
-
- public void execute() {
- cancelled = false;
- progressDialog.show();
-
- thread = new Thread() {
- @Override
- public void run() {
- try {
- final T result = doInBackground();
- if (cancelled) {
- progressDialog.dismiss();
- return;
- }
-
- getHandler().post(new Runnable() {
- @Override
- public void run() {
- try {
- progressDialog.dismiss();
- } catch(Exception e) {
- Log.w(TAG, "Failed to dismiss dialog");
- }
- done(result);
- }
- });
-
- } catch (final Throwable t) {
- if (cancelled) {
- return;
- }
- getHandler().post(new Runnable() {
- @Override
- public void run() {
- try {
- progressDialog.dismiss();
- } catch(Exception e) {
- Log.w(TAG, "Failed to dismiss dialog");
- }
- error(t);
- }
- });
- }
- }
- };
- thread.start();
- }
-
- protected void cancel() {
- cancelled = true;
- if (thread != null) {
- thread.interrupt();
- }
-
- if (finishActivityOnCancel) {
- getActivity().finish();
- }
- }
-
- protected boolean isCancelled() {
- return cancelled;
- }
-
- protected void error(Throwable error) {
- Log.w(TAG, "Got exception: " + error, error);
- new ErrorDialog(getActivity(), getErrorMessage(error), finishActivityOnCancel);
- }
-
- @Override
- public void updateProgress(final String message) {
- if(!cancelled) {
- getHandler().post(new Runnable() {
- @Override
- public void run() {
- progressDialog.setMessage(message);
- }
- });
- }
- }
-}