[Android] Add a permission livedata to be observed outside of the permission dialog

Nicolas Pomepuy git at videolan.org
Tue Dec 3 17:57:43 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Dec  3 15:15:47 2024 +0100| [4ffe95489506629ef393c7c199b389349c9f1c0d] | committer: Nicolas Pomepuy

Add a permission livedata to be observed outside of the permission dialog

> https://code.videolan.org/videolan/vlc-android/commit/4ffe95489506629ef393c7c199b389349c9f1c0d
---

 .../org/videolan/vlc/gui/dialogs/PermissionListDialog.kt    | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PermissionListDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PermissionListDialog.kt
index 027ced2f4a..c2f3936ab2 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PermissionListDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PermissionListDialog.kt
@@ -35,6 +35,7 @@ import android.view.ViewGroup
 import android.widget.RadioButton
 import androidx.core.app.ActivityCompat
 import androidx.core.content.ContextCompat
+import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.lifecycleScope
 import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
 import kotlinx.coroutines.launch
@@ -69,6 +70,7 @@ class PermissionListDialog : VLCBottomSheetDialogFragment() {
         }
 
     companion object {
+        val hasAnyPermission = MutableLiveData<Boolean>().apply { value = false }
 
         fun newInstance(): PermissionListDialog {
             return PermissionListDialog()
@@ -85,6 +87,15 @@ class PermissionListDialog : VLCBottomSheetDialogFragment() {
 
     override fun initialFocusedView(): View = binding.permissionTitle
 
+    override fun onCreate(savedInstanceState: Bundle?) {
+        refreshPermissionLiveData()
+        super.onCreate(savedInstanceState)
+    }
+
+    private fun refreshPermissionLiveData() {
+        hasAnyPermission.postValue(Permissions.hasAllAccess(requireActivity()) || Permissions.hasAnyFileFineAccess(requireActivity()))
+    }
+
     override fun onCreateView(
         inflater: LayoutInflater, container: ViewGroup?,
         savedInstanceState: Bundle?
@@ -105,6 +116,8 @@ class PermissionListDialog : VLCBottomSheetDialogFragment() {
 
     private fun updateStorageState() {
 
+        refreshPermissionLiveData()
+
         //Notification
 
         binding.notificationPermissionCheck.setImageDrawable(ContextCompat.getDrawable(requireActivity(), if (Permissions.canSendNotifications(requireActivity())) R.drawable.ic_permission_check_checked else R.drawable.ic_permission_check_unchecked))



More information about the Android mailing list