Skip to content
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

ActivityResultContract for custom activity #611

Closed
andriishpek-sigma opened this issue Jan 30, 2024 · 4 comments
Closed

ActivityResultContract for custom activity #611

andriishpek-sigma opened this issue Jan 30, 2024 · 4 comments

Comments

@andriishpek-sigma
Copy link

It would be nice if CropImageContract allows to provide custom activity class. Currently I need to implement custom contract with delegation to library implementation:

class CustomCropImageContract :
    ActivityResultContract<CropImageContractOptions, CropImageView.CropResult>() {

    private val delegate = CropImageContract()

    override fun createIntent(context: Context, input: CropImageContractOptions): Intent {
        return delegate.createIntent(context, input).apply {
            setClass(context, CropImage::class.java)
        }
    }

    override fun parseResult(resultCode: Int, intent: Intent?): CropImageView.CropResult {
        return delegate.parseResult(resultCode, intent)
    }

    override fun getSynchronousResult(
        context: Context,
        input: CropImageContractOptions
    ): SynchronousResult<CropImageView.CropResult>? {
        return delegate.getSynchronousResult(context, input)
    }
}

CropImageContractOptions may be a good place to provide custom class.

@vanniktech
Copy link
Contributor

Roll your own activity and just use the CropImageView.

@andriishpek-sigma
Copy link
Author

@vanniktech That's not the question I'm asking. I am using my own activity. And I have to write this crutch as above for result handing, simply because your default result contract isn't suitable for custom activities.

@vanniktech
Copy link
Contributor

simply because your default result contract isn't suitable for custom activities.

Yeah also this I'm planning to deprecate. It makes no sense to use this from the library if you are writing your own Activity.

@andriishpek-sigma
Copy link
Author

It makes no sense to use this from the library if you are writing your own Activity.

It does. I extend CropImageActivity that returns as a result CropImageView.CropResult. On the other hand CropImageContract properly parses and returns actual instance of CropImageView.CropResult.

The point of my suggestion is that CropImageActivity can be extended, but CropImageContract cannot (it explicitly creates an intent on CropImageActivity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants