diff app/src/main/java/com/bartsent/simpleresizer/EditImage.kt @ 30:aacf7a856b5f

Bug fixes, incl for getting "stuck" when file chooser backed out of.
author David Barts <n5jrn@me.com>
date Wed, 24 Feb 2021 19:14:50 -0800
parents eec88eba58e9
children be08576794af
line wrap: on
line diff
--- a/app/src/main/java/com/bartsent/simpleresizer/EditImage.kt	Wed Feb 24 18:44:47 2021 -0800
+++ b/app/src/main/java/com/bartsent/simpleresizer/EditImage.kt	Wed Feb 24 19:14:50 2021 -0800
@@ -94,7 +94,6 @@
     override fun onResume() {
         super.onResume()
 
-        Log.d("EditImage", "intent action = ${intent?.action ?: "(none)"}")
         // Read the URI, die if we can't.
         val imageUri = intent?.data ?: intent?.extras?.get(Intent.EXTRA_STREAM) as? Uri
         if (imageUri == null) {
@@ -110,15 +109,15 @@
             State.uri = imageUri
             binding.progressBar.visibility = ProgressBar.VISIBLE
             ThreadPools.WORKERS.execute {
-                State.bitmap = contentResolver.openInputStream(imageUri).use {
+                val newBitmap = contentResolver.openInputStream(imageUri).use {
                     BitmapFactory.decodeStream(it)
                 }
                 runOnUiThread {
                     binding.progressBar.visibility = ProgressBar.INVISIBLE
-                    if (State.bitmap == null)
+                    if (newBitmap == null)
                         showFatalError(getString(R.string.error_bad_image))
                     else
-                        setImage(State.bitmap!!)
+                        setImage(newBitmap)
                 }
             }
             return
@@ -137,6 +136,11 @@
         binding.root.invalidate()
     }
 
+    private fun unsetImage(): Unit {
+        State.uri = null
+        State.bitmap = null
+    }
+
     private val CUSTOM = 999998
     private val CANCEL = 999999
 
@@ -270,9 +274,8 @@
         }
     }
 
-     fun cancelClicked(view: View): Unit {
-        State.uri = null
-        State.bitmap = null
+    fun cancelClicked(view: View): Unit {
+        unsetImage()
         finish()
     }
 
@@ -321,9 +324,10 @@
             }
             runOnUiThread {
                 binding.progressBar.visibility = ProgressBar.INVISIBLE
-                if (errorMessage == null)
+                if (errorMessage == null) {
+                    unsetImage()
                     finish()
-                else
+                } else
                     Toast.makeText(applicationContext, errorMessage, Toast.LENGTH_LONG).show()
             }
         }