diff options
| -rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 15 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/CacheListActivity.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/CachePopup.java | 15 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 24 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/connector/gc/GCParserTest.java | 5 |
5 files changed, 21 insertions, 40 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() { diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java index 1509563..e6fed94 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java @@ -21,7 +21,6 @@ import cgeo.test.Compare; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import android.os.Handler; import android.test.suitebuilder.annotation.MediumTest; import java.util.ArrayList; @@ -157,7 +156,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { cache.setGeocode("GC2ZN4G"); // upload coordinates GCParser.editModifiedCoordinates(cache, new Geopoint("N51 21.544", "E07 02.566")); - cache.drop(new Handler()); + cache.dropSynchronous(); final String page = GCParser.requestHtmlPage(cache.getGeocode(), null, "n", "0"); final Geocache cache2 = GCParser.parseCacheFromText(page, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY); assertNotNull(cache2); @@ -166,7 +165,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { assertEquals(new Geopoint("N51 21.544", "E07 02.566"), cache2.getCoords()); // delete coordinates GCParser.deleteModifiedCoordinates(cache2); - cache2.drop(new Handler()); + cache2.dropSynchronous(); final String page2 = GCParser.requestHtmlPage(cache.getGeocode(), null, "n", "0"); final Geocache cache3 = GCParser.parseCacheFromText(page2, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY); assertNotNull(cache3); |
