Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed IllegalArgumentException in LocationServicesOkObservableApi23Factory #573

Merged
merged 4 commits into from
May 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.functions.Cancellable;
import io.reactivex.schedulers.Schedulers;

@TargetApi(Build.VERSION_CODES.KITKAT)
public class LocationServicesOkObservableApi23Factory {
Expand All @@ -30,7 +31,7 @@ public class LocationServicesOkObservableApi23Factory {
public Observable<Boolean> get() {
return Observable.create(new ObservableOnSubscribe<Boolean>() {
@Override
public void subscribe(final ObservableEmitter<Boolean> emitter) throws Exception {
public void subscribe(final ObservableEmitter<Boolean> emitter) {
final boolean initialValue = locationServicesStatus.isLocationProviderOk();
final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
Expand All @@ -43,11 +44,14 @@ public void onReceive(Context context, Intent intent) {
context.registerReceiver(broadcastReceiver, new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
emitter.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
public void cancel() {
context.unregisterReceiver(broadcastReceiver);
}
});
}
}).distinctUntilChanged();
})
.distinctUntilChanged()
.subscribeOn(Schedulers.trampoline())
.unsubscribeOn(Schedulers.trampoline());
}
}