Android-Image-Cropper icon indicating copy to clipboard operation
Android-Image-Cropper copied to clipboard

ActivityResultContract for custom activity

Open andriishpek-sigma opened this issue 5 months ago • 0 comments

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.

andriishpek-sigma avatar Jan 30 '24 09:01 andriishpek-sigma