Last active
May 16, 2018 14:41
-
-
Save talosdev/f8052ba03e3cd82a5503fbd5fa236190 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class LocationPresenter implements LocationContract.Presenter { | |
| private static final String TAG = "LOCATION"; | |
| private final WeakReference<LocationContract.View> viewWeakReference; | |
| private final LocationInteractor interactor; | |
| private final CompositeDisposable disposables = new CompositeDisposable(); | |
| @Inject | |
| public LocationPresenter(LocationContract.View view, LocationInteractor interactor) { | |
| this.viewWeakReference = new WeakReference<>(view); | |
| this.interactor = interactor; | |
| } | |
| @Override | |
| public void getLocation() { | |
| disposables.add( | |
| interactor.getLocation() | |
| .subscribe( | |
| location -> { | |
| LocationContract.View view = viewWeakReference.get(); | |
| if (view != null) { | |
| view.showLatitude(String.valueOf(location.latitude())); | |
| view.showLongitude(String.valueOf(location.longitude())); | |
| } | |
| }, | |
| throwable -> { | |
| LocationContract.View view = viewWeakReference.get(); | |
| if (view != null) { | |
| Log.e(TAG, "Error while getting location", throwable); | |
| if (throwable instanceof NoLocationAvailableException) { | |
| view.showNoLocationAvailable(); | |
| } else { | |
| view.showGenericError(); | |
| } | |
| } | |
| } | |
| ) | |
| ); | |
| } | |
| @Override | |
| public void cleanup() { | |
| disposables.clear(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment