[Android] MLBrowser: block local directories when no perm
Duncan McNamara
git at videolan.org
Wed Mar 16 12:42:12 UTC 2022
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Wed Mar 16 12:31:17 2022 +0100| [f8b751527f19f6b24126965f349084a489700b64] | committer: Duncan McNamara
MLBrowser: block local directories when no perm
Enable MLBrowser when there are no storage permissions, so that the user
can select network directories to scan
> https://code.videolan.org/videolan/vlc-android/commit/f8b751527f19f6b24126965f349084a489700b64
---
.../television/ui/preferences/PreferencesFragment.kt | 20 +++++++++++---------
.../vlc/gui/browser/StorageFragmentDelegate.kt | 8 ++++++++
.../vlc/gui/preferences/PreferencesFragment.kt | 18 ++++++++----------
3 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesFragment.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesFragment.kt
index 5ceebc2c3..145cef2e0 100644
--- a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesFragment.kt
@@ -62,15 +62,17 @@ class PreferencesFragment : BasePreferenceFragment() {
val context = activity ?: return false
return when (preference.key) {
"directories" -> {
- when {
- Medialibrary.getInstance().isWorking -> Toast.makeText(context, getString(R.string.settings_ml_block_scan), Toast.LENGTH_SHORT).show()
- Permissions.canReadStorage(context) -> {
- val intent = Intent(context.applicationContext, SecondaryActivity::class.java)
- intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER)
- startActivity(intent)
- activity.setResult(RESULT_RESTART)
- }
- else -> Permissions.showStoragePermissionDialog(context as FragmentActivity, false)
+ if (Medialibrary.getInstance().isWorking) {
+ Toast.makeText(
+ context,
+ getString(R.string.settings_ml_block_scan),
+ Toast.LENGTH_SHORT
+ ).show()
+ } else {
+ val intent = Intent(context.applicationContext, SecondaryActivity::class.java)
+ intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER)
+ startActivity(intent)
+ activity.setResult(RESULT_RESTART)
}
true
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageFragmentDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageFragmentDelegate.kt
index 43b3844a3..b3e5c8f3b 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageFragmentDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageFragmentDelegate.kt
@@ -29,13 +29,16 @@ import android.os.Handler
import android.view.View
import android.widget.CheckBox
import androidx.collection.SimpleArrayMap
+import androidx.fragment.app.FragmentActivity
import org.videolan.medialibrary.interfaces.EntryPointsEventsCb
import org.videolan.medialibrary.interfaces.Medialibrary
+import org.videolan.resources.util.canReadStorage
import org.videolan.tools.*
import org.videolan.vlc.MediaParsingService
import org.videolan.vlc.gui.SecondaryActivity
import org.videolan.vlc.gui.helpers.MedialibraryUtils
import org.videolan.vlc.gui.helpers.ThreeStatesCheckbox
+import org.videolan.vlc.util.Permissions
interface IStorageFragmentDelegate {
fun checkBoxAction(v: View, mrl: String)
@@ -78,6 +81,11 @@ class StorageFragmentDelegate : IStorageFragmentDelegate, EntryPointsEventsCb {
override fun checkBoxAction(v: View, mrl: String) {
val tscb = v as ThreeStatesCheckbox
val checked = tscb.state == ThreeStatesCheckbox.STATE_CHECKED
+ if (checked && mrl.contains("file://") && !canReadStorage(context)) {
+ Permissions.showStoragePermissionDialog(context as FragmentActivity, false)
+ tscb.state = ThreeStatesCheckbox.STATE_UNCHECKED
+ return
+ }
if ((context as? SecondaryActivity)?.isOnboarding == true) {
val path = mrl.sanitizePath()
if (checked) {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt
index 596d40867..f5c84ace3 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt
@@ -98,16 +98,14 @@ class PreferencesFragment : BasePreferenceFragment(), SharedPreferences.OnShared
override fun onPreferenceTreeClick(preference: Preference): Boolean {
when (preference.key) {
"directories" -> {
- when {
- Medialibrary.getInstance().isWorking -> UiTools.snacker(requireActivity(), getString(R.string.settings_ml_block_scan))
- Permissions.canReadStorage(requireContext()) -> {
- val activity = requireActivity()
- val intent = Intent(activity.applicationContext, SecondaryActivity::class.java)
- intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER)
- startActivity(intent)
- activity.setResult(RESULT_RESTART)
- }
- else -> Permissions.showStoragePermissionDialog(requireActivity(), false)
+ if (Medialibrary.getInstance().isWorking) {
+ UiTools.snacker(requireActivity(), getString(R.string.settings_ml_block_scan))
+ } else {
+ val activity = requireActivity()
+ val intent = Intent(activity.applicationContext, SecondaryActivity::class.java)
+ intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER)
+ startActivity(intent)
+ activity.setResult(RESULT_RESTART)
}
return true
}
More information about the Android
mailing list