aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/activity/Progress.java10
-rw-r--r--main/src/cgeo/geocaching/cgeodetail.java32
-rw-r--r--tests/src/cgeo/geocaching/activity/ProgressTest.java16
3 files changed, 31 insertions, 27 deletions
diff --git a/main/src/cgeo/geocaching/activity/Progress.java b/main/src/cgeo/geocaching/activity/Progress.java
index 28aaa66..ddb98b2 100644
--- a/main/src/cgeo/geocaching/activity/Progress.java
+++ b/main/src/cgeo/geocaching/activity/Progress.java
@@ -8,28 +8,28 @@ import android.content.Context;
*/
public class Progress {
- private static ProgressDialog dialog;
+ private ProgressDialog dialog;
- public static synchronized void dismiss() {
+ public synchronized void dismiss() {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
dialog = null;
}
- public static synchronized void show(Context context, String title, String message, boolean indeterminate, boolean cancelable) {
+ public synchronized void show(Context context, String title, String message, boolean indeterminate, boolean cancelable) {
if (dialog == null) {
dialog = ProgressDialog.show(context, title, message, indeterminate, cancelable);
}
}
- public static synchronized void setMessage(final String message) {
+ public synchronized void setMessage(final String message) {
if (dialog != null && dialog.isShowing()) {
dialog.setMessage(message);
}
}
- public static synchronized boolean isShowing() {
+ public synchronized boolean isShowing() {
return dialog != null && dialog.isShowing();
}
diff --git a/main/src/cgeo/geocaching/cgeodetail.java b/main/src/cgeo/geocaching/cgeodetail.java
index 4b6558b..01ef151 100644
--- a/main/src/cgeo/geocaching/cgeodetail.java
+++ b/main/src/cgeo/geocaching/cgeodetail.java
@@ -115,6 +115,8 @@ public class cgeodetail extends AbstractActivity {
*/
private boolean disableResumeSetView = false;
+ private Progress progress = new Progress();
+
private Handler storeCacheHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -201,7 +203,7 @@ public class cgeodetail extends AbstractActivity {
}
private void updateStatusMsg(final String msg) {
- Progress.setMessage(res.getString(R.string.cache_dialog_loading_details)
+ progress.setMessage(res.getString(R.string.cache_dialog_loading_details)
+ "\n\n"
+ msg);
}
@@ -269,7 +271,7 @@ public class cgeodetail extends AbstractActivity {
showToast(res.getString(R.string.err_load_descr_failed));
}
- Progress.dismiss();
+ progress.dismiss();
longDescDisplayed = true;
}
@@ -307,7 +309,7 @@ public class cgeodetail extends AbstractActivity {
@Override
public void handleMessage(Message msg) {
watchlistThread = null;
- Progress.dismiss();
+ progress.dismiss();
if (msg.what == -1) {
showToast(res.getString(R.string.err_watchlist_failed));
} else {
@@ -391,7 +393,7 @@ public class cgeodetail extends AbstractActivity {
} else if (StringUtils.isNotBlank(geocode)) {
title = geocode.toUpperCase();
}
- Progress.show(this, title, res.getString(R.string.cache_dialog_loading_details), true, true);
+ progress.show(this, title, res.getString(R.string.cache_dialog_loading_details), true, true);
} catch (Exception e) {
// nothing, we lost the window
}
@@ -616,7 +618,7 @@ public class cgeodetail extends AbstractActivity {
cache = app.getCache(searchId);
if (cache == null) {
- Progress.dismiss();
+ progress.dismiss();
if (StringUtils.isNotBlank(geocode)) {
showToast(res.getString(R.string.err_detail_cache_find) + " " + geocode + ".");
@@ -1083,7 +1085,7 @@ public class cgeodetail extends AbstractActivity {
Log.e(Settings.tag, "cgeodetail.setView: " + e.toString());
}
- Progress.dismiss();
+ progress.dismiss();
displayLogs();
@@ -1367,7 +1369,7 @@ public class cgeodetail extends AbstractActivity {
}
public void loadLongDesc() {
- Progress.show(this, null, res.getString(R.string.cache_dialog_loading_description), true, true);
+ progress.show(this, null, res.getString(R.string.cache_dialog_loading_description), true, true);
threadLongDesc = new loadLongDesc(loadDescriptionHandler);
threadLongDesc.start();
@@ -1670,12 +1672,12 @@ public class cgeodetail extends AbstractActivity {
private class storeCache implements View.OnClickListener {
public void onClick(View arg0) {
- if (Progress.isShowing()) {
+ if (progress.isShowing()) {
showToast(res.getString(R.string.err_detail_still_working));
return;
}
- Progress.show(cgeodetail.this, res.getString(R.string.cache_dialog_offline_save_title), res.getString(R.string.cache_dialog_offline_save_message), true, true);
+ progress.show(cgeodetail.this, res.getString(R.string.cache_dialog_offline_save_title), res.getString(R.string.cache_dialog_offline_save_message), true, true);
if (storeThread != null) {
storeThread.interrupt();
@@ -1688,12 +1690,12 @@ public class cgeodetail extends AbstractActivity {
private class refreshCache implements View.OnClickListener {
public void onClick(View arg0) {
- if (Progress.isShowing()) {
+ if (progress.isShowing()) {
showToast(res.getString(R.string.err_detail_still_working));
return;
}
- Progress.show(cgeodetail.this, res.getString(R.string.cache_dialog_refresh_title), res.getString(R.string.cache_dialog_refresh_message), true, true);
+ progress.show(cgeodetail.this, res.getString(R.string.cache_dialog_refresh_title), res.getString(R.string.cache_dialog_refresh_message), true, true);
if (refreshThread != null) {
refreshThread.interrupt();
@@ -1736,12 +1738,12 @@ public class cgeodetail extends AbstractActivity {
private class dropCache implements View.OnClickListener {
public void onClick(View arg0) {
- if (Progress.isShowing()) {
+ if (progress.isShowing()) {
showToast(res.getString(R.string.err_detail_still_working));
return;
}
- Progress.show(cgeodetail.this, res.getString(R.string.cache_dialog_offline_drop_title), res.getString(R.string.cache_dialog_offline_drop_message), true, false);
+ progress.show(cgeodetail.this, res.getString(R.string.cache_dialog_offline_drop_title), res.getString(R.string.cache_dialog_offline_drop_message), true, false);
Thread thread = new dropCacheThread(dropCacheHandler);
thread.start();
}
@@ -1766,11 +1768,11 @@ public class cgeodetail extends AbstractActivity {
*/
private abstract class AbstractWatchlistClickListener implements View.OnClickListener {
public void doExecute(int titleId, int messageId, Thread thread) {
- if (Progress.isShowing()) {
+ if (progress.isShowing()) {
showToast(res.getString(R.string.err_watchlist_still_managing));
return;
}
- Progress.show(cgeodetail.this, res.getString(titleId), res.getString(messageId), true, true);
+ progress.show(cgeodetail.this, res.getString(titleId), res.getString(messageId), true, true);
if (watchlistThread != null) {
watchlistThread.interrupt();
diff --git a/tests/src/cgeo/geocaching/activity/ProgressTest.java b/tests/src/cgeo/geocaching/activity/ProgressTest.java
index 8d97ce3..5df5272 100644
--- a/tests/src/cgeo/geocaching/activity/ProgressTest.java
+++ b/tests/src/cgeo/geocaching/activity/ProgressTest.java
@@ -10,17 +10,19 @@ public class ProgressTest extends ActivityInstrumentationTestCase2<cgeo> {
}
public void testProgressWrapper() {
- assertFalse(Progress.isShowing()); // nothing shown initially
+ final Progress progress = new Progress();
- Progress.show(getActivity(), "Title", "Message", true, false);
- assertTrue(Progress.isShowing());
+ assertFalse(progress.isShowing()); // nothing shown initially
- Progress.setMessage("Test");
- assertTrue(Progress.isShowing());
+ progress.show(getActivity(), "Title", "Message", true, false);
+ assertTrue(progress.isShowing());
+
+ progress.setMessage("Test");
+ assertTrue(progress.isShowing());
for (int i = 0; i < 2; i++) { // fault tolerant when dismissing to often
- Progress.dismiss();
- assertFalse(Progress.isShowing());
+ progress.dismiss();
+ assertFalse(progress.isShowing());
}
}
}