diff --git a/app/src/main/java/sushi/hardcore/droidfs/add_volume/SelectPathFragment.kt b/app/src/main/java/sushi/hardcore/droidfs/add_volume/SelectPathFragment.kt index 3927f2f..0307419 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/add_volume/SelectPathFragment.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/add_volume/SelectPathFragment.kt @@ -80,16 +80,6 @@ class SelectPathFragment: Fragment() { return binding.root } - private fun requestManageAllFiles(): Boolean { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - if (!Environment.isExternalStorageManager()) { - startActivity(Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:"+requireContext().packageName))) - return true - } - } - return false - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { sharedPrefs = PreferenceManager.getDefaultSharedPreferences(requireContext()) originalRememberVolume = sharedPrefs.getBoolean(ConstValues.REMEMBER_VOLUME_KEY, true) @@ -111,29 +101,33 @@ class SelectPathFragment: Fragment() { refreshStatus(binding.editVolumeName.text) } binding.buttonPickDirectory.setOnClickListener { - if (!requestManageAllFiles()) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if ( - ContextCompat.checkSelfPermission( - requireContext(), - Manifest.permission.READ_EXTERNAL_STORAGE - ) + ContextCompat.checkSelfPermission( - requireContext(), - Manifest.permission.WRITE_EXTERNAL_STORAGE - ) == PackageManager.PERMISSION_GRANTED - ) { - launchPickDirectory() - } else { - askStoragePermissions.launch( - arrayOf( - Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE - ) - ) - } - } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (Environment.isExternalStorageManager()) { launchPickDirectory() + } else { + startActivity(Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:"+requireContext().packageName))) } + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if ( + ContextCompat.checkSelfPermission( + requireContext(), + Manifest.permission.READ_EXTERNAL_STORAGE + ) + ContextCompat.checkSelfPermission( + requireContext(), + Manifest.permission.WRITE_EXTERNAL_STORAGE + ) == PackageManager.PERMISSION_GRANTED + ) { + launchPickDirectory() + } else { + askStoragePermissions.launch( + arrayOf( + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE + ) + ) + } + } else { + launchPickDirectory() } } binding.editVolumeName.addTextChangedListener(object: TextWatcher {