android: fix picking file from gallery (#631)

This commit is contained in:
Evgeny Poberezkin
2022-05-10 16:15:11 +01:00
committed by GitHub
parent 3d8ccdaa9f
commit 89ea57e4b6
2 changed files with 11 additions and 11 deletions

View File

@@ -11,7 +11,7 @@ android {
applicationId "chat.simplex.app"
minSdk 29
targetSdk 32
versionCode 28
versionCode 30
versionName "2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@@ -128,16 +128,16 @@ class CustomTakePicturePreview: ActivityResultContract<Void?, Bitmap?>() {
}
}
class GetGalleryContent: ActivityResultContracts.GetContent() {
override fun createIntent(context: Context, input: String): Intent {
super.createIntent(context, input)
return Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
}
}
//class GetGalleryContent: ActivityResultContracts.GetContent() {
// override fun createIntent(context: Context, input: String): Intent {
// super.createIntent(context, input)
// return Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
// }
//}
@Composable
fun rememberGalleryLauncher(cb: (Uri?) -> Unit): ManagedActivityResultLauncher<String, Uri?> =
rememberLauncherForActivityResult(contract = GetGalleryContent(), cb)
//@Composable
//fun rememberGalleryLauncher(cb: (Uri?) -> Unit): ManagedActivityResultLauncher<String, Uri?> =
// rememberLauncherForActivityResult(contract = GetGalleryContent(), cb)
@Composable
fun rememberCameraLauncher(cb: (Bitmap?) -> Unit): ManagedActivityResultLauncher<Void?, Bitmap?> =
@@ -160,7 +160,7 @@ fun GetImageBottomSheet(
hideBottomSheet: () -> Unit
) {
val context = LocalContext.current
val galleryLauncher = rememberGalleryLauncher { uri: Uri? ->
val galleryLauncher = rememberGetContentLauncher { uri: Uri? ->
if (uri != null) {
val source = ImageDecoder.createSource(context.contentResolver, uri)
val bitmap = ImageDecoder.decodeBitmap(source)