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

Refactor cropimageview to kotlin #94

Merged
merged 5 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [unreleased x.x.x] -
### Changed
- CropOverlayView to kotlin [#38](https://github.com/CanHub/Android-Image-Cropper/issues/38)
- CropOverlayView to Kotlin [#38](https://github.com/CanHub/Android-Image-Cropper/issues/38)
- CropImageView to Kotlin [#39](https://github.com/CanHub/Android-Image-Cropper/issues/39)

## [2.2.2] - 19/03/21
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.lang.ref.WeakReference

internal class BitmapLoadingWorkerJob internal constructor(
class BitmapLoadingWorkerJob internal constructor(
private val activity: FragmentActivity,
cropImageView: CropImageView,
val uri: Uri
Expand Down
34 changes: 13 additions & 21 deletions cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ open class CropImageActivity :
} == true &&
CommonVersionCheck.isAtLeastM23()
) {

// request permissions and handle the result in onRequestPermissionsResult()
requestPermissions(
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
Expand All @@ -89,9 +88,7 @@ open class CropImageActivity :
}

supportActionBar?.let {
title = if (options.activityTitle != null && options.activityTitle.isNotEmpty())
options.activityTitle
else resources.getString(R.string.crop_image_activity_title)
title = if (options.activityTitle.isNotEmpty()) options.activityTitle else resources.getString(R.string.crop_image_activity_title)
it.setDisplayHomeAsUpEnabled(true)
}
}
Expand Down Expand Up @@ -221,12 +218,11 @@ open class CropImageActivity :

override fun onSetImageUriComplete(view: CropImageView, uri: Uri, error: Exception?) {
if (error == null) {
if (options.initialCropWindowRectangle != null) {
if (options.initialCropWindowRectangle != null)
cropImageView?.cropRect = options.initialCropWindowRectangle
}
if (options.initialRotation > -1) {

if (options.initialRotation > -1)
cropImageView?.rotatedDegrees = options.initialRotation
}
} else setResult(null, error, 1)
}

Expand All @@ -238,19 +234,15 @@ open class CropImageActivity :
* Execute crop image and save the result tou output uri.
*/
open fun cropImage() {
if (options.noOutputImage) {
setResult(null, null, 1)
} else {
val outputUri = outputUri
cropImageView?.saveCroppedImageAsync(
outputUri,
options.outputCompressFormat,
options.outputCompressQuality,
options.outputRequestWidth,
options.outputRequestHeight,
options.outputRequestSizeOptions
)
}
if (options.noOutputImage) setResult(null, null, 1)
else cropImageView?.saveCroppedImageAsync(
outputUri,
options.outputCompressFormat,
options.outputCompressQuality,
options.outputRequestWidth,
options.outputRequestHeight,
options.outputRequestSizeOptions
)
}

/**
Expand Down
Loading