diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2014-05-12 17:53:01 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2014-05-13 07:33:03 +0200 |
| commit | 37774fbe5fbe6a0900207309747c6b01fcfa2753 (patch) | |
| tree | f447603ddf9dbbd9ff8c4200094172264fd8eb5f /main/src | |
| parent | 29d6e9e4bb286f4bbe4ba5166ad8886d241e5f4f (diff) | |
| download | cgeo-37774fbe5fbe6a0900207309747c6b01fcfa2753.zip cgeo-37774fbe5fbe6a0900207309747c6b01fcfa2753.tar.gz cgeo-37774fbe5fbe6a0900207309747c6b01fcfa2753.tar.bz2 | |
Upgrade to RxJava 0.18.3 and use the new Scheduler interface
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 11 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/CachePopup.java | 6 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 13 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 7 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/network/HtmlImage.java | 26 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/network/StatusUpdater.java | 7 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/sensors/GeoDataProvider.java | 14 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CompassView.java | 7 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/utils/RxUtils.java | 8 |
9 files changed, 41 insertions, 58 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 6f15bcb..11fe672 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -56,13 +56,12 @@ import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; 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.android.observables.AndroidObservable; +import rx.functions.Action0; import rx.functions.Action1; import rx.schedulers.Schedulers; import rx.subscriptions.CompositeSubscription; @@ -300,9 +299,9 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc final String realGeocode = geocode; final String realGuid = guid; - Schedulers.io().schedule(new Action1<Inner>() { + Schedulers.io().createWorker().schedule(new Action0() { @Override - public void call(final Inner inner) { + public void call() { search = Geocache.searchByGeocode(realGeocode, StringUtils.isBlank(realGeocode) ? realGuid : null, 0, false, loadCacheHandler); loadCacheHandler.sendMessage(Message.obtain()); } @@ -2227,9 +2226,9 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc 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()); - Schedulers.io().schedule(new Action1<Inner>() { + Schedulers.io().createWorker().schedule(new Action0() { @Override - public void call(final Inner inner) { + public void call() { cache.store(listId, storeCacheHandler); } }); diff --git a/main/src/cgeo/geocaching/CachePopup.java b/main/src/cgeo/geocaching/CachePopup.java index 543be22..f91d275 100644 --- a/main/src/cgeo/geocaching/CachePopup.java +++ b/main/src/cgeo/geocaching/CachePopup.java @@ -11,7 +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.Action0; import rx.functions.Action1; import rx.schedulers.Schedulers; @@ -126,9 +126,9 @@ 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()); - Schedulers.io().schedule(new Action1<Inner>() { + Schedulers.io().createWorker().schedule(new Action0() { @Override - public void call(final Inner inner) { + public void call() { cache.store(listId, storeCacheHandler); invalidateOptionsMenuCompatible(); } diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 19c15fd..8836115 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -35,7 +35,6 @@ import cgeo.geocaching.utils.MatcherWrapper; import cgeo.geocaching.utils.UncertainProperty; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.Predicate; @@ -44,11 +43,9 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; - import rx.Scheduler; -import rx.Scheduler.Inner; import rx.Subscription; -import rx.functions.Action1; +import rx.functions.Action0; import android.app.Activity; import android.content.Intent; @@ -1438,9 +1435,9 @@ public class Geocache implements ICache, IWaypoint { } public Subscription drop(final Handler handler, final Scheduler scheduler) { - return scheduler.schedule(new Action1<Inner>() { + return scheduler.createWorker().schedule(new Action0() { @Override - public void call(final Inner inner) { + public void call() { try { dropSynchronous(); handler.sendMessage(Message.obtain()); @@ -1499,9 +1496,9 @@ public class Geocache implements ICache, IWaypoint { } public Subscription refresh(final int newListId, final CancellableHandler handler, final Scheduler scheduler) { - return scheduler.schedule(new Action1<Inner>() { + return scheduler.createWorker().schedule(new Action0() { @Override - public void call(final Inner inner) { + public void call() { refreshSynchronous(newListId, handler); handler.sendEmptyMessage(CancellableHandler.DONE); } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 723cc12..b5d0b0e 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -43,9 +43,8 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.eclipse.jdt.annotation.NonNull; - -import rx.Scheduler; import rx.Subscription; +import rx.functions.Action0; import rx.functions.Action1; import rx.schedulers.Schedulers; import rx.subscriptions.CompositeSubscription; @@ -1007,9 +1006,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto * loading timer Triggers every 250ms and checks for viewport change and starts a {@link LoadRunnable}. */ private Subscription startLoadTimer() { - return Schedulers.newThread().schedulePeriodically(new Action1<Scheduler.Inner>() { + return Schedulers.newThread().createWorker().schedulePeriodically(new Action0() { @Override - public void call(Scheduler.Inner inner) { + public void call() { try { if (mapView != null) { // get current viewport diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java index 9c55fe9..167559d 100644 --- a/main/src/cgeo/geocaching/network/HtmlImage.java +++ b/main/src/cgeo/geocaching/network/HtmlImage.java @@ -13,21 +13,20 @@ import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.RxUtils; import ch.boye.httpclientandroidlib.HttpResponse; + import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; + import rx.Observable; import rx.Observable.OnSubscribe; -import rx.Scheduler; -import rx.Scheduler.Inner; import rx.Subscriber; -import rx.functions.Action1; +import rx.functions.Action0; import rx.functions.Func0; import rx.functions.Func1; -import rx.schedulers.Schedulers; import rx.subjects.PublishSubject; import rx.subscriptions.CompositeSubscription; @@ -44,6 +43,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Date; +import java.util.concurrent.Executor; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -94,8 +94,7 @@ public class HtmlImage implements Html.ImageGetter { final private PublishSubject<Observable<String>> loading = PublishSubject.create(); final Observable<String> waitForEnd = Observable.merge(loading).publish().refCount(); final CompositeSubscription subscription = new CompositeSubscription(waitForEnd.subscribe()); - final private Scheduler downloadScheduler = Schedulers.executor(new ThreadPoolExecutor(10, 10, 5, TimeUnit.SECONDS, - new LinkedBlockingQueue<Runnable>())); + final private Executor downloadExecutor = new ThreadPoolExecutor(10, 10, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); public HtmlImage(final String geocode, final boolean returnErrorImage, final int listId, final boolean onlySave) { this.geocode = geocode; @@ -152,9 +151,9 @@ public class HtmlImage implements Html.ImageGetter { @Override public void call(final Subscriber<? super BitmapDrawable> subscriber) { subscription.add(subscriber); - subscriber.add(RxUtils.computationScheduler.schedule(new Action1<Inner>() { + subscriber.add(RxUtils.computationScheduler.createWorker().schedule(new Action0() { @Override - public void call(final Inner inner) { + public void call() { final Pair<BitmapDrawable, Boolean> loaded = loadFromDisk(); final BitmapDrawable bitmap = loaded.getLeft(); if (loaded.getRight()) { @@ -165,12 +164,11 @@ public class HtmlImage implements Html.ImageGetter { if (bitmap != null && !onlySave) { subscriber.onNext(bitmap); } - subscriber.add(downloadScheduler.schedule(new Action1<Inner>() { - @Override - public void call(final Inner inner) { + downloadExecutor.execute(new Runnable() { + @Override public void run() { downloadAndSave(subscriber); } - })); + }); } })); } @@ -205,9 +203,9 @@ public class HtmlImage implements Html.ImageGetter { if (onlySave) { subscriber.onCompleted(); } else { - RxUtils.computationScheduler.schedule(new Action1<Inner>() { + RxUtils.computationScheduler.createWorker().schedule(new Action0() { @Override - public void call(final Inner inner) { + public void call() { final Pair<BitmapDrawable, Boolean> loaded = loadFromDisk(); final BitmapDrawable image = loaded.getLeft(); if (image != null) { diff --git a/main/src/cgeo/geocaching/network/StatusUpdater.java b/main/src/cgeo/geocaching/network/StatusUpdater.java index 4055f01..bf9ebdf 100644 --- a/main/src/cgeo/geocaching/network/StatusUpdater.java +++ b/main/src/cgeo/geocaching/network/StatusUpdater.java @@ -5,10 +5,9 @@ import cgeo.geocaching.utils.Version; import org.json.JSONException; import org.json.JSONObject; -import rx.Scheduler; +import rx.functions.Action0; import rx.schedulers.Schedulers; import rx.subjects.BehaviorSubject; -import rx.functions.Action1; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; @@ -52,9 +51,9 @@ public class StatusUpdater { final static public BehaviorSubject<Status> latestStatus = BehaviorSubject.create(Status.defaultStatus(null)); static { - Schedulers.io().schedulePeriodically(new Action1<Scheduler.Inner>() { + Schedulers.io().createWorker().schedulePeriodically(new Action0() { @Override - public void call(final Scheduler.Inner inner) { + public void call() { final JSONObject response = Network.requestJSON("http://status.cgeo.org/api/status.json", new Parameters("version_code", String.valueOf(Version.getVersionCode(CgeoApplication.getInstance())), diff --git a/main/src/cgeo/geocaching/sensors/GeoDataProvider.java b/main/src/cgeo/geocaching/sensors/GeoDataProvider.java index a77b477..a68f2a6 100644 --- a/main/src/cgeo/geocaching/sensors/GeoDataProvider.java +++ b/main/src/cgeo/geocaching/sensors/GeoDataProvider.java @@ -1,18 +1,15 @@ package cgeo.geocaching.sensors; -import android.os.*; import cgeo.geocaching.utils.Log; - import cgeo.geocaching.utils.StartableHandlerThread; + import org.apache.commons.lang3.StringUtils; import rx.Observable; import rx.Observable.OnSubscribe; -import rx.Scheduler.Inner; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; -import rx.functions.Action1; import rx.observables.ConnectableObservable; import rx.subjects.BehaviorSubject; import rx.subscriptions.CompositeSubscription; @@ -24,6 +21,7 @@ import android.location.GpsStatus; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; +import android.os.Bundle; import java.util.concurrent.TimeUnit; @@ -98,9 +96,9 @@ public class GeoDataProvider implements OnSubscribe<IGeoData> { @Override public Subscription connect() { final CompositeSubscription subscription = new CompositeSubscription(); - AndroidSchedulers.handlerThread(handlerThread.getHandler()).schedule(new Action1<Inner>() { + AndroidSchedulers.handlerThread(handlerThread.getHandler()).createWorker().schedule(new Action0() { @Override - public void call(final Inner inner) { + public void call() { synchronized(lock) { if (count++ == 0) { Log.d("GeoDataProvider: starting the GPS and network listeners" + " (" + ++debugSessionCounter + ")"); @@ -118,9 +116,9 @@ public class GeoDataProvider implements OnSubscribe<IGeoData> { subscription.add(Subscriptions.create(new Action0() { @Override public void call() { - AndroidSchedulers.handlerThread(handlerThread.getHandler()).schedule(new Action1<Inner>() { + AndroidSchedulers.handlerThread(handlerThread.getHandler()).createWorker().schedule(new Action0() { @Override - public void call(final Inner inner) { + public void call() { synchronized (lock) { if (--count == 0) { Log.d("GeoDataProvider: stopping the GPS and network listeners" + " (" + debugSessionCounter + ")"); diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java index f7111f7..915303b 100644 --- a/main/src/cgeo/geocaching/ui/CompassView.java +++ b/main/src/cgeo/geocaching/ui/CompassView.java @@ -3,10 +3,9 @@ package cgeo.geocaching.ui; import cgeo.geocaching.R; import cgeo.geocaching.utils.AngleUtils; -import rx.Scheduler; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; -import rx.functions.Action1; +import rx.functions.Action0; import android.content.Context; import android.content.res.Resources; @@ -88,9 +87,9 @@ public class CompassView extends View { initialDisplay = true; - periodicUpdate = AndroidSchedulers.mainThread().schedulePeriodically(new Action1<Scheduler.Inner>() { + periodicUpdate = AndroidSchedulers.mainThread().createWorker().schedulePeriodically(new Action0() { @Override - public void call(final Scheduler.Inner inner) { + public void call() { final float newAzimuthShown = smoothUpdate(northMeasured, azimuthShown); final float newCacheHeadingShown = smoothUpdate(cacheHeadingMeasured, cacheHeadingShown); if (Math.abs(AngleUtils.difference(azimuthShown, newAzimuthShown)) >= 2 || diff --git a/main/src/cgeo/geocaching/utils/RxUtils.java b/main/src/cgeo/geocaching/utils/RxUtils.java index 8e7864c..deba573 100644 --- a/main/src/cgeo/geocaching/utils/RxUtils.java +++ b/main/src/cgeo/geocaching/utils/RxUtils.java @@ -3,16 +3,10 @@ package cgeo.geocaching.utils; import rx.Scheduler; import rx.schedulers.Schedulers; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - public class RxUtils { // Utility class, not to be instanciated private RxUtils() {} - final static private int cores = Runtime.getRuntime().availableProcessors(); - public final static Scheduler computationScheduler = Schedulers.executor(new ThreadPoolExecutor(1, cores, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>())); - + public final static Scheduler computationScheduler = Schedulers.computation(); } |
