Mercurial > cgi-bin > hgweb.cgi > SimpleResizer
comparison app/src/main/java/com/bartsent/simpleresizer/MainActivity.kt @ 3:21d2df45d350
Fix race condition.
author | David Barts <n5jrn@me.com> |
---|---|
date | Tue, 09 Feb 2021 08:56:00 -0800 |
parents | 06825e49f7aa |
children | b6a217c850fb |
comparison
equal
deleted
inserted
replaced
2:06825e49f7aa | 3:21d2df45d350 |
---|---|
9 import com.bartsent.simpleresizer.databinding.ActivityMainBinding | 9 import com.bartsent.simpleresizer.databinding.ActivityMainBinding |
10 | 10 |
11 class MainActivity : AppCompatActivity() { | 11 class MainActivity : AppCompatActivity() { |
12 val GET_IMAGE = 1 | 12 val GET_IMAGE = 1 |
13 private lateinit var binding: ActivityMainBinding | 13 private lateinit var binding: ActivityMainBinding |
14 private var showChooser = true | |
14 | 15 |
15 override fun onCreate(savedInstanceState: Bundle?) { | 16 override fun onCreate(savedInstanceState: Bundle?) { |
16 super.onCreate(savedInstanceState) | 17 super.onCreate(savedInstanceState) |
17 setContentView(R.layout.activity_main) | |
18 binding = ActivityMainBinding.inflate(layoutInflater) | 18 binding = ActivityMainBinding.inflate(layoutInflater) |
19 setContentView(binding.root) | |
19 } | 20 } |
20 | 21 |
21 override fun onResume() { | 22 override fun onResume() { |
22 super.onResume() | 23 super.onResume() |
23 Intent(Intent.ACTION_GET_CONTENT).run { | 24 if (showChooser) { |
24 type = "image/*" | 25 Intent(Intent.ACTION_GET_CONTENT).run { |
25 addCategory(Intent.CATEGORY_OPENABLE) | 26 type = "image/*" |
26 startActivityForResult(this, GET_IMAGE) | 27 addCategory(Intent.CATEGORY_OPENABLE) |
28 startActivityForResult(this, GET_IMAGE) | |
29 } | |
30 } else { | |
31 showChooser = true | |
27 } | 32 } |
28 } | 33 } |
29 | 34 |
30 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | 35 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
36 showChooser = false | |
31 super.onActivityResult(requestCode, resultCode, data) | 37 super.onActivityResult(requestCode, resultCode, data) |
32 Log.d("MainActivity", "onActivityResult called") | 38 Log.d("MainActivity", "onActivityResult called, requestCode=$requestCode, resultCode=$resultCode") |
33 if (requestCode == GET_IMAGE) { | 39 if (requestCode == GET_IMAGE) { |
34 val imageUri = data?.data | 40 val imageUri = data?.data |
41 Log.d("MainActivity", "imageUri=${imageUri ?: "(null)"}") | |
35 if (resultCode == Activity.RESULT_OK && imageUri != null) { | 42 if (resultCode == Activity.RESULT_OK && imageUri != null) { |
36 Intent(Intent.ACTION_SEND, imageUri, this, EditImage::class.java).run { | 43 Intent(Intent.ACTION_SEND, imageUri, this, EditImage::class.java).run { |
37 startActivity(this) | 44 startActivity(this) |
38 } | 45 } |
39 } else { | 46 } else { |