42
42
import fr .free .nrw .commons .wikidata .WikidataEditListener ;
43
43
import io .reactivex .Observable ;
44
44
import io .reactivex .android .schedulers .AndroidSchedulers ;
45
- import io .reactivex .disposables .Disposable ;
46
45
import io .reactivex .schedulers .Schedulers ;
47
46
import timber .log .Timber ;
48
47
@@ -85,8 +84,6 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
85
84
private BottomSheetBehavior bottomSheetBehaviorForDetails ; // Behavior for details bottom sheet
86
85
87
86
private LatLng curLatLng ;
88
- private Disposable placesDisposable ;
89
- private Disposable placesDisposableCustom ;
90
87
private boolean lockNearbyView ; //Determines if the nearby places needs to be refreshed
91
88
public View view ;
92
89
private Snackbar snackbar ;
@@ -298,7 +295,7 @@ public void refreshView(LocationServiceManager.LocationChangeType locationChange
298
295
bundle .clear ();
299
296
bundle .putString ("CurLatLng" , gsonCurLatLng );
300
297
301
- placesDisposable = Observable .fromCallable (() -> nearbyController
298
+ compositeDisposable . add ( Observable .fromCallable (() -> nearbyController
302
299
.loadAttractionsFromLocation (curLatLng , curLatLng , false , true ))
303
300
.subscribeOn (Schedulers .io ())
304
301
.observeOn (AndroidSchedulers .mainThread ())
@@ -307,7 +304,7 @@ public void refreshView(LocationServiceManager.LocationChangeType locationChange
307
304
Timber .d (throwable );
308
305
showErrorMessage (getString (R .string .error_fetching_nearby_places ));
309
306
progressBar .setVisibility (View .GONE );
310
- });
307
+ })) ;
311
308
312
309
} else if (locationChangeType
313
310
.equals (LOCATION_SLIGHTLY_CHANGED ) && nearbyMapFragment != null ) {
@@ -335,15 +332,15 @@ public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshFor
335
332
336
333
populateForCurrentLocation = refreshForCurrentLocation ;
337
334
this .customLatLng = customLatLng ;
338
- placesDisposableCustom = Observable .fromCallable (() -> nearbyController
335
+ compositeDisposable . add ( Observable .fromCallable (() -> nearbyController
339
336
.loadAttractionsFromLocation (curLatLng , customLatLng , false , populateForCurrentLocation ))
340
337
.subscribeOn (Schedulers .io ())
341
338
.observeOn (AndroidSchedulers .mainThread ())
342
339
.subscribe (this ::populatePlacesFromCustomLocation ,
343
340
throwable -> {
344
341
Timber .d (throwable );
345
342
showErrorMessage (getString (R .string .error_fetching_nearby_places ));
346
- });
343
+ })) ;
347
344
348
345
if (nearbyMapFragment != null ) {
349
346
nearbyMapFragment .searchThisAreaButton .setVisibility (View .GONE );
@@ -467,7 +464,7 @@ private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate,
467
464
|| curLatLng .getLongitude () < nearbyMapFragment .boundaryCoordinates [2 ].getLongitude ()
468
465
|| curLatLng .getLongitude () > nearbyMapFragment .boundaryCoordinates [3 ].getLongitude ())) {
469
466
// populate places
470
- placesDisposable = Observable .fromCallable (() -> nearbyController
467
+ compositeDisposable . add ( Observable .fromCallable (() -> nearbyController
471
468
.loadAttractionsFromLocation (curLatLng , curLatLng , false , updateViaButton ))
472
469
.subscribeOn (Schedulers .io ())
473
470
.observeOn (AndroidSchedulers .mainThread ())
@@ -476,7 +473,7 @@ private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate,
476
473
Timber .d (throwable );
477
474
showErrorMessage (getString (R .string .error_fetching_nearby_places ));
478
475
progressBar .setVisibility (View .GONE );
479
- });
476
+ })) ;
480
477
nearbyMapFragment .setBundleForUpdates (bundle );
481
478
nearbyMapFragment .updateMapSignificantlyForCurrentLocation ();
482
479
updateListFragment ();
@@ -782,13 +779,7 @@ public void onAttach(Context context) {
782
779
@ Override
783
780
public void onDestroy () {
784
781
super .onDestroy ();
785
- if (placesDisposable != null ) {
786
- placesDisposable .dispose ();
787
- }
788
782
wikidataEditListener .setAuthenticationStateListener (null );
789
- if (placesDisposableCustom != null ) {
790
- placesDisposableCustom .dispose ();
791
- }
792
783
}
793
784
794
785
@ Override
0 commit comments