aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-03-11 05:47:12 +0100
committerSamuel Tardieu <sam@rfc1149.net>2014-03-11 05:50:58 +0100
commit56b6b5bc0714a4c9ebdbf7e9dd3315877d4e1cd4 (patch)
treecad9b1d7470e05cb24d05bd68586d3b2669d3fe1 /main
parentc6bbc8c732243b7a88e4d65856b93e21081bcf4f (diff)
downloadcgeo-56b6b5bc0714a4c9ebdbf7e9dd3315877d4e1cd4.zip
cgeo-56b6b5bc0714a4c9ebdbf7e9dd3315877d4e1cd4.tar.gz
cgeo-56b6b5bc0714a4c9ebdbf7e9dd3315877d4e1cd4.tar.bz2
refactoring: remove cache thread operations
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java74
-rw-r--r--main/src/cgeo/geocaching/CachePopup.java25
2 files changed, 24 insertions, 75 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 80e1f7b..55cfb2b 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -58,6 +58,7 @@ import org.apache.commons.lang3.tuple.Pair;
import rx.Observable;
import rx.Observable.OnSubscribe;
import rx.Observer;
+import rx.Scheduler.Inner;
import rx.Subscriber;
import rx.Subscription;
import rx.android.observables.AndroidObservable;
@@ -300,8 +301,15 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
});
- // Initialization done. Let's load the data with the given information.
- new LoadCacheThread(geocode, guid, loadCacheHandler).start();
+ final String realGeocode = geocode;
+ final String realGuid = guid;
+ Schedulers.io().schedule(new Action1<Inner>() {
+ @Override
+ public void call(final Inner inner) {
+ search = Geocache.searchByGeocode(realGeocode, StringUtils.isBlank(realGeocode) ? realGuid : null, 0, false, loadCacheHandler);
+ loadCacheHandler.sendMessage(Message.obtain());
+ }
+ });
}
@Override
@@ -601,37 +609,6 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
/**
- * Loads the cache with the given geocode or guid.
- */
- private class LoadCacheThread extends Thread {
-
- private CancellableHandler handler = null;
- private String geocode;
- private String guid;
-
- public LoadCacheThread(final String geocode, final String guid, final CancellableHandler handlerIn) {
- handler = handlerIn;
-
- if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid)) {
- showToast(res.getString(R.string.err_detail_cache_forgot));
-
- progress.dismiss();
- finish();
- return;
- }
-
- this.geocode = geocode;
- this.guid = guid;
- }
-
- @Override
- public void run() {
- search = Geocache.searchByGeocode(geocode, StringUtils.isBlank(geocode) ? guid : null, 0, false, handler);
- handler.sendMessage(Message.obtain());
- }
- }
-
- /**
* Tries to navigate to the {@link Geocache} of this activity.
*/
private void startDefaultNavigation() {
@@ -2233,33 +2210,14 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
}
- private StoreCacheThread storeThread;
-
- private class StoreCacheThread extends Thread {
- final private int listId;
- final private CancellableHandler handler;
-
- public StoreCacheThread(final int listId, final CancellableHandler handler) {
- this.listId = listId;
- this.handler = handler;
- }
-
- @Override
- public void run() {
- cache.store(listId, handler);
- storeThread = null;
- }
- }
-
protected void storeCache(final int listId, final StoreCacheHandler storeCacheHandler) {
progress.show(this, res.getString(R.string.cache_dialog_offline_save_title), res.getString(R.string.cache_dialog_offline_save_message), true, storeCacheHandler.cancelMessage());
-
- if (storeThread != null) {
- storeThread.interrupt();
- }
-
- storeThread = new StoreCacheThread(listId, storeCacheHandler);
- storeThread.start();
+ Schedulers.io().schedule(new Action1<Inner>() {
+ @Override
+ public void call(final Inner inner) {
+ cache.store(listId, storeCacheHandler);
+ }
+ });
}
private static final class StoreCachePersonalNoteHandler extends StoreCacheHandler {
diff --git a/main/src/cgeo/geocaching/CachePopup.java b/main/src/cgeo/geocaching/CachePopup.java
index 700b81c..543be22 100644
--- a/main/src/cgeo/geocaching/CachePopup.java
+++ b/main/src/cgeo/geocaching/CachePopup.java
@@ -11,6 +11,7 @@ import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.Log;
import org.apache.commons.lang3.StringUtils;
+import rx.Scheduler.Inner;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
@@ -125,23 +126,13 @@ public class CachePopup extends AbstractPopupActivity {
protected void storeCache(final int listId) {
final StoreCacheHandler storeCacheHandler = new StoreCacheHandler(R.string.cache_dialog_offline_save_message);
progress.show(CachePopup.this, res.getString(R.string.cache_dialog_offline_save_title), res.getString(R.string.cache_dialog_offline_save_message), true, storeCacheHandler.cancelMessage());
- new StoreCacheThread(listId, storeCacheHandler).start();
- }
- }
-
- private class StoreCacheThread extends Thread {
- final private int listId;
- final private CancellableHandler handler;
-
- public StoreCacheThread(final int listId, final CancellableHandler handler) {
- this.listId = listId;
- this.handler = handler;
- }
-
- @Override
- public void run() {
- cache.store(listId, handler);
- invalidateOptionsMenuCompatible();
+ Schedulers.io().schedule(new Action1<Inner>() {
+ @Override
+ public void call(final Inner inner) {
+ cache.store(listId, storeCacheHandler);
+ invalidateOptionsMenuCompatible();
+ }
+ });
}
}