Skip to content

Commit

Permalink
Merge pull request #8 from xmartlabs/camera-permission
Browse files Browse the repository at this point in the history
Ask for camera permission
  • Loading branch information
VictorAlbertos committed May 18, 2016
2 parents 808e5e1 + ce3dde8 commit df0c6b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,20 @@ public final class GrantPermissions extends UseCase<Void> {
}

@Override public Observable<Void> react() {
return requestPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
}

private Observable<Void> requestPermissions(String... permissionsString) {
RxPermissions permissions = RxPermissions.getInstance(targetUi.activity());
return permissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
return permissions.request(permissionsString)
.flatMap(granted -> {
if (granted) return Observable.<Void>just(null);
throw new PermissionDeniedException();
});
}

public Observable<Void> reactAlsoWithCameraPermission() {
return requestPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.CAMERA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class Camera extends Worker {
}

public <T> Observable<Response<T, String>> takePhoto() {
return grantPermissions.react()
return grantPermissions.reactAlsoWithCameraPermission()
.flatMap(granted -> takePhoto.react())
.flatMap(uri -> cropImage.with(uri).react())
.flatMap(uri -> saveImage.with(uri).react())
Expand Down

0 comments on commit df0c6b1

Please sign in to comment.