aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-03-11 05:42:48 +0100
committerSamuel Tardieu <sam@rfc1149.net>2014-03-11 05:43:35 +0100
commitc6bbc8c732243b7a88e4d65856b93e21081bcf4f (patch)
tree17397f64c78264c3c841904aefc7c492bbcf7ef8 /main
parent7eb0975a59a88ab9b01c64d2fb2f2a8e21574604 (diff)
downloadcgeo-c6bbc8c732243b7a88e4d65856b93e21081bcf4f.zip
cgeo-c6bbc8c732243b7a88e4d65856b93e21081bcf4f.tar.gz
cgeo-c6bbc8c732243b7a88e4d65856b93e21081bcf4f.tar.bz2
refactoring: factor out code for cache dropping
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java15
-rw-r--r--main/src/cgeo/geocaching/CacheListActivity.java2
-rw-r--r--main/src/cgeo/geocaching/CachePopup.java15
-rw-r--r--main/src/cgeo/geocaching/Geocache.java24
4 files changed, 19 insertions, 37 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index b125e14..80e1f7b 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -1074,20 +1074,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
progress.show(CacheDetailActivity.this, res.getString(R.string.cache_dialog_offline_drop_title), res.getString(R.string.cache_dialog_offline_drop_message), true, null);
- new DropCacheThread(new ChangeNotificationHandler(CacheDetailActivity.this, progress)).start();
- }
- }
-
- private class DropCacheThread extends Thread {
- private Handler handler;
-
- public DropCacheThread(Handler handler) {
- this.handler = handler;
- }
-
- @Override
- public void run() {
- cache.drop(this.handler);
+ cache.drop(new ChangeNotificationHandler(CacheDetailActivity.this, progress), Schedulers.io());
}
}
diff --git a/main/src/cgeo/geocaching/CacheListActivity.java b/main/src/cgeo/geocaching/CacheListActivity.java
index 7e45477..51f98ad 100644
--- a/main/src/cgeo/geocaching/CacheListActivity.java
+++ b/main/src/cgeo/geocaching/CacheListActivity.java
@@ -828,7 +828,7 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA
adapter.notifyDataSetChanged();
refreshCurrentList();
}
- });
+ }, Schedulers.io());
break;
case R.id.menu_move_to_list:
new StoredList.UserInterface(this).promptForListSelection(R.string.cache_menu_move_list, new Action1<Integer>() {
diff --git a/main/src/cgeo/geocaching/CachePopup.java b/main/src/cgeo/geocaching/CachePopup.java
index 38c6e65..700b81c 100644
--- a/main/src/cgeo/geocaching/CachePopup.java
+++ b/main/src/cgeo/geocaching/CachePopup.java
@@ -174,20 +174,7 @@ public class CachePopup extends AbstractPopupActivity {
final DropCacheHandler dropCacheHandler = new DropCacheHandler();
progress.show(CachePopup.this, res.getString(R.string.cache_dialog_offline_drop_title), res.getString(R.string.cache_dialog_offline_drop_message), true, null);
- new DropCacheThread(dropCacheHandler).start();
- }
- }
-
- private class DropCacheThread extends Thread {
- final private Handler handler;
-
- public DropCacheThread(Handler handlerIn) {
- handler = handlerIn;
- }
-
- @Override
- public void run() {
- cache.drop(handler);
+ cache.drop(dropCacheHandler, Schedulers.io());
}
}
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index f3c2ecd..8dde37d 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -1445,15 +1445,23 @@ public class Geocache implements ICache, IWaypoint {
return "cache";
}
- public void drop(Handler handler) {
- try {
- DataStore.markDropped(Collections.singletonList(this));
- DataStore.removeCache(getGeocode(), EnumSet.of(RemoveFlag.REMOVE_CACHE));
+ public Subscription drop(final Handler handler, final Scheduler scheduler) {
+ return scheduler.schedule(new Action1<Inner>() {
+ @Override
+ public void call(final Inner inner) {
+ try {
+ dropSynchronous();
+ handler.sendMessage(Message.obtain());
+ } catch (final Exception e) {
+ Log.e("cache.drop: ", e);
+ }
+ }
+ });
+ }
- handler.sendMessage(Message.obtain());
- } catch (final Exception e) {
- Log.e("cache.drop: ", e);
- }
+ public void dropSynchronous() {
+ DataStore.markDropped(Collections.singletonList(this));
+ DataStore.removeCache(getGeocode(), EnumSet.of(RemoveFlag.REMOVE_CACHE));
}
public void checkFields() {