Replace old permission dialog with the new bottom sheet

This commit is contained in:
Nicolas Pomepuy 2024-11-13 09:14:56 +01:00 committed by Duncan McNamara
parent 9e90826844
commit f36aab1863
5 changed files with 4 additions and 130 deletions

View File

@ -663,9 +663,6 @@
<string name="widget_default_text" translatable="false">VLC media player</string>
<string name="allow_storage_access_title">Allow VLC to access video and audio files</string>
<string name="allow_storage_access_description">VLC needs you to grant this permission to access the media files on this device.</string>
<string name="allow_storage_manager_title">Allow VLC all file access</string>
<string name="allow_storage_manager_description">%s\n\nGrant permission?</string>
<string name="allow_storage_manager_explanation">To get all the capabilities of VLC and the support of all types of media files, we strongly suggest you to grant this permission.</string>
<string name="partial_content">VLC cannot access all of your files</string>
<string name="partial_content_description">Starting with Android 11, applications need a special permission to access all device\'s files.\n\n%s</string>
<string name="never_ask_again">Never ask again</string>

View File

@ -62,8 +62,8 @@ import org.videolan.vlc.R
import org.videolan.vlc.StartActivity
import org.videolan.vlc.gui.audio.AudioBrowserFragment
import org.videolan.vlc.gui.browser.BaseBrowserFragment
import org.videolan.vlc.gui.dialogs.AllAccessPermissionDialog
import org.videolan.vlc.gui.dialogs.NotificationPermissionManager
import org.videolan.vlc.gui.dialogs.PermissionListDialog
import org.videolan.vlc.gui.dialogs.UPDATE_DATE
import org.videolan.vlc.gui.dialogs.UPDATE_URL
import org.videolan.vlc.gui.dialogs.UpdateDialog
@ -156,7 +156,7 @@ class MainActivity : ContentActivity(),
//Only the partial permission is granted for Android 11+
if (!settings.getBoolean(PERMISSION_NEVER_ASK, false) && settings.getLong(PERMISSION_NEXT_ASK, 0L) < System.currentTimeMillis() && Permissions.canReadStorage(this) && !Permissions.hasAllAccess(this)) {
UiTools.snackerMessageInfinite(this, getString(R.string.partial_content))?.setAction(R.string.more) {
AllAccessPermissionDialog.newInstance().show(supportFragmentManager, AllAccessPermissionDialog::class.simpleName)
PermissionListDialog.newInstance().show(supportFragmentManager, PermissionListDialog::class.simpleName)
}?.show()
settings.putSingle(PERMISSION_NEXT_ASK, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(2))
}

View File

@ -1,82 +0,0 @@
/**
* **************************************************************************
* AllAccessPermissionDialog.kt
* ****************************************************************************
* Copyright © 2015 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* ***************************************************************************
*/
package org.videolan.vlc.gui.dialogs
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.CheckBox
import android.widget.TextView
import androidx.lifecycle.lifecycleScope
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
import kotlinx.coroutines.launch
import org.videolan.tools.PERMISSION_NEVER_ASK
import org.videolan.tools.Settings
import org.videolan.tools.putSingle
import org.videolan.vlc.R
import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getStoragePermission
class AllAccessPermissionDialog : VLCBottomSheetDialogFragment() {
private lateinit var titleView:TextView
private lateinit var grantAllAccessButton:Button
private lateinit var neverAskAgain:CheckBox
companion object {
/**
* Create a new AllAccessPermissionDialog
*/
fun newInstance(): AllAccessPermissionDialog {
return AllAccessPermissionDialog()
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.dialog_all_access, container)
titleView = view.findViewById(R.id.title)
view.findViewById<TextView>(R.id.description).text = getString(R.string.partial_content_description, getString(R.string.allow_storage_manager_explanation))
grantAllAccessButton = view.findViewById(R.id.grant_all_access_button)
neverAskAgain = view.findViewById(R.id.never_ask_again)
val settings = Settings.getInstance(requireActivity())
grantAllAccessButton.setOnClickListener {
lifecycleScope.launch { requireActivity().getStoragePermission(withDialog = false) }
dismiss()
}
neverAskAgain.setOnCheckedChangeListener { _, isChecked ->
settings.putSingle(PERMISSION_NEVER_ASK, isChecked)
}
return view
}
override fun getDefaultState(): Int {
return STATE_EXPANDED
}
override fun initialFocusedView(): View = titleView
override fun needToManageOrientation(): Boolean {
return true
}
}

View File

@ -47,6 +47,7 @@ import org.videolan.resources.SCHEME_PACKAGE
import org.videolan.resources.util.isExternalStorageManager
import org.videolan.resources.util.startMedialibrary
import org.videolan.tools.*
import org.videolan.vlc.gui.dialogs.PermissionListDialog
import org.videolan.vlc.gui.onboarding.ONBOARDING_DONE_KEY
import org.videolan.vlc.util.FileUtils
import org.videolan.vlc.util.Permissions
@ -134,11 +135,7 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
val uri = Uri.fromParts(SCHEME_PACKAGE, requireContext().packageName, null)
val intent = Intent(android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, uri)
if (intent.isCallable(requireActivity())) {
if (withDialog) Permissions.showExternalPermissionDialog(requireActivity()) { asked ->
if (asked) {
askAllAccessPermission(intent)
}
} else askAllAccessPermission(intent)
PermissionListDialog.newInstance().show(requireActivity().supportFragmentManager, PermissionListDialog::class.simpleName)
return
}
}

View File

@ -244,17 +244,6 @@ object Permissions {
createDialog(activity, exit)
}
/**
* Display a dialog asking for the [Manifest.permission.MANAGE_EXTERNAL_STORAGE] permission if needed
*
* @param activity: the activity used to trigger the dialog
* @param listener: the listener for the permission result
*/
fun showExternalPermissionDialog(activity: FragmentActivity, listener: (boolean: Boolean) -> Unit) {
if (activity.isFinishing || sAlertDialog != null && sAlertDialog!!.isShowing) return
sAlertDialog = createExternalManagerDialog(activity, listener)
}
private fun createDialog(activity: FragmentActivity, exit: Boolean): Dialog {
val dialogBuilder = android.app.AlertDialog.Builder(activity)
.setTitle(activity.getString(R.string.allow_storage_access_title))
@ -272,33 +261,6 @@ object Permissions {
return dialogBuilder.show()
}
/**
* Display a dialog asking for the [Manifest.permission.MANAGE_EXTERNAL_STORAGE] permission
*
* @param activity: the activity used to trigger the dialog
* @param listener: the listener for the permission result
*/
private fun createExternalManagerDialog(activity: FragmentActivity, listener: (boolean: Boolean) -> Unit): Dialog {
val dialogBuilder = android.app.AlertDialog.Builder(activity)
.setTitle(activity.getString(R.string.allow_storage_manager_title))
.setMessage(activity.getString(R.string.allow_storage_manager_description, activity.getString(R.string.allow_storage_manager_explanation)))
.setIcon(R.drawable.ic_warning)
.setPositiveButton(activity.getString(R.string.ok)) { _, _ ->
listener.invoke(true)
}.setNegativeButton(activity.getString(R.string.cancel)) { _, _ ->
activity.finish()
listener.invoke(false)
}
.setCancelable(false)
return dialogBuilder.show().apply {
if (activity is AppCompatActivity) activity.lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onDestroy(owner: LifecycleOwner) {
dismiss()
}
})
}
}
private fun createDialogCompat(activity: FragmentActivity, exit: Boolean): Dialog {
val dialogBuilder = AlertDialog.Builder(activity)
.setTitle(activity.getString(R.string.allow_storage_access_title))