-
-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onActivityResult is deprecated #26
Comments
Hey @zihadrizkyef thanks for the suggestion, for sure is time for us to change. I'm happy if you have time to do it, just need to open the PR ^^ |
Hello guys, there is a way to do this with ActivityResult Api
Create launcher
and when u need to start it
|
Yes @dimiitpk And this is something we want to add in the library directly, I'm organising now all work to be done in the lib =p But feel free to open a PR if you are confident of how doing it! |
It is not a bug nor an issue with current version.
And then launch like this:
|
@AlexanderHoddleITE please feel free to drop a PR to update the library if you are feeling up to help the community today, hahahaha |
@Canato no need for PR to update the library for this one, just like @AlexanderHoddleITE said this is not a bug nor an issue with the library as it is already able to work with the latest approach of onActivityResult. Just need to update the README.md for the documentation update. You can close this now. |
Indeed @ArcherEmiya05 you can do your own wrapper around, but we are still using |
Can't it just be remove since all we need is the intent itself then just leave it to consumer to handle the result? |
I would like to send a PR for this, but I am not sure what the best option is here. One way to have this working could be to have CropImageOptions as input and ActivityResult as output like this: class CropImageContract : ActivityResultContract<CropImageOptions, CropImage.ActivityResult?>() {
override fun createIntent(context: Context, input: CropImageOptions): Intent {
input.validate()
return Intent().apply {
val bundle = Bundle()
bundle.putParcelable(CropImage.CROP_IMAGE_EXTRA_OPTIONS, input)
putExtra(CropImage.CROP_IMAGE_EXTRA_BUNDLE, bundle)
}
}
override fun parseResult(
resultCode: Int,
intent: Intent?
): CropImage.ActivityResult? {
return getActivityResult(intent)
}
} The problem with this is that one cannot supply a Uri as input, so it only works if you want to show the file picker. Maybe its better to have the options in the constructor and the uri as input? class CropImageContract(
private val options: CropImageOptions
) : ActivityResultContract<Uri?, CropImage.ActivityResult?>() {
init {
options.validate()
}
override fun createIntent(context: Context, input: Uri?): Intent {
return Intent().apply {
val bundle = Bundle()
bundle.putParcelable(CropImage.CROP_IMAGE_EXTRA_SOURCE, input)
bundle.putParcelable(CropImage.CROP_IMAGE_EXTRA_OPTIONS, options)
putExtra(CropImage.CROP_IMAGE_EXTRA_BUNDLE, bundle)
}
}
override fun parseResult(
resultCode: Int,
intent: Intent?
): CropImage.ActivityResult? {
return getActivityResult(intent)
}
} This is less flexible if one needs multiple crop options. Thoughts? |
@connyduck and a new data class, like
So we could use Would work? 🤔 |
Yes that would work, but its cumbersome if you don't want to supply a uri. Maybe it can be improved by adding some convienience functions. I'll try to find a nice solution. |
I am working with private val cropActivityResultContract = object : ActivityResultContract<Any?, Uri>() {
override fun createIntent(context: Context, input: Any?): Intent {
return CropImage.activity()
.setGuidelines(CropImageView.Guidelines.ON)
.getIntent(context)
}
override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
return CropImage.getActivityResult(intent)?.uriContent
}
}
private lateinit var cropActivityResultLauncher: ActivityResultLauncher<Any?> In my |
|
Hey @swagatgithub not you don't need to implement yourself like Dimiitpk needed on the time he wrote. You can use the library activity contracts, like is showed on the README and the sample folder |
Hi, i really love your project, but i see that we are still using OnActivityResult which is deprecated.
Maybe we can use this one : https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract
The text was updated successfully, but these errors were encountered: