Skip to content

Commit

Permalink
API: Make BitmapLoadingWorkerJob internal.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech committed Oct 20, 2022
1 parent 9b39b1d commit 605f14c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ import kotlinx.coroutines.withContext
import java.lang.ref.WeakReference
import kotlin.coroutines.CoroutineContext

class BitmapLoadingWorkerJob internal constructor(
internal class BitmapLoadingWorkerJob internal constructor(
private val context: Context,
cropImageView: CropImageView,
val uri: Uri,
) : CoroutineScope {

private val width: Int
private val height: Int
private val cropImageViewReference = WeakReference(cropImageView)
private var currentJob: Job = Job()
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + currentJob

override val coroutineContext: CoroutineContext get() = Dispatchers.Main + currentJob

init {
val metrics = cropImageView.resources.displayMetrics
val densityAdj: Double = if (metrics.density > 1) (1.0 / metrics.density) else 1.0
val densityAdj = if (metrics.density > 1) (1.0 / metrics.density) else 1.0
width = (metrics.widthPixels * densityAdj).toInt()
height = (metrics.heightPixels * densityAdj).toInt()
}
Expand Down Expand Up @@ -86,9 +85,7 @@ class BitmapLoadingWorkerJob internal constructor(
}

/** The result of BitmapLoadingWorkerJob async loading. */
companion object
class Result {

internal companion object class Result {
/**
* The Android URI of the image to load.
* NOT a file path, for it use [getUriFilePath]
Expand Down
9 changes: 5 additions & 4 deletions cropper/src/main/kotlin/com/canhub/cropper/CropImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ import kotlin.math.sqrt

/** Custom view that provides cropping capabilities to an image. */
@Suppress("unused", "MemberVisibilityCanBePrivate")
class CropImageView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
FrameLayout(context, attrs),
CropWindowChangeListener {
class CropImageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
) : FrameLayout(context, attrs), CropWindowChangeListener {

/** Image view widget used to show the image for cropping. */
private val imageView: ImageView
Expand Down Expand Up @@ -871,7 +872,7 @@ class CropImageView @JvmOverloads constructor(context: Context, attrs: Attribute
*
* @param result the result of bitmap loading
*/
fun onSetImageUriAsyncComplete(result: BitmapLoadingWorkerJob.Result) {
internal fun onSetImageUriAsyncComplete(result: BitmapLoadingWorkerJob.Result) {
bitmapLoadingWorkerJob = null
setProgressBarVisibility()
if (result.error == null) {
Expand Down

0 comments on commit 605f14c

Please sign in to comment.