Skip to content

Commit 65aaa62

Browse files
authored
Technical: Update all the dependencies. (#628)
1 parent 80c12e5 commit 65aaa62

17 files changed

Lines changed: 156 additions & 147 deletions

File tree

.editorconfig

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
[*.{kt,kts}]
2+
ktlint_code_style=intellij_idea
23
indent_size=2
34
continuation_indent_size=2
4-
insert_final_newline=true
55
ij_kotlin_allow_trailing_comma=true
66
ij_kotlin_allow_trailing_comma_on_call_site=true
7+
insert_final_newline=true
78
ktlint_standard_annotation=disabled
8-
ktlint_standard_argument-list-wrapping=disabled
9-
ktlint_standard_spacing-between-declarations-with-annotations=disabled
9+
ktlint_standard_max-line-length=disabled
1010
ktlint_standard_filename=disabled
11-
ktlint_standard_property-naming=disabled
11+
ktlint_standard_spacing-between-declarations-with-annotations=disabled
12+
ktlint_standard_blank-line-between-when-conditions=disabled
13+
ktlint_standard_backing-property-naming=disabled
14+
ktlint_standard_kdoc=disabled
15+
ktlint_standard_condition-wrapping=disabled
16+
ktlint_experimental=enabled

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ codeQualityTools {
2323
}
2424
ktlint {
2525
toolVersion = libs.versions.ktlint.get()
26-
experimental = true
2726
}
2827
detekt {
2928
enabled = false // Don"t want.

cropper/build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,24 @@ dependencies {
5959
testImplementation(libs.mock)
6060
testImplementation(libs.robolectric)
6161
}
62+
63+
// Workaround https://github.com/cashapp/paparazzi/issues/1231
64+
plugins.withId("app.cash.paparazzi") {
65+
// Defer until afterEvaluate so that testImplementation is created by Android plugin.
66+
afterEvaluate {
67+
dependencies.constraints {
68+
add("testImplementation", "com.google.guava:guava") {
69+
attributes {
70+
attribute(
71+
TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
72+
objects.named(TargetJvmEnvironment::class.java, TargetJvmEnvironment.STANDARD_JVM),
73+
)
74+
}
75+
because(
76+
"LayoutLib and sdk-common depend on Guava's -jre published variant." +
77+
"See https://github.com/cashapp/paparazzi/issues/906.",
78+
)
79+
}
80+
}
81+
}
82+
}

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

Lines changed: 59 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -128,35 +128,33 @@ internal object BitmapUtils {
128128
uri: Uri,
129129
reqWidth: Int,
130130
reqHeight: Int,
131-
): BitmapSampled {
132-
return try {
133-
val resolver = context.contentResolver
134-
// First decode with inJustDecodeBounds=true to check dimensions
135-
val options = decodeImageForOption(resolver, uri)
136-
if (options.outWidth == -1 && options.outHeight == -1) throw RuntimeException("File is not a picture")
137-
// Calculate inSampleSize
138-
options.inSampleSize = max(
139-
calculateInSampleSizeByRequestedSize(
140-
width = options.outWidth,
141-
height = options.outHeight,
142-
reqWidth = reqWidth,
143-
reqHeight = reqHeight,
144-
),
145-
calculateInSampleSizeByMaxTextureSize(
146-
width = options.outWidth,
147-
height = options.outHeight,
148-
),
149-
)
150-
// Decode bitmap with inSampleSize set
151-
val bitmap = decodeImage(
152-
resolver = resolver,
153-
uri = uri,
154-
options = options,
155-
)
156-
BitmapSampled(bitmap, options.inSampleSize)
157-
} catch (e: Exception) {
158-
throw CropException.FailedToLoadBitmap(uri, e.message)
159-
}
131+
): BitmapSampled = try {
132+
val resolver = context.contentResolver
133+
// First decode with inJustDecodeBounds=true to check dimensions
134+
val options = decodeImageForOption(resolver, uri)
135+
if (options.outWidth == -1 && options.outHeight == -1) throw RuntimeException("File is not a picture")
136+
// Calculate inSampleSize
137+
options.inSampleSize = max(
138+
calculateInSampleSizeByRequestedSize(
139+
width = options.outWidth,
140+
height = options.outHeight,
141+
reqWidth = reqWidth,
142+
reqHeight = reqHeight,
143+
),
144+
calculateInSampleSizeByMaxTextureSize(
145+
width = options.outWidth,
146+
height = options.outHeight,
147+
),
148+
)
149+
// Decode bitmap with inSampleSize set
150+
val bitmap = decodeImage(
151+
resolver = resolver,
152+
uri = uri,
153+
options = options,
154+
)
155+
BitmapSampled(bitmap, options.inSampleSize)
156+
} catch (e: Exception) {
157+
throw CropException.FailedToLoadBitmap(uri, e.message)
160158
}
161159

162160
/**
@@ -325,58 +323,42 @@ internal object BitmapUtils {
325323
/**
326324
* Get left value of the bounding rectangle of the given points.
327325
*/
328-
fun getRectLeft(points: FloatArray): Float {
329-
return min(min(min(points[0], points[2]), points[4]), points[6])
330-
}
326+
fun getRectLeft(points: FloatArray): Float = min(min(min(points[0], points[2]), points[4]), points[6])
331327

332328
/**
333329
* Get top value of the bounding rectangle of the given points.
334330
*/
335-
fun getRectTop(points: FloatArray): Float {
336-
return min(min(min(points[1], points[3]), points[5]), points[7])
337-
}
331+
fun getRectTop(points: FloatArray): Float = min(min(min(points[1], points[3]), points[5]), points[7])
338332

339333
/**
340334
* Get right value of the bounding rectangle of the given points.
341335
*/
342-
fun getRectRight(points: FloatArray): Float {
343-
return max(max(max(points[0], points[2]), points[4]), points[6])
344-
}
336+
fun getRectRight(points: FloatArray): Float = max(max(max(points[0], points[2]), points[4]), points[6])
345337

346338
/**
347339
* Get bottom value of the bounding rectangle of the given points.
348340
*/
349-
fun getRectBottom(points: FloatArray): Float {
350-
return max(max(max(points[1], points[3]), points[5]), points[7])
351-
}
341+
fun getRectBottom(points: FloatArray): Float = max(max(max(points[1], points[3]), points[5]), points[7])
352342

353343
/**
354344
* Get width of the bounding rectangle of the given points.
355345
*/
356-
fun getRectWidth(points: FloatArray): Float {
357-
return getRectRight(points) - getRectLeft(points)
358-
}
346+
fun getRectWidth(points: FloatArray): Float = getRectRight(points) - getRectLeft(points)
359347

360348
/**
361349
* Get height of the bounding rectangle of the given points.
362350
*/
363-
fun getRectHeight(points: FloatArray): Float {
364-
return getRectBottom(points) - getRectTop(points)
365-
}
351+
fun getRectHeight(points: FloatArray): Float = getRectBottom(points) - getRectTop(points)
366352

367353
/**
368354
* Get horizontal center value of the bounding rectangle of the given points.
369355
*/
370-
fun getRectCenterX(points: FloatArray): Float {
371-
return (getRectRight(points) + getRectLeft(points)) / 2f
372-
}
356+
fun getRectCenterX(points: FloatArray): Float = (getRectRight(points) + getRectLeft(points)) / 2f
373357

374358
/**
375359
* Get vertical center value of the bounding rectangle of the given points.
376360
*/
377-
fun getRectCenterY(points: FloatArray): Float {
378-
return (getRectBottom(points) + getRectTop(points)) / 2f
379-
}
361+
fun getRectCenterY(points: FloatArray): Float = (getRectBottom(points) + getRectTop(points)) / 2f
380362

381363
/**
382364
* Get a rectangle for the given 4 points (x0,y0,x1,y1,x2,y2,x3,y3) by finding the min/max 2
@@ -457,7 +439,7 @@ internal object BitmapUtils {
457439
): Uri {
458440
val newUri = customOutputUri ?: buildUri(context, compressFormat)
459441

460-
return context.contentResolver.openOutputStream(newUri, WRITE_AND_TRUNCATE).use {
442+
return context.contentResolver.openOutputStream(newUri, WRITE_AND_TRUNCATE)!!.use {
461443
bitmap.compress(compressFormat, compressQuality, it)
462444
newUri
463445
}
@@ -701,14 +683,12 @@ internal object BitmapUtils {
701683
* Decode image from uri using "inJustDecodeBounds" to get the image dimensions.
702684
*/
703685
@Throws(FileNotFoundException::class)
704-
private fun decodeImageForOption(resolver: ContentResolver, uri: Uri): BitmapFactory.Options {
705-
return resolver.openInputStream(uri).use {
706-
val options = BitmapFactory.Options()
707-
options.inJustDecodeBounds = true
708-
BitmapFactory.decodeStream(it, EMPTY_RECT, options)
709-
options.inJustDecodeBounds = false
710-
options
711-
}
686+
private fun decodeImageForOption(resolver: ContentResolver, uri: Uri): BitmapFactory.Options = resolver.openInputStream(uri).use {
687+
val options = BitmapFactory.Options()
688+
options.inJustDecodeBounds = true
689+
BitmapFactory.decodeStream(it, EMPTY_RECT, options)
690+
options.inJustDecodeBounds = false
691+
options
712692
}
713693

714694
/**
@@ -790,14 +770,14 @@ internal object BitmapUtils {
790770
* Note: rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping.
791771
*/
792772
private fun cropForRotatedImage(
793-
bitmap: Bitmap?,
773+
bitmap: Bitmap,
794774
cropPoints: FloatArray,
795775
rect: Rect,
796776
degreesRotated: Int,
797777
fixAspectRatio: Boolean,
798778
aspectRatioX: Int,
799779
aspectRatioY: Int,
800-
): Bitmap? {
780+
): Bitmap {
801781
var tempBitmap = bitmap
802782
if (degreesRotated % 90 != 0) {
803783
var adjLeft = 0
@@ -823,14 +803,14 @@ internal object BitmapUtils {
823803
}
824804
val bitmapTmp = tempBitmap
825805
tempBitmap = Bitmap.createBitmap(
826-
bitmap!!,
806+
bitmap,
827807
rect.left,
828808
rect.top,
829809
rect.width(),
830810
rect.height(),
831811
)
832812
if (bitmapTmp != tempBitmap) {
833-
bitmapTmp?.recycle()
813+
bitmapTmp.recycle()
834814
}
835815
}
836816
return tempBitmap
@@ -888,22 +868,20 @@ internal object BitmapUtils {
888868
degrees: Int,
889869
flipHorizontally: Boolean,
890870
flipVertically: Boolean,
891-
): Bitmap {
892-
return if (degrees > 0 || flipHorizontally || flipVertically) {
893-
val matrix = Matrix()
894-
matrix.setRotate(degrees.toFloat())
895-
matrix.postScale(
896-
(if (flipHorizontally) -1 else 1).toFloat(),
897-
(if (flipVertically) -1 else 1).toFloat(),
898-
)
899-
val newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, false)
900-
if (newBitmap != bitmap) {
901-
bitmap.recycle()
902-
}
903-
newBitmap
904-
} else {
905-
bitmap
871+
): Bitmap = if (degrees > 0 || flipHorizontally || flipVertically) {
872+
val matrix = Matrix()
873+
matrix.setRotate(degrees.toFloat())
874+
matrix.postScale(
875+
(if (flipHorizontally) -1 else 1).toFloat(),
876+
(if (flipVertically) -1 else 1).toFloat(),
877+
)
878+
val newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, false)
879+
if (newBitmap != bitmap) {
880+
bitmap.recycle()
906881
}
882+
newBitmap
883+
} else {
884+
bitmap
907885
}
908886
// Only need to check for width since opengl textures are always squared
909887
// Keep track of the maximum texture size

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ object CropImage {
7474
/**
7575
* Result data of Crop Image Activity.
7676
*/
77-
open class ActivityResult : CropResult, Parcelable {
77+
open class ActivityResult :
78+
CropResult,
79+
Parcelable {
7880

7981
constructor(
8082
originalUri: Uri?,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import com.canhub.cropper.databinding.CropImageActivityBinding
2929
import com.canhub.cropper.utils.getUriForFile
3030
import java.io.File
3131

32-
open class CropImageActivity : AppCompatActivity(), OnSetImageUriCompleteListener, OnCropImageCompleteListener {
32+
open class CropImageActivity :
33+
AppCompatActivity(),
34+
OnSetImageUriCompleteListener,
35+
OnCropImageCompleteListener {
3336

3437
/** Persist URI image to crop URI if specific permissions are required. */
3538
private var cropImageUri: Uri? = null

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import android.widget.ImageView
1515
internal class CropImageAnimation(
1616
private val imageView: ImageView,
1717
private val cropOverlayView: CropOverlayView,
18-
) : Animation(), AnimationListener {
18+
) : Animation(),
19+
AnimationListener {
1920

2021
private val startBoundPoints = FloatArray(8)
2122
private val endBoundPoints = FloatArray(8)

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,9 @@ internal class CropImageIntentChooser(
187187
* See [StackOverflow
188188
* question](http://stackoverflow.com/questions/32789027/android-m-camera-intent-permission-bug).
189189
*/
190-
private fun isExplicitCameraPermissionRequired(context: Context): Boolean {
191-
return SDK_INT >= Build.VERSION_CODES.M &&
192-
hasCameraPermissionInManifest(context) &&
193-
context.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
194-
}
190+
private fun isExplicitCameraPermissionRequired(context: Context): Boolean = SDK_INT >= Build.VERSION_CODES.M &&
191+
hasCameraPermissionInManifest(context) &&
192+
context.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
195193

196194
/**
197195
* Check if the app requests a specific permission in the manifest.

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import kotlin.math.sqrt
3939
class CropImageView @JvmOverloads constructor(
4040
context: Context,
4141
attrs: AttributeSet? = null,
42-
) : FrameLayout(context, attrs), CropWindowChangeListener {
42+
) : FrameLayout(context, attrs),
43+
CropWindowChangeListener {
4344

4445
/** Image view widget used to show the image for cropping. */
4546
private val imageView: ImageView
@@ -1756,15 +1757,13 @@ class CropImageView @JvmOverloads constructor(
17561757
*
17571758
* [context] used to retrieve the bitmap in case you need from activity result
17581759
*/
1759-
fun getBitmap(context: Context): Bitmap? {
1760-
return bitmap ?: try {
1761-
when {
1762-
SDK_INT >= 28 -> ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uriContent!!))
1763-
else -> @Suppress("DEPRECATION") MediaStore.Images.Media.getBitmap(context.contentResolver, uriContent)
1764-
}
1765-
} catch (e: Exception) {
1766-
null
1760+
fun getBitmap(context: Context): Bitmap? = bitmap ?: try {
1761+
when {
1762+
SDK_INT >= 28 -> ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uriContent!!))
1763+
else -> @Suppress("DEPRECATION") MediaStore.Images.Media.getBitmap(context.contentResolver, uriContent)
17671764
}
1765+
} catch (e: Exception) {
1766+
null
17681767
}
17691768

17701769
/**

cropper/src/test/kotlin/com/canhub/cropper/ContractTestFragment.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@ class ContractTestFragment(
1919
cropImage.launch(input)
2020
}
2121

22-
fun cropImageIntent(input: CropImageContractOptions): Intent {
23-
return cropImage.contract.createIntent(requireContext(), input)
24-
}
22+
fun cropImageIntent(input: CropImageContractOptions): Intent = cropImage.contract.createIntent(requireContext(), input)
2523
}

0 commit comments

Comments
 (0)