comparison app/src/main/java/com/bartsent/simpleresizer/MainActivity.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 20da616dcda0
children 0023e6013dd9
comparison
equal deleted inserted replaced
29:eec88eba58e9 30:aacf7a856b5f
21 setContentView(binding.root) 21 setContentView(binding.root)
22 } 22 }
23 23
24 override fun onResume() { 24 override fun onResume() {
25 super.onResume() 25 super.onResume()
26 if (showChooser) { 26 if (showChooser)
27 Intent(Intent.ACTION_GET_CONTENT).run { 27 doShowChooser()
28 type = "image/*" 28 else
29 addCategory(Intent.CATEGORY_OPENABLE)
30 startActivityForResult(this, GET_IMAGE)
31 }
32 } else {
33 showChooser = true 29 showChooser = true
30 }
31
32 fun doShowChooser(): Unit {
33 Intent(Intent.ACTION_GET_CONTENT).run {
34 type = "image/*"
35 addCategory(Intent.CATEGORY_OPENABLE)
36 startActivityForResult(this, GET_IMAGE)
34 } 37 }
35 } 38 }
36 39
37 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 40 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
38 showChooser = false 41 showChooser = false
43 Intent(Intent.ACTION_SEND, imageUri, this, EditImage::class.java).run { 46 Intent(Intent.ACTION_SEND, imageUri, this, EditImage::class.java).run {
44 startActivity(this) 47 startActivity(this)
45 } 48 }
46 } else { 49 } else {
47 Toast.makeText(applicationContext, "Unable to get image!", Toast.LENGTH_LONG).show() 50 Toast.makeText(applicationContext, "Unable to get image!", Toast.LENGTH_LONG).show()
51 doShowChooser()
48 } 52 }
49 } 53 }
50 } 54 }
51 } 55 }