mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
extract check permissions to private helper method
This commit is contained in:
parent
edda5a7807
commit
5bffb9aaec
1 changed files with 28 additions and 23 deletions
|
@ -69,30 +69,8 @@ public class MediaProvider {
|
||||||
public static List<MediaFolder> getImageFolders(ContentResolver contentResolver, int itemLimit,
|
public static List<MediaFolder> getImageFolders(ContentResolver contentResolver, int itemLimit,
|
||||||
@Nullable final Activity activity) {
|
@Nullable final Activity activity) {
|
||||||
// check permissions
|
// check permissions
|
||||||
if (activity != null &&
|
checkPermissions(activity);
|
||||||
!PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
|
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
||||||
// Check if we should show an explanation
|
|
||||||
if (PermissionUtil.shouldShowRequestPermissionRationale(activity,
|
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
||||||
// Show explanation to the user and then request permission
|
|
||||||
Snackbar snackbar = Snackbar.make(activity.findViewById(R.id.ListLayout),
|
|
||||||
R.string.permission_storage_access, Snackbar.LENGTH_INDEFINITE)
|
|
||||||
.setAction(R.string.common_ok, new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
PermissionUtil.requestWriteExternalStoreagePermission(activity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ThemeUtils.colorSnackbar(activity.getApplicationContext(), snackbar);
|
|
||||||
|
|
||||||
snackbar.show();
|
|
||||||
} else {
|
|
||||||
// No explanation needed, request the permission.
|
|
||||||
PermissionUtil.requestWriteExternalStoreagePermission(activity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// query media/image folders
|
// query media/image folders
|
||||||
Cursor cursorFolders;
|
Cursor cursorFolders;
|
||||||
|
@ -185,6 +163,33 @@ public class MediaProvider {
|
||||||
return mediaFolders;
|
return mediaFolders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void checkPermissions(@Nullable Activity activity) {
|
||||||
|
if (activity != null &&
|
||||||
|
!PermissionUtil.checkSelfPermission(activity.getApplicationContext(),
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
|
// Check if we should show an explanation
|
||||||
|
if (PermissionUtil.shouldShowRequestPermissionRationale(activity,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
|
// Show explanation to the user and then request permission
|
||||||
|
Snackbar snackbar = Snackbar.make(activity.findViewById(R.id.ListLayout),
|
||||||
|
R.string.permission_storage_access, Snackbar.LENGTH_INDEFINITE)
|
||||||
|
.setAction(R.string.common_ok, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
PermissionUtil.requestWriteExternalStoreagePermission(activity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ThemeUtils.colorSnackbar(activity.getApplicationContext(), snackbar);
|
||||||
|
|
||||||
|
snackbar.show();
|
||||||
|
} else {
|
||||||
|
// No explanation needed, request the permission.
|
||||||
|
PermissionUtil.requestWriteExternalStoreagePermission(activity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static List<MediaFolder> getVideoFolders(ContentResolver contentResolver, int itemLimit) {
|
public static List<MediaFolder> getVideoFolders(ContentResolver contentResolver, int itemLimit) {
|
||||||
Cursor cursorFolders = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
Cursor cursorFolders = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
||||||
VIDEOS_FOLDER_PROJECTION, null, null, null);
|
VIDEOS_FOLDER_PROJECTION, null, null, null);
|
||||||
|
|
Loading…
Reference in a new issue