Refactor the storage fine permission request code

This commit is contained in:
Nicolas Pomepuy 2024-10-15 08:59:46 +02:00 committed by Duncan McNamara
parent 7d9760aab6
commit dbab387fcf
4 changed files with 8 additions and 5 deletions

View File

@ -169,7 +169,7 @@ class MainActivity : ContentActivity(),
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 1000) {
if (requestCode == Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
forceRefresh()
}

View File

@ -104,7 +104,7 @@ class OnboardingActivity : AppCompatActivity(), OnboardingFragmentListener {
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 1000) {
if (requestCode == Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
viewModel.permissionAlreadyAsked = true
onNext()
@ -124,7 +124,7 @@ class OnboardingActivity : AppCompatActivity(), OnboardingFragmentListener {
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO
), 1000
), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
)
return@launch
} else getStoragePermission(withDialog = false, onlyMedia = false)

View File

@ -51,6 +51,7 @@ import org.videolan.vlc.gui.SecondaryActivity
import org.videolan.vlc.gui.helpers.getBitmapFromDrawable
import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.askStoragePermission
import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getStoragePermission
import org.videolan.vlc.util.Permissions
class EmptyLoadingStateView : FrameLayout {
@ -158,14 +159,14 @@ class EmptyLoadingStateView : FrameLayout {
EmptyLoadingState.MISSING_AUDIO_PERMISSION -> ActivityCompat.requestPermissions(
context as Activity, arrayOf(
Manifest.permission.READ_MEDIA_AUDIO
), 1000
), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
)
EmptyLoadingState.MISSING_VIDEO_PERMISSION -> ActivityCompat.requestPermissions(
context as Activity, arrayOf(
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.READ_MEDIA_IMAGES
), 1000
), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
)
else -> (context as? FragmentActivity)?.askStoragePermission(false, null)

View File

@ -64,6 +64,8 @@ object Permissions {
const val PERMISSION_WRITE_STORAGE_TAG = 253
const val MANAGE_EXTERNAL_STORAGE = 256
const val FINE_STORAGE_PERMISSION_REQUEST_CODE = 100001
const val PERMISSION_SYSTEM_RINGTONE = 42
private const val PERMISSION_SYSTEM_BRIGHTNESS = 43