Skip to content

Commit

Permalink
API: Make CropImageIntentChooser internal.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech committed Oct 23, 2022
1 parent 3ec7695 commit 7381f62
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import android.provider.MediaStore
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts

class CropImageIntentChooser(
internal class CropImageIntentChooser(
private val activity: ComponentActivity,
private val callback: ResultCallback,
) {
interface ResultCallback {
internal interface ResultCallback {
fun onSuccess(uri: Uri?)
fun onCancelled()
}

companion object {
internal companion object {
const val GOOGLE_PHOTOS = "com.google.android.apps.photos"
const val GOOGLE_PHOTOS_GO = "com.google.android.apps.photosgo"
const val SAMSUNG_GALLERY = "com.sec.android.gallery3d"
Expand All @@ -40,16 +40,15 @@ class CropImageIntentChooser(
MIUI_GALLERY,
)
private var cameraImgUri: Uri? = null
private val intentChooser =
activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { activityRes ->
private val intentChooser = activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { activityRes ->
if (activityRes.resultCode == Activity.RESULT_OK) {
/*
Here we don't know whether a gallery app or the camera app is selected
via the intent chooser. If a gallery app is selected and an image is
chosen then we get the result from activityRes.
If a camera app is selected we take the uri we passed to the camera
app for storing the captured image
*/
/**
* Here we don't know whether a gallery app or the camera app is selected
* via the intent chooser. If a gallery app is selected and an image is
* chosen then we get the result from activityRes.
* If a camera app is selected we take the uri we passed to the camera
* app for storing the captured image
*/
(activityRes.data?.data ?: cameraImgUri).let { uri ->
callback.onSuccess(uri)
}
Expand Down

0 comments on commit 7381f62

Please sign in to comment.