fix permission request handling for permanently denied permissions

This commit is contained in:
Akinwale Ariwodola 2020-05-27 22:56:07 +01:00
parent c844c4f896
commit a859682954
2 changed files with 21 additions and 14 deletions

View file

@ -2915,11 +2915,17 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public static void requestPermission(String permission, int requestCode, String rationale, Context context, boolean forceRequest) {
if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
if (!forceRequest && ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission)) {
Toast.makeText(context, rationale, Toast.LENGTH_LONG).show();
} else {
if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission)) {
if (context instanceof MainActivity) {
((MainActivity) context).showMessage(rationale);
}
} else if (forceRequest) {
startingPermissionRequest = true;
ActivityCompat.requestPermissions((Activity) context, new String[] { permission }, requestCode);
} else {
if (context instanceof MainActivity) {
((MainActivity) context).showError(rationale);
}
}
}
}

View file

@ -255,8 +255,10 @@ public class PublishFragment extends BaseFragment implements
}
}
if (!storageRefusedOnce) {
checkStoragePermissionAndLoadVideos();
}
}
@SuppressLint("RestrictedApi")
public void onStop() {
@ -394,23 +396,22 @@ public class PublishFragment extends BaseFragment implements
}
if (launchFilePickerPending) {
launchFilePickerPending = false;
launchFilePicker();
launchFilePicker();e
}
}
@Override
public void onStoragePermissionRefused() {
if (!storageRefusedOnce) {
storageRefusedOnce = true;
View root = getView();
if (root != null) {
Snackbar.make(root, R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG).
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
Helper.setViewText(noVideosLoaded, R.string.storage_permission_rationale_videos);
}
checkNoVideosLoaded();
}
storageRefusedOnce = true;
}
}
public String getSuggestedPublishUrl() {
Map<String, Object> params = getParams();