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 RuntimePermissionRequestHandler implements PermissionRequestHandler { | |
| private final WeakReference<Activity> activityWeakReference; | |
| private final String permission; | |
| private final int requestCode; | |
| private AsyncSubject<PermissionRequestResult> subject; | |
| public RuntimePermissionRequestHandler(Activity activity, String permission, int requestCode) { | |
| this.activityWeakReference = new WeakReference<>(activity); | |
| this.permission = permission; |
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
| @Override | |
| @SuppressWarnings({"MissingPermission"}) | |
| public void onRequestPermissionsResult(int requestCode, | |
| @NonNull String[] permissions, | |
| @NonNull int[] grantResults) { | |
| if (requestCode == locationRequestCode) { | |
| if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |
| permissionsRequestResultDispatcher.dispatchResult(true); | |
| } else { | |
| permissionsRequestResultDispatcher.dispatchResult(false); |
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
| /** | |
| * Dispatches the result of the permission request from the Activity to the | |
| * {@link RuntimePermissionRequestHandler} | |
| */ | |
| public class PermissionsRequestResultDispatcher { | |
| private RuntimePermissionRequestHandler permissionRequestHandler; | |
| @Inject | |
| public PermissionsRequestResultDispatcher(RuntimePermissionRequestHandler handler) { |
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
| @Override | |
| public Single<PermissionRequestResult> requestPermission() { | |
| subject = AsyncSubject.create(); | |
| if (activityWeakReference.get() != null) { | |
| ActivityCompat.requestPermissions( | |
| activityWeakReference.get(), | |
| new String[] {permission}, | |
| requestCode); | |
| } |
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
| @Override | |
| public boolean checkHasPermission() { | |
| if (activityWeakReference.get() != null) { | |
| Activity activity = activityWeakReference.get(); | |
| return ContextCompat.checkSelfPermission(activity, permission) | |
| == PackageManager.PERMISSION_GRANTED; | |
| } | |
| return false; | |
| } |
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 interface PermissionRequestHandler { | |
| boolean checkHasPermission(); | |
| Single<PermissionRequestResult> requestPermission(); | |
| enum PermissionRequestResult { | |
| GRANTED, | |
| DENIED_SOFT, | |
| DENIED_HARD |
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 LocationActivity extends AppCompatActivity implements LocationContract.View { | |
| private static final int REQ_CODE = 111; | |
| @BindView(R.id.latitudeTextView) | |
| TextView latitudeTextView; | |
| @BindView(R.id.longitudeTextView) | |
| TextView longitudeTextView; | |
| @BindView(R.id.softDenyTextView) | |
| TextView softDeniedWarningTextView; |
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 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
| package talosdev.clean.features.location.presentation; | |
| import android.util.Log; | |
| import java.lang.ref.WeakReference; | |
| import javax.inject.Inject; | |
| import io.reactivex.disposables.CompositeDisposable; | |
| import talosdev.clean.features.location.domain.LocationInteractor; |
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 LocationInteractor { | |
| private final LocationProvider locationProvider; | |
| @Inject | |
| public LocationInteractor(LocationProvider locationProvider) { | |
| this.locationProvider = locationProvider; | |
| } | |
| public Single<Location> getLocation() { |