To be placed in a main parent Activity, or as part of some custom BaseActivity class for handling permission request and responses without losing the "flow".
Example usage:
btn_load_timeline?.setOnClickListener {
permissionCheck(Manifest.permission.READ_EXTERNAL_STORAGE, PermissionRequestCode.TIMELINE_FEATURE_EXTERNAL_STORAGE) { permissionResponse ->
when (permissionResponse) {
PermissionResponse.PERMISSION_GRANTED -> {
Log.d(TAG, "Permission granted, load timeline here")
// Do stuff with granted permission
}
PermissionResponse.PERMISSION_DENIED -> {
Log.d(TAG, "Permission Denied, but can still prompt again")
// Can prompt for permission again, or show rationale, etc.
}
PermissionResponse.PERMISSION_DONT_SHOW_AGAIN -> {
Log.d(TAG, "Permission Denied, and user selected 'Don't Show Again'")
// Disable feature, and/or let user know they'll need to go to Settings > App Info to enable the permission
}
}
}
}