public Observable<String> waitForEndObservable(@Nullable final CancellableHandler handler) { if (handler != null) { handler.unsubscribeIfCancelled(subscription); } loading.onCompleted(); return waitForEnd; }
public void waitForBackgroundLoading(@Nullable final CancellableHandler handler) { if (handler != null) { handler.unsubscribeIfCancelled(subscription); } loading.onCompleted(); waitForEnd.toBlockingObservable().lastOrDefault(null); }
private cgSearch storeParsedCaches(Collection<cgCache> caches) { final cgSearch search = new cgSearch(); final cgeoapplication app = cgeoapplication.getInstance(); int storedCaches = 0; for (cgCache cache : caches) { // remove from cache because a cache might be re-imported app.removeCacheFromCache(cache.getGeocode()); app.addCacheToSearch(search, cache); if (progressHandler.isCancelled()) { throw new CancellationException(); } progressHandler.sendMessage(progressHandler.obtainMessage(0, ++storedCaches, 0)); } return search; }
@Override public void handleMessage(Message msg) { switch (msg.what) { case IMPORT_STEP_READ_FILE: Message cancelMessage = importStepHandler.obtainMessage(IMPORT_STEP_CANCEL); progress.show( (Context) fromActivity, res.getString(R.string.gpx_import_title_reading_file), res.getString(msg.arg1), ProgressDialog.STYLE_HORIZONTAL, cancelMessage); progress.setMaxProgressAndReset(msg.arg2); break; case IMPORT_STEP_READ_WPT_FILE: case IMPORT_STEP_STORE_CACHES: progress.setMessage(res.getString(msg.arg1)); progress.setMaxProgressAndReset(msg.arg2); break; case IMPORT_STEP_FINISHED: progress.dismiss(); fromActivity.helpDialog( res.getString(R.string.gpx_import_title_caches_imported), msg.arg1 + " " + res.getString(R.string.gpx_import_caches_imported)); closeActivity(); break; case IMPORT_STEP_FINISHED_WITH_ERROR: progress.dismiss(); fromActivity.helpDialog( res.getString(R.string.gpx_import_title_caches_import_failed), res.getString(msg.arg1) + "\n\n" + msg.obj); closeActivity(); break; case IMPORT_STEP_CANCEL: progress.dismiss(); progressHandler.cancel(); break; case IMPORT_STEP_CANCELED: fromActivity.showShortToast(res.getString(R.string.gpx_import_canceled)); closeActivity(); break; } }