Skip to content

Commit

Permalink
Technical: Update all the dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech committed May 15, 2024
1 parent d382c97 commit 37b5a5d
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 139 deletions.
13 changes: 9 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[*.{kt,kts}]
ktlint_code_style=intellij_idea
indent_size=2
continuation_indent_size=2
insert_final_newline=true
ij_kotlin_allow_trailing_comma=true
ij_kotlin_allow_trailing_comma_on_call_site=true
insert_final_newline=true
ktlint_standard_annotation=disabled
ktlint_standard_argument-list-wrapping=disabled
ktlint_standard_spacing-between-declarations-with-annotations=disabled
ktlint_standard_max-line-length=disabled
ktlint_standard_filename=disabled
ktlint_standard_property-naming=disabled
ktlint_standard_spacing-between-declarations-with-annotations=disabled
ktlint_standard_blank-line-between-when-conditions=disabled
ktlint_standard_backing-property-naming=disabled
ktlint_standard_kdoc=disabled
ktlint_standard_condition-wrapping=disabled
ktlint_experimental=enabled
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ codeQualityTools {
}
ktlint {
toolVersion = libs.versions.ktlint.get()
experimental = true
}
detekt {
enabled = false // Don"t want.
Expand Down
21 changes: 21 additions & 0 deletions cropper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,24 @@ dependencies {
testImplementation(libs.mock)
testImplementation(libs.robolectric)
}

// Workaround https://github.com/cashapp/paparazzi/issues/1231
plugins.withId("app.cash.paparazzi") {
// Defer until afterEvaluate so that testImplementation is created by Android plugin.
afterEvaluate {
dependencies.constraints {
add("testImplementation", "com.google.guava:guava") {
attributes {
attribute(
TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
objects.named(TargetJvmEnvironment::class.java, TargetJvmEnvironment.STANDARD_JVM),
)
}
because(
"LayoutLib and sdk-common depend on Guava's -jre published variant." +
"See https://github.com/cashapp/paparazzi/issues/906.",
)
}
}
}
}
130 changes: 54 additions & 76 deletions cropper/src/main/kotlin/com/canhub/cropper/BitmapUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,33 @@ internal object BitmapUtils {
uri: Uri,
reqWidth: Int,
reqHeight: Int,
): BitmapSampled {
return try {
val resolver = context.contentResolver
// First decode with inJustDecodeBounds=true to check dimensions
val options = decodeImageForOption(resolver, uri)
if (options.outWidth == -1 && options.outHeight == -1) throw RuntimeException("File is not a picture")
// Calculate inSampleSize
options.inSampleSize = max(
calculateInSampleSizeByRequestedSize(
width = options.outWidth,
height = options.outHeight,
reqWidth = reqWidth,
reqHeight = reqHeight,
),
calculateInSampleSizeByMaxTextureSize(
width = options.outWidth,
height = options.outHeight,
),
)
// Decode bitmap with inSampleSize set
val bitmap = decodeImage(
resolver = resolver,
uri = uri,
options = options,
)
BitmapSampled(bitmap, options.inSampleSize)
} catch (e: Exception) {
throw CropException.FailedToLoadBitmap(uri, e.message)
}
): BitmapSampled = try {
val resolver = context.contentResolver
// First decode with inJustDecodeBounds=true to check dimensions
val options = decodeImageForOption(resolver, uri)
if (options.outWidth == -1 && options.outHeight == -1) throw RuntimeException("File is not a picture")
// Calculate inSampleSize
options.inSampleSize = max(
calculateInSampleSizeByRequestedSize(
width = options.outWidth,
height = options.outHeight,
reqWidth = reqWidth,
reqHeight = reqHeight,
),
calculateInSampleSizeByMaxTextureSize(
width = options.outWidth,
height = options.outHeight,
),
)
// Decode bitmap with inSampleSize set
val bitmap = decodeImage(
resolver = resolver,
uri = uri,
options = options,
)
BitmapSampled(bitmap, options.inSampleSize)
} catch (e: Exception) {
throw CropException.FailedToLoadBitmap(uri, e.message)
}

/**
Expand Down Expand Up @@ -325,58 +323,42 @@ internal object BitmapUtils {
/**
* Get left value of the bounding rectangle of the given points.
*/
fun getRectLeft(points: FloatArray): Float {
return min(min(min(points[0], points[2]), points[4]), points[6])
}
fun getRectLeft(points: FloatArray): Float = min(min(min(points[0], points[2]), points[4]), points[6])

/**
* Get top value of the bounding rectangle of the given points.
*/
fun getRectTop(points: FloatArray): Float {
return min(min(min(points[1], points[3]), points[5]), points[7])
}
fun getRectTop(points: FloatArray): Float = min(min(min(points[1], points[3]), points[5]), points[7])

/**
* Get right value of the bounding rectangle of the given points.
*/
fun getRectRight(points: FloatArray): Float {
return max(max(max(points[0], points[2]), points[4]), points[6])
}
fun getRectRight(points: FloatArray): Float = max(max(max(points[0], points[2]), points[4]), points[6])

/**
* Get bottom value of the bounding rectangle of the given points.
*/
fun getRectBottom(points: FloatArray): Float {
return max(max(max(points[1], points[3]), points[5]), points[7])
}
fun getRectBottom(points: FloatArray): Float = max(max(max(points[1], points[3]), points[5]), points[7])

/**
* Get width of the bounding rectangle of the given points.
*/
fun getRectWidth(points: FloatArray): Float {
return getRectRight(points) - getRectLeft(points)
}
fun getRectWidth(points: FloatArray): Float = getRectRight(points) - getRectLeft(points)

/**
* Get height of the bounding rectangle of the given points.
*/
fun getRectHeight(points: FloatArray): Float {
return getRectBottom(points) - getRectTop(points)
}
fun getRectHeight(points: FloatArray): Float = getRectBottom(points) - getRectTop(points)

/**
* Get horizontal center value of the bounding rectangle of the given points.
*/
fun getRectCenterX(points: FloatArray): Float {
return (getRectRight(points) + getRectLeft(points)) / 2f
}
fun getRectCenterX(points: FloatArray): Float = (getRectRight(points) + getRectLeft(points)) / 2f

/**
* Get vertical center value of the bounding rectangle of the given points.
*/
fun getRectCenterY(points: FloatArray): Float {
return (getRectBottom(points) + getRectTop(points)) / 2f
}
fun getRectCenterY(points: FloatArray): Float = (getRectBottom(points) + getRectTop(points)) / 2f

/**
* Get a rectangle for the given 4 points (x0,y0,x1,y1,x2,y2,x3,y3) by finding the min/max 2
Expand Down Expand Up @@ -701,14 +683,12 @@ internal object BitmapUtils {
* Decode image from uri using "inJustDecodeBounds" to get the image dimensions.
*/
@Throws(FileNotFoundException::class)
private fun decodeImageForOption(resolver: ContentResolver, uri: Uri): BitmapFactory.Options {
return resolver.openInputStream(uri).use {
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeStream(it, EMPTY_RECT, options)
options.inJustDecodeBounds = false
options
}
private fun decodeImageForOption(resolver: ContentResolver, uri: Uri): BitmapFactory.Options = resolver.openInputStream(uri).use {
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeStream(it, EMPTY_RECT, options)
options.inJustDecodeBounds = false
options
}

/**
Expand Down Expand Up @@ -888,22 +868,20 @@ internal object BitmapUtils {
degrees: Int,
flipHorizontally: Boolean,
flipVertically: Boolean,
): Bitmap {
return if (degrees > 0 || flipHorizontally || flipVertically) {
val matrix = Matrix()
matrix.setRotate(degrees.toFloat())
matrix.postScale(
(if (flipHorizontally) -1 else 1).toFloat(),
(if (flipVertically) -1 else 1).toFloat(),
)
val newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, false)
if (newBitmap != bitmap) {
bitmap.recycle()
}
newBitmap
} else {
bitmap
): Bitmap = if (degrees > 0 || flipHorizontally || flipVertically) {
val matrix = Matrix()
matrix.setRotate(degrees.toFloat())
matrix.postScale(
(if (flipHorizontally) -1 else 1).toFloat(),
(if (flipVertically) -1 else 1).toFloat(),
)
val newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, false)
if (newBitmap != bitmap) {
bitmap.recycle()
}
newBitmap
} else {
bitmap
}
// Only need to check for width since opengl textures are always squared
// Keep track of the maximum texture size
Expand Down
4 changes: 3 additions & 1 deletion cropper/src/main/kotlin/com/canhub/cropper/CropImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ object CropImage {
/**
* Result data of Crop Image Activity.
*/
open class ActivityResult : CropResult, Parcelable {
open class ActivityResult :
CropResult,
Parcelable {

constructor(
originalUri: Uri?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import com.canhub.cropper.databinding.CropImageActivityBinding
import com.canhub.cropper.utils.getUriForFile
import java.io.File

open class CropImageActivity : AppCompatActivity(), OnSetImageUriCompleteListener, OnCropImageCompleteListener {
open class CropImageActivity :
AppCompatActivity(),
OnSetImageUriCompleteListener,
OnCropImageCompleteListener {

/** Persist URI image to crop URI if specific permissions are required. */
private var cropImageUri: Uri? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import android.widget.ImageView
internal class CropImageAnimation(
private val imageView: ImageView,
private val cropOverlayView: CropOverlayView,
) : Animation(), AnimationListener {
) : Animation(),
AnimationListener {

private val startBoundPoints = FloatArray(8)
private val endBoundPoints = FloatArray(8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ internal class CropImageIntentChooser(
* See [StackOverflow
* question](http://stackoverflow.com/questions/32789027/android-m-camera-intent-permission-bug).
*/
private fun isExplicitCameraPermissionRequired(context: Context): Boolean {
return SDK_INT >= Build.VERSION_CODES.M &&
hasCameraPermissionInManifest(context) &&
context.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
}
private fun isExplicitCameraPermissionRequired(context: Context): Boolean = SDK_INT >= Build.VERSION_CODES.M &&
hasCameraPermissionInManifest(context) &&
context.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED

/**
* Check if the app requests a specific permission in the manifest.
Expand Down
17 changes: 8 additions & 9 deletions cropper/src/main/kotlin/com/canhub/cropper/CropImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import kotlin.math.sqrt
class CropImageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
) : FrameLayout(context, attrs), CropWindowChangeListener {
) : FrameLayout(context, attrs),
CropWindowChangeListener {

/** Image view widget used to show the image for cropping. */
private val imageView: ImageView
Expand Down Expand Up @@ -1756,15 +1757,13 @@ class CropImageView @JvmOverloads constructor(
*
* [context] used to retrieve the bitmap in case you need from activity result
*/
fun getBitmap(context: Context): Bitmap? {
return bitmap ?: try {
when {
SDK_INT >= 28 -> ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uriContent!!))
else -> @Suppress("DEPRECATION") MediaStore.Images.Media.getBitmap(context.contentResolver, uriContent)
}
} catch (e: Exception) {
null
fun getBitmap(context: Context): Bitmap? = bitmap ?: try {
when {
SDK_INT >= 28 -> ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uriContent!!))
else -> @Suppress("DEPRECATION") MediaStore.Images.Media.getBitmap(context.contentResolver, uriContent)
}
} catch (e: Exception) {
null
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ class ContractTestFragment(
cropImage.launch(input)
}

fun cropImageIntent(input: CropImageContractOptions): Intent {
return cropImage.contract.createIntent(requireContext(), input)
}
fun cropImageIntent(input: CropImageContractOptions): Intent = cropImage.contract.createIntent(requireContext(), input)
}
36 changes: 18 additions & 18 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
[versions]
minSdk = "21"
compileSdk = "33"
targetSdk = "33"
compileSdk = "34"
targetSdk = "34"

androidgradleplugin = "8.0.2"
kotlin = "1.8.22"
kotlinxcoroutines = "1.7.2"
ktlint = "0.50.0"
androidgradleplugin = "8.4.0"
kotlin = "1.9.24"
kotlinxcoroutines = "1.8.1"
ktlint = "1.2.1"

[libraries]
androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version = "1.7.2" }
androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version = "1.9.0" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version = "1.6.1" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version = "1.9.0" }
androidx-exifinterface = { module = "androidx.exifinterface:exifinterface", version = "1.3.6" }
androidx-fragment-testing = { module = "androidx.fragment:fragment-testing", version = "1.6.0" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version = "1.13.1" }
androidx-exifinterface = { module = "androidx.exifinterface:exifinterface", version = "1.3.7" }
androidx-fragment-testing = { module = "androidx.fragment:fragment-testing", version = "1.7.1" }
androidx-test-junit = { module = "androidx.test.ext:junit", version = "1.1.5" }
junit = { module = "junit:junit", version = "4.13.2" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinxcoroutines" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxcoroutines" }
leakcanary-android = { module = "com.squareup.leakcanary:leakcanary-android", version = "2.12" }
material = { module = "com.google.android.material:material", version = "1.9.0" }
leakcanary-android = { module = "com.squareup.leakcanary:leakcanary-android", version = "2.14" }
material = { module = "com.google.android.material:material", version = "1.12.0" }
mock = { module = "io.mockk:mockk", version = "1.13.5" }
plugin-android-cache-fix = { module = "org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin", version = "2.7.2" }
plugin-android-cache-fix = { module = "org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin", version = "3.0.1" }
plugin-androidgradleplugin = { module = "com.android.tools.build:gradle", version.ref = "androidgradleplugin" }
plugin-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version = "1.8.20" }
plugin-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version = "1.9.20" }
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
plugin-licensee = { module = "app.cash.licensee:licensee-gradle-plugin", version = "1.7.0" }
plugin-paparazzi = { module = "app.cash.paparazzi:paparazzi-gradle-plugin", version = "1.3.0" }
plugin-publish = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.25.3" }
plugin-licensee = { module = "app.cash.licensee:licensee-gradle-plugin", version = "1.11.0" }
plugin-paparazzi = { module = "app.cash.paparazzi:paparazzi-gradle-plugin", version = "1.3.3" }
plugin-publish = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.28.0" }
robolectric = { module = "org.robolectric:robolectric", version = "4.9" }
timber = { module = "com.jakewharton.timber:timber", version = "5.0.1" }

[plugins]
codequalitytools = { id = "com.vanniktech.code.quality.tools", version = "0.23.0" }
codequalitytools = { id = "com.vanniktech.code.quality.tools", version = "0.24.0" }
dependencygraphgenerator = { id = "com.vanniktech.dependency.graph.generator", version = "0.8.0" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Loading

0 comments on commit 37b5a5d

Please sign in to comment.