# HG changeset patch # User David Barts # Date 1614222890 28800 # Node ID aacf7a856b5f63394e018db1c0be25d8d39b62e9 # Parent eec88eba58e92557b5dc9bc44e7807d6bfcfd1b7 Bug fixes, incl for getting "stuck" when file chooser backed out of. diff -r eec88eba58e9 -r aacf7a856b5f app/src/main/java/com/bartsent/simpleresizer/EditImage.kt --- 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() } } diff -r eec88eba58e9 -r aacf7a856b5f app/src/main/java/com/bartsent/simpleresizer/MainActivity.kt --- a/app/src/main/java/com/bartsent/simpleresizer/MainActivity.kt Wed Feb 24 18:44:47 2021 -0800 +++ b/app/src/main/java/com/bartsent/simpleresizer/MainActivity.kt Wed Feb 24 19:14:50 2021 -0800 @@ -23,14 +23,17 @@ override fun onResume() { super.onResume() - if (showChooser) { - Intent(Intent.ACTION_GET_CONTENT).run { - type = "image/*" - addCategory(Intent.CATEGORY_OPENABLE) - startActivityForResult(this, GET_IMAGE) - } - } else { + if (showChooser) + doShowChooser() + else showChooser = true + } + + fun doShowChooser(): Unit { + Intent(Intent.ACTION_GET_CONTENT).run { + type = "image/*" + addCategory(Intent.CATEGORY_OPENABLE) + startActivityForResult(this, GET_IMAGE) } } @@ -45,6 +48,7 @@ } } else { Toast.makeText(applicationContext, "Unable to get image!", Toast.LENGTH_LONG).show() + doShowChooser() } } }