Skip to content

Commit 52f6721

Browse files
authored
Refactoring: Always require passing all BitmapCroppingWorkerJob.Result parameters & use more named arguments. (#511)
1 parent f483517 commit 52f6721

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

cropper/src/main/kotlin/com/canhub/cropper/BitmapCroppingWorkerJob.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,17 @@ internal class BitmapCroppingWorkerJob(
7474
}
7575
else -> {
7676
onPostExecute(
77-
Result(bitmap = null, sampleSize = 1),
77+
Result(
78+
bitmap = null,
79+
uri = null,
80+
error = null,
81+
sampleSize = 1,
82+
),
7883
)
7984
return@launch
8085
}
8186
}
87+
8288
val resizedBitmap = BitmapUtils.resizeBitmap(
8389
bitmap = bitmapSampled.bitmap,
8490
reqWidth = reqWidth,
@@ -100,13 +106,19 @@ internal class BitmapCroppingWorkerJob(
100106
bitmap = resizedBitmap,
101107
uri = newUri,
102108
sampleSize = bitmapSampled.sampleSize,
109+
error = null,
103110
),
104111
)
105112
}
106113
}
107114
} catch (throwable: Exception) {
108115
onPostExecute(
109-
Result(error = throwable, sampleSize = 1),
116+
Result(
117+
bitmap = null,
118+
uri = null,
119+
error = throwable,
120+
sampleSize = 1,
121+
),
110122
)
111123
}
112124
}
@@ -134,11 +146,11 @@ internal class BitmapCroppingWorkerJob(
134146

135147
internal data class Result(
136148
/** The cropped bitmap. */
137-
val bitmap: Bitmap? = null,
149+
val bitmap: Bitmap?,
138150
/** The saved cropped bitmap uri. */
139-
val uri: Uri? = null,
151+
val uri: Uri?,
140152
/** The error that occurred during async bitmap cropping. */
141-
val error: Exception? = null,
153+
val error: Exception?,
142154
/** Sample size used creating the crop bitmap to lower its size. */
143155
val sampleSize: Int,
144156
)

cropper/src/main/kotlin/com/canhub/cropper/CropImageView.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -930,16 +930,16 @@ class CropImageView @JvmOverloads constructor(
930930
val listener = mOnCropImageCompleteListener
931931
if (listener != null) {
932932
val cropResult = CropResult(
933-
originalBitmap,
934-
imageUri,
935-
result.bitmap,
936-
result.uri,
937-
result.error,
938-
cropPoints,
939-
cropRect,
940-
wholeImageRect,
941-
rotatedDegrees,
942-
result.sampleSize,
933+
originalBitmap = originalBitmap,
934+
originalUri = imageUri,
935+
bitmap = result.bitmap,
936+
uriContent = result.uri,
937+
error = result.error,
938+
cropPoints = cropPoints,
939+
cropRect = cropRect,
940+
wholeImageRect = wholeImageRect,
941+
rotation = rotatedDegrees,
942+
sampleSize = result.sampleSize,
943943
)
944944
listener.onCropImageComplete(this, cropResult)
945945
}

0 commit comments

Comments
 (0)