changeset 37:0dbd924cb5e8

Explain why permission needed, per guidelines.
author David Barts <n5jrn@me.com>
date Tue, 23 Mar 2021 22:30:34 -0700
parents 70f1d11d53ad
children 444fe4416c9b
files app/src/main/java/com/bartsent/simpleresizer/EditImage.kt app/src/main/res/values/strings.xml
diffstat 2 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/app/src/main/java/com/bartsent/simpleresizer/EditImage.kt	Fri Mar 19 12:49:13 2021 -0700
+++ b/app/src/main/java/com/bartsent/simpleresizer/EditImage.kt	Tue Mar 23 22:30:34 2021 -0700
@@ -325,12 +325,26 @@
         }
     }
 
+    fun requestWritePermission(): Unit {
+        requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_WRITE_EXTERNAL)
+    }
+
     fun doneClicked(view: View?): Unit {
-        // If we need a permission, request it and bail. We will be called again
+        // If we need WRITE_EXTERNAL_STORAGE, request it and bail. We will be called again
         // (with the permission) if it is granted.
         if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.Q) {
             if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
-                requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_WRITE_EXTERNAL)
+                if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE))
+                    AlertDialog.Builder(this).also {
+                        it.setMessage(getString(R.string.permission_needed, getString(R.string.app_name)))
+                        it.setNeutralButton(R.string.ok_text) { dialog, _ ->
+                            dialog.dismiss()
+                            requestWritePermission()
+                        }
+                        it.create()
+                    }.show()
+                else
+                    requestWritePermission()
                 return
             }
         }
--- a/app/src/main/res/values/strings.xml	Fri Mar 19 12:49:13 2021 -0700
+++ b/app/src/main/res/values/strings.xml	Tue Mar 23 22:30:34 2021 -0700
@@ -1,5 +1,8 @@
 <resources>
+    <!-- Our Name -->
     <string name="app_name">Simple Resizer</string>
+
+    <!-- Editing -->
     <string name="bad_scale">Invalid maximum dimension.</string>
     <string name="cancel_text">Cancel</string>
     <string name="custom_scale_hint">max. dimension</string>
@@ -16,6 +19,7 @@
     <string name="error_unexpected">Unexpected %s.</string>
     <string name="image_size_text">%d ✕ %d</string>
     <string name="ok_text">OK</string>
+    <string name="permission_needed">%s needs the WRITE_EXTERNAL_STORAGE permission to save the resized image. Please approve granting this permission in the next dialog.</string>
     <string name="r_180">180˚</string>
     <string name="r_90_ccw">90˚ CCW</string>
     <string name="r_90_cw">90˚ CW</string>