rework the permission request flow a bit
This commit is contained in:
parent
387b7d679b
commit
243893f2ad
|
@ -150,8 +150,8 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
}
|
||||
|
||||
// just request the permission, tryLoadGallery will then trigger in onResume
|
||||
handleMediaPermissions {
|
||||
if (!it) {
|
||||
handleMediaPermissions { success ->
|
||||
if (!success) {
|
||||
toast(R.string.no_storage_permissions)
|
||||
finish()
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
|
||||
if (!mWasMediaManagementPromptShown) {
|
||||
mWasMediaManagementPromptShown = true
|
||||
handleMediaManagementPrompt(false) { }
|
||||
handleMediaManagementPrompt { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -479,12 +479,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
private fun tryLoadGallery() {
|
||||
// avoid calling anything right after granting the permission, it will be called from onResume()
|
||||
val wasMissingPermission = config.appRunCount == 1 && !hasPermission(getPermissionToRequest())
|
||||
handleMediaPermissions {
|
||||
if (wasMissingPermission) {
|
||||
return@handleMediaPermissions
|
||||
}
|
||||
handleMediaPermissions { success ->
|
||||
if (success) {
|
||||
if (wasMissingPermission) {
|
||||
return@handleMediaPermissions
|
||||
}
|
||||
|
||||
if (it) {
|
||||
if (!mWasDefaultFolderChecked) {
|
||||
openDefaultFolder()
|
||||
mWasDefaultFolderChecked = true
|
||||
|
|
|
@ -485,7 +485,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
private fun setupKeepLastModified() {
|
||||
settings_keep_last_modified.isChecked = config.keepLastModified
|
||||
settings_keep_last_modified_holder.setOnClickListener {
|
||||
handleMediaManagementPrompt(false) {
|
||||
handleMediaManagementPrompt {
|
||||
settings_keep_last_modified.toggle()
|
||||
config.keepLastModified = settings_keep_last_modified.isChecked
|
||||
}
|
||||
|
|
|
@ -662,7 +662,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
}
|
||||
|
||||
private fun checkMediaManagementAndCopy(isCopyOperation: Boolean) {
|
||||
handleMediaManagementPrompt(true) {
|
||||
handleMediaManagementPrompt {
|
||||
copyMoveTo(isCopyOperation)
|
||||
}
|
||||
}
|
||||
|
@ -1109,7 +1109,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
return
|
||||
}
|
||||
|
||||
handleMediaManagementPrompt(true) {
|
||||
handleMediaManagementPrompt {
|
||||
if (config.isDeletePasswordProtectionOn) {
|
||||
handleDeletePasswordProtection {
|
||||
deleteConfirmed()
|
||||
|
@ -1225,7 +1225,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
}
|
||||
|
||||
private fun checkMediaManagementAndRename() {
|
||||
handleMediaManagementPrompt(true) {
|
||||
handleMediaManagementPrompt {
|
||||
renameFile()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ class MediaAdapter(
|
|||
}
|
||||
|
||||
private fun checkMediaManagementAndRename() {
|
||||
activity.handleMediaManagementPrompt(true) {
|
||||
activity.handleMediaManagementPrompt {
|
||||
renameFile()
|
||||
}
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ class MediaAdapter(
|
|||
}
|
||||
|
||||
private fun checkMediaManagementAndCopy(isCopyOperation: Boolean) {
|
||||
activity.handleMediaManagementPrompt(true) {
|
||||
activity.handleMediaManagementPrompt {
|
||||
copyMoveTo(isCopyOperation)
|
||||
}
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ class MediaAdapter(
|
|||
}
|
||||
|
||||
private fun checkDeleteConfirmation() {
|
||||
activity.handleMediaManagementPrompt(true) {
|
||||
activity.handleMediaManagementPrompt {
|
||||
if (config.isDeletePasswordProtectionOn) {
|
||||
activity.handleDeletePasswordProtection {
|
||||
deleteFiles()
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.simplemobiletools.gallery.pro.dialogs
|
||||
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.gallery.pro.R
|
||||
import kotlinx.android.synthetic.main.dialog_confirm_delete_folder.view.*
|
||||
|
||||
class AllFilesPermissionDialog(
|
||||
val activity: BaseSimpleActivity, message: String = "", val callback: (result: Boolean) -> Unit, val neutralPressed: () -> Unit
|
||||
) {
|
||||
private var dialog: AlertDialog? = null
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_message, null)
|
||||
view.message.text = message
|
||||
|
||||
activity.getAlertDialogBuilder().setPositiveButton(R.string.all_files) { dialog, which -> positivePressed() }
|
||||
.setNeutralButton(R.string.media_only) { dialog, which -> neutralPressed() }
|
||||
.apply {
|
||||
activity.setupDialogStuff(view, this) { alertDialog ->
|
||||
dialog = alertDialog
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun positivePressed() {
|
||||
dialog?.dismiss()
|
||||
callback(true)
|
||||
}
|
||||
}
|
|
@ -26,7 +26,6 @@ import com.bumptech.glide.load.DecodeFormat
|
|||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.SecurityDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
|
@ -37,6 +36,7 @@ import com.simplemobiletools.gallery.pro.BuildConfig
|
|||
import com.simplemobiletools.gallery.pro.R
|
||||
import com.simplemobiletools.gallery.pro.activities.SettingsActivity
|
||||
import com.simplemobiletools.gallery.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.gallery.pro.dialogs.AllFilesPermissionDialog
|
||||
import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog
|
||||
import com.simplemobiletools.gallery.pro.helpers.RECYCLE_BIN
|
||||
import com.simplemobiletools.gallery.pro.models.DateTaken
|
||||
|
@ -127,19 +127,21 @@ fun SimpleActivity.launchAbout() {
|
|||
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
|
||||
}
|
||||
|
||||
fun BaseSimpleActivity.handleMediaManagementPrompt(avoidShowingAllFiles: Boolean, callback: () -> Unit) {
|
||||
fun BaseSimpleActivity.handleMediaManagementPrompt(callback: () -> Unit) {
|
||||
if (canManageMedia() || isExternalStorageManager()) {
|
||||
callback()
|
||||
} else if (isRPlus() && resources.getBoolean(R.bool.require_all_files_access) && !avoidShowingAllFiles) {
|
||||
} else if (isRPlus() && resources.getBoolean(R.bool.require_all_files_access) && !config.avoidShowingAllFilesPrompt) {
|
||||
if (Environment.isExternalStorageManager()) {
|
||||
callback()
|
||||
} else {
|
||||
var messagePrompt = getString(R.string.access_storage_prompt)
|
||||
if (isSPlus()) {
|
||||
messagePrompt += "\n\n${getString(R.string.media_management_alternative)}"
|
||||
messagePrompt += if (isSPlus()) {
|
||||
"\n\n${getString(R.string.media_management_alternative)}"
|
||||
} else {
|
||||
"\n\n${getString(R.string.alternative_media_access)}"
|
||||
}
|
||||
|
||||
ConfirmationAdvancedDialog(this, messagePrompt, 0, R.string.ok, 0, true) { success ->
|
||||
AllFilesPermissionDialog(this, messagePrompt, callback = { success ->
|
||||
if (success) {
|
||||
try {
|
||||
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
|
||||
|
@ -155,15 +157,14 @@ fun BaseSimpleActivity.handleMediaManagementPrompt(avoidShowingAllFiles: Boolean
|
|||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isSPlus() && !MediaStore.canManageMedia(this) && !isExternalStorageManager()) {
|
||||
val message = "${getString(R.string.media_management_prompt)}\n\n${getString(R.string.media_management_note)}"
|
||||
ConfirmationDialog(this, message, 0, R.string.ok, 0) {
|
||||
launchMediaManagementIntent(callback)
|
||||
}, neutralPressed = {
|
||||
if (isSPlus()) {
|
||||
launchMediaManagementIntent(callback)
|
||||
} else {
|
||||
config.avoidShowingAllFilesPrompt = true
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
callback()
|
||||
|
|
|
@ -546,4 +546,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
var customFoldersOrder: String
|
||||
get() = prefs.getString(CUSTOM_FOLDERS_ORDER, "")!!
|
||||
set(customFoldersOrder) = prefs.edit().putString(CUSTOM_FOLDERS_ORDER, customFoldersOrder).apply()
|
||||
|
||||
var avoidShowingAllFilesPrompt: Boolean
|
||||
get() = prefs.getBoolean(AVOID_SHOWING_ALL_FILES_PROMPT, false)
|
||||
set(avoidShowingAllFilesPrompt) = prefs.edit().putBoolean(AVOID_SHOWING_ALL_FILES_PROMPT, avoidShowingAllFilesPrompt).apply()
|
||||
}
|
||||
|
|
|
@ -96,6 +96,7 @@ const val LIMIT_FOLDER_TITLE = "folder_limit_title"
|
|||
const val THUMBNAIL_SPACING = "thumbnail_spacing"
|
||||
const val FILE_ROUNDED_CORNERS = "file_rounded_corners"
|
||||
const val CUSTOM_FOLDERS_ORDER = "custom_folders_order"
|
||||
const val AVOID_SHOWING_ALL_FILES_PROMPT = "avoid_showing_all_files_prompt"
|
||||
|
||||
// slideshow
|
||||
const val SLIDESHOW_INTERVAL = "slideshow_interval"
|
||||
|
|
Loading…
Reference in New Issue