From 4936eecb1730ca691a812816dc22eb644ff2e57b Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 May 2022 15:15:43 +0200 Subject: [PATCH] require the All Files access in foss and prepaid app variants --- app/build.gradle | 2 +- app/src/foss/res/values/bools.xml | 1 + .../gallery/pro/extensions/Activity.kt | 27 ++++++++++++++++++- app/src/main/res/values/bools.xml | 4 +++ app/src/prepaid/res/values/bools.xml | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/values/bools.xml diff --git a/app/build.gradle b/app/build.gradle index 80e5df4e9..d42adadd7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,7 +78,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:06110ebf15' + implementation 'com.github.SimpleMobileTools:Simple-Commons:a2b7c9c278' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24' diff --git a/app/src/foss/res/values/bools.xml b/app/src/foss/res/values/bools.xml index e966e6564..6c8ad83c3 100644 --- a/app/src/foss/res/values/bools.xml +++ b/app/src/foss/res/values/bools.xml @@ -1,4 +1,5 @@ true + true diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index 4c34b733d..2bc1cfa9d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -12,9 +12,11 @@ import android.graphics.drawable.Drawable import android.graphics.drawable.LayerDrawable import android.net.Uri import android.os.Build +import android.os.Environment import android.provider.MediaStore import android.provider.MediaStore.Files import android.provider.MediaStore.Images +import android.provider.Settings import android.util.DisplayMetrics import android.view.View import androidx.appcompat.app.AppCompatActivity @@ -24,6 +26,7 @@ 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.extensions.* import com.simplemobiletools.commons.helpers.* @@ -127,7 +130,29 @@ fun SimpleActivity.launchAbout() { } fun BaseSimpleActivity.handleMediaManagementPrompt(callback: () -> Unit) { - if (isSPlus() && !MediaStore.canManageMedia(this) && !isExternalStorageManager()) { + if (isRPlus() && resources.getBoolean(R.bool.require_all_files_access)) { + if (Environment.isExternalStorageManager()) { + callback() + } else { + ConfirmationAdvancedDialog(this, "", R.string.access_storage_prompt, R.string.ok, 0) { success -> + if (success) { + try { + val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) + intent.addCategory("android.intent.category.DEFAULT") + intent.data = Uri.parse("package:$packageName") + startActivity(intent) + } catch (e: Exception) { + showErrorToast(e) + val intent = Intent() + intent.action = Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION + startActivity(intent) + } + } else { + finish() + } + } + } + } else if (isSPlus() && !MediaStore.canManageMedia(this) && !isExternalStorageManager()) { ConfirmationDialog(this, "", R.string.media_management_prompt, R.string.ok, 0) { launchMediaManagementIntent(callback) } diff --git a/app/src/main/res/values/bools.xml b/app/src/main/res/values/bools.xml new file mode 100644 index 000000000..a1efad2e7 --- /dev/null +++ b/app/src/main/res/values/bools.xml @@ -0,0 +1,4 @@ + + + false + diff --git a/app/src/prepaid/res/values/bools.xml b/app/src/prepaid/res/values/bools.xml index d78678c11..680bc6430 100644 --- a/app/src/prepaid/res/values/bools.xml +++ b/app/src/prepaid/res/values/bools.xml @@ -3,4 +3,5 @@ false true true + true