diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml index 3cedfcf44..217e36158 100644 --- a/application/resources/src/main/res/values/strings.xml +++ b/application/resources/src/main/res/values/strings.xml @@ -663,9 +663,6 @@ VLC media player Allow VLC to access video and audio files VLC needs you to grant this permission to access the media files on this device. - Allow VLC all file access - %s\n\nGrant permission? - To get all the capabilities of VLC and the support of all types of media files, we strongly suggest you to grant this permission. VLC cannot access all of your files Starting with Android 11, applications need a special permission to access all device\'s files.\n\n%s Never ask again diff --git a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt index afbf2da58..e678a1ce2 100644 --- a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt +++ b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt @@ -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)) } diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AllAccessPermissionDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AllAccessPermissionDialog.kt deleted file mode 100644 index 686f2a531..000000000 --- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AllAccessPermissionDialog.kt +++ /dev/null @@ -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(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 - } -} \ No newline at end of file diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt index 7bbf590cc..9f299d177 100644 --- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt +++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt @@ -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 } } diff --git a/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt index 44b1cd13c..0f2452f8d 100644 --- a/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt +++ b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt @@ -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))