Skip to content

Commit

Permalink
use MainThreadSubscription
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartDengg committed Nov 15, 2015
1 parent 1928687 commit 4fd9d7f
Showing 1 changed file with 5 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.util.SparseArray;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jakewharton.rxbinding.internal.MainThreadSubscription;
import com.joker.rxweather.common.Constants;
import com.joker.rxweather.common.rx.rxAndroid.SchedulersCompat;
import com.joker.rxweather.model.entities.AddressEntity;
Expand All @@ -19,11 +20,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import org.json.JSONObject;
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Func1;
import rx.functions.Func2;

Expand All @@ -33,9 +32,6 @@
public class PrepareCase extends UseCase<SparseArray> {

private static final String TAG = PrepareCase.class.getSimpleName();
private volatile int unsubscribed;
private static final AtomicIntegerFieldUpdater<PrepareCase> unsubscribedUpdater =
AtomicIntegerFieldUpdater.newUpdater(PrepareCase.class, "unsubscribed");

private LocationManager locationManager;
private AssetManager assetManager;
Expand Down Expand Up @@ -80,22 +76,13 @@ public void onLocationChanged(final Location location) {
subscriber.onNext(location);
subscriber.onCompleted();
}
locationManager.removeUpdates(this);
handlerThread.getLooper().quit();
}
};

subscriber.add(new Subscription() {
@Override public void unsubscribe() {
if (unsubscribedUpdater.compareAndSet(PrepareCase.this, 0, 1)) {

locationManager.removeUpdates(locationListener);
handlerThread.getLooper().quit();
}
}

@Override public boolean isUnsubscribed() {
return unsubscribed != 0;
subscriber.add(new MainThreadSubscription() {
@Override protected void onUnsubscribe() {
locationManager.removeUpdates(locationListener);
handlerThread.getLooper().quit();
}
});

Expand Down

0 comments on commit 4fd9d7f

Please sign in to comment.