Fix crash(es) caused by failing to dispose Rx observables (#2669)

This commit is contained in:
Dmitry Brant 2019-03-19 17:08:04 -04:00 committed by Adam Jones
parent 38d39e08ac
commit 8474c04c64
21 changed files with 121 additions and 86 deletions

View file

@ -61,7 +61,6 @@ import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
@ -101,7 +100,6 @@ public class ContributionsFragment
@BindView(R.id.card_view_nearby) public NearbyNotificationCardView nearbyNotificationCardView;
@BindView(R.id.campaigns_view) CampaignView campaignView;
private Disposable placesDisposable;
private LatLng curLatLng;
private boolean firstLocationUpdate = true;
@ -592,7 +590,7 @@ public class ContributionsFragment
private void updateClosestNearbyCardViewInfo() {
curLatLng = locationManager.getLastLocation();
placesDisposable = Observable.fromCallable(() -> nearbyController
compositeDisposable.add(Observable.fromCallable(() -> nearbyController
.loadAttractionsFromLocation(curLatLng, curLatLng, true, false)) // thanks to boolean, it will only return closest result
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -600,7 +598,7 @@ public class ContributionsFragment
throwable -> {
Timber.d(throwable);
updateNearbyNotification(null);
});
}));
}
private void updateNearbyNotification(@Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
@ -635,10 +633,6 @@ public class ContributionsFragment
isUploadServiceConnected = false;
}
}
if (placesDisposable != null) {
placesDisposable.dispose();
}
}
@Override

View file

@ -307,11 +307,11 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
@SuppressLint("CheckResult")
private void setNotificationCount() {
Observable.fromCallable(() -> notificationController.getNotifications(false))
compositeDisposable.add(Observable.fromCallable(() -> notificationController.getNotifications(false))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::initNotificationViews,
throwable -> Timber.e(throwable, "Error occurred while loading notifications"));
throwable -> Timber.e(throwable, "Error occurred while loading notifications")));
}
private void initNotificationViews(List<Notification> notificationList) {