Skip to content

Commit

Permalink
Update dependency com.diffplug.spotless:spotless-plugin-gradle to v6.…
Browse files Browse the repository at this point in the history
…19.0 (#2371)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: John Rodriguez <jrod@squareup.com>
  • Loading branch information
renovate[bot] and jrodbx committed May 30, 2023
1 parent fc4d1cb commit 7091672
Show file tree
Hide file tree
Showing 26 changed files with 120 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ trim_trailing_whitespace = true
insert_final_newline = true

[*.{kt,kts}]
ij_kotlin_imports_layout=*
ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,kotlinx.**,^
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
classpath libs.plugin.kotlin
classpath 'com.github.ben-manes:gradle-versions-plugin:0.46.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.25.2'
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.3.0'
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.18.0'
classpath 'org.jetbrains.kotlinx:binary-compatibility-validator:0.13.1'
}
}
Expand Down Expand Up @@ -66,11 +66,13 @@ subprojects {
target('**/*.kt')
licenseHeaderFile(rootProject.file('gradle/license-header.txt'))
// Spotless doesn't read .editorconfig yet: https://github.com/diffplug/spotless/issues/142
ktlint('0.41.0').userData([
ktlint('0.46.1').editorConfigOverride([
'insert_final_newline': 'true',
'end_of_line': 'lf',
'charset': 'utf-8',
'indent_size': '2',
'trim_trailing_whitespace': 'true',
'ij_kotlin_imports_layout': '*,java.**,javax.**,kotlin.**,kotlinx.**,^'
])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.squareup.picasso3.RequestCreator
fun Picasso.rememberPainter(
key: Any? = null,
onError: ((Exception) -> Unit)? = null,
request: (Picasso) -> RequestCreator,
request: (Picasso) -> RequestCreator
): Painter {
return remember(key) { PicassoPainter(this, request, onError) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ class PollexorRequestTransformerTest {
private val transformer = PollexorRequestTransformer(Thumbor.create(HOST))
private val secureTransformer = PollexorRequestTransformer(Thumbor.create(HOST, KEY))
private val alwaysResizeTransformer = PollexorRequestTransformer(
Thumbor.create(HOST), alwaysTransform = true
Thumbor.create(HOST),
alwaysTransform = true
)
private val callbackTransformer = PollexorRequestTransformer(
Thumbor.create(HOST), callback = { it.filter("custom") }
Thumbor.create(HOST),
callback = { it.filter("custom") }
)

@Test fun resourceIdRequestsAreNotTransformed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ internal class PicassoSampleAdapter(context: Context?) : BaseAdapter() {
): View {
val view = if (convertView == null) {
inflater.inflate(R.layout.picasso_sample_activity_item, parent, false) as TextView
} else
} else {
convertView as TextView
}

view.text = getItem(position).label
return view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ fun ImageGrid(
urls: List<String>,
contentScale: ContentScale,
alignment: Alignment,
picasso: Picasso = PicassoInitializer.get(),
picasso: Picasso = PicassoInitializer.get()
) {
LazyVerticalGrid(
columns = Adaptive(150.dp),
modifier = modifier,
modifier = modifier
) {
items(urls.size) {
val url = urls[it]
Expand Down Expand Up @@ -166,6 +166,7 @@ fun Options(
}
}
}

@Composable
private fun OptionText(modifier: Modifier, key: String, selected: Boolean, onClick: () -> Unit) {
Box(modifier = modifier) {
Expand All @@ -188,7 +189,7 @@ private val CONTENT_SCALES = mapOf(
Pair("Fill Width", ContentScale.FillWidth),
Pair("Fill Height", ContentScale.FillHeight),
Pair("Fill Bounds", ContentScale.FillBounds),
Pair("None", ContentScale.None),
Pair("None", ContentScale.None)
)

private val ALIGNMENTS = mapOf(
Expand Down
3 changes: 2 additions & 1 deletion picasso/src/main/java/com/squareup/picasso3/BitmapHunter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ internal open class BitmapHunter(
} catch (e: RuntimeException) {
Picasso.HANDLER.post {
throw RuntimeException(
"Transformation ${transformation.key()} crashed with exception.", e
"Transformation ${transformation.key()} crashed with exception.",
e
)
}

Expand Down
17 changes: 12 additions & 5 deletions picasso/src/main/java/com/squareup/picasso3/BitmapUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ internal object BitmapUtils {
request: Request
) {
calculateInSampleSize(
reqWidth, reqHeight, options.outWidth, options.outHeight, options, request
reqWidth,
reqHeight,
options.outWidth,
options.outHeight,
options,
request
)
}

Expand Down Expand Up @@ -101,10 +106,11 @@ internal object BitmapUtils {
val exceptionCatchingSource = ExceptionCatchingSource(source)
val bufferedSource = exceptionCatchingSource.buffer()
val bitmap =
if (VERSION.SDK_INT >= 28)
if (VERSION.SDK_INT >= 28) {
decodeStreamP(request, bufferedSource)
else
} else {
decodeStreamPreP(request, bufferedSource)
}
exceptionCatchingSource.throwIfCaught()
return bitmap
}
Expand Down Expand Up @@ -201,10 +207,11 @@ internal object BitmapUtils {
} else {
val heightRatio = height / requestHeight
val widthRatio = width / requestWidth
if (request.centerInside)
if (request.centerInside) {
max(heightRatio, widthRatio)
else
} else {
min(heightRatio, widthRatio)
}
}
if (ratio != 0) ratio else 1
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ internal class ContactsPhotoRequestHandler(private val context: Context) : Reque
companion object {
/** A lookup uri (e.g. content://com.android.contacts/contacts/lookup/3570i61d948d30808e537) */
private const val ID_LOOKUP = 1

/** A contact thumbnail uri (e.g. content://com.android.contacts/contacts/38/photo) */
private const val ID_THUMBNAIL = 2

/** A contact uri (e.g. content://com.android.contacts/contacts/38) */
private const val ID_CONTACT = 3

/**
* A contact display photo (high resolution) uri
* (e.g. content://com.android.contacts/display_photo/5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ internal open class ContentStreamRequestHandler(val context: Context) : RequestH
request: Request,
callback: Callback
) {

var signaledCallback = false
try {
val requestUri = checkNotNull(request.uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ internal class MediaStoreRequestHandler(context: Context) : ContentStreamRequest
options.inJustDecodeBounds = true

calculateInSampleSize(
request.targetWidth, request.targetHeight, picassoKind.width,
picassoKind.height, options, request
request.targetWidth,
request.targetHeight,
picassoKind.width,
picassoKind.height,
options,
request
)

val bitmap = if (isVideo) {
Expand Down
2 changes: 2 additions & 0 deletions picasso/src/main/java/com/squareup/picasso3/NetworkPolicy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ enum class NetworkPolicy(val index: Int) {
* Skips checking the disk cache and forces loading through the network.
*/
NO_CACHE(1 shl 0),

/**
* Skips storing the result into the disk cache.
*/
NO_STORE(1 shl 1),

/**
* Forces the request through the disk cache only, skipping network.
*/
Expand Down
1 change: 1 addition & 0 deletions picasso/src/main/java/com/squareup/picasso3/Picasso.kt
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ class Picasso internal constructor(
enum class Priority {
LOW,
NORMAL,

/**
* High priority requests will post to the front of main thread's message queue when
* they complete loading and their images need to be rendered.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class PicassoExecutorService(
threadCount: Int = DEFAULT_THREAD_COUNT,
threadFactory: ThreadFactory = PicassoThreadFactory()
) : ThreadPoolExecutor(
threadCount, threadCount, 0, MILLISECONDS, PriorityBlockingQueue(), threadFactory
threadCount,
threadCount,
0,
MILLISECONDS,
PriorityBlockingQueue(),
threadFactory
) {
override fun submit(task: Runnable): Future<*> {
val ftask = PicassoFutureTask(task as BitmapHunter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ internal abstract class RemoteViewsAction(
) : RemoteViewsAction(picasso, data, errorResId, target, callback) {
override fun update() {
val manager = ContextCompat.getSystemService(
picasso.context, NotificationManager::class.java
picasso.context,
NotificationManager::class.java
)
manager?.notify(notificationTag, notificationId, notification)
}
Expand Down
1 change: 1 addition & 0 deletions picasso/src/main/java/com/squareup/picasso3/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class Request internal constructor(builder: Builder) {
var transformations: MutableList<Transformation>? = null
var config: Config? = null
var priority: Priority? = null

/** Internal use only. Used by [DeferredRequestCreator]. */
var tag: Any? = null
var memoryPolicy = 0
Expand Down
15 changes: 9 additions & 6 deletions picasso/src/main/java/com/squareup/picasso3/RequestCreator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class RequestCreator internal constructor(
private var noFade = false
private var deferred = false
private var setPlaceholder = true

@DrawableRes private var placeholderResId = 0

@DrawableRes private var errorResId = 0
private var placeholderDrawable: Drawable? = null
private var errorDrawable: Drawable? = null
Expand Down Expand Up @@ -179,7 +181,7 @@ class RequestCreator internal constructor(
*/
fun resizeDimen(
@DimenRes targetWidthResId: Int,
@DimenRes targetHeightResId: Int,
@DimenRes targetHeightResId: Int
): RequestCreator {
val resources = picasso.context.resources
val targetWidth = resources.getDimensionPixelSize(targetWidthResId)
Expand Down Expand Up @@ -306,7 +308,7 @@ class RequestCreator internal constructor(
*/
fun memoryPolicy(
policy: MemoryPolicy,
vararg additional: MemoryPolicy,
vararg additional: MemoryPolicy
): RequestCreator {
data.memoryPolicy(policy, *additional)
return this
Expand All @@ -318,7 +320,7 @@ class RequestCreator internal constructor(
*/
fun networkPolicy(
policy: NetworkPolicy,
vararg additional: NetworkPolicy,
vararg additional: NetworkPolicy
): RequestCreator {
data.networkPolicy(policy, *additional)
return this
Expand Down Expand Up @@ -362,6 +364,7 @@ class RequestCreator internal constructor(

return bitmap
}

/**
* Asynchronously fulfills the request without a [ImageView] or [BitmapTarget],
* and invokes the target [Callback] with the result. This is useful when you want to warm
Expand Down Expand Up @@ -501,7 +504,7 @@ class RequestCreator internal constructor(
notificationId: Int,
notification: Notification,
notificationTag: String? = null,
callback: Callback? = null,
callback: Callback? = null
) {
val started = System.nanoTime()
check(!deferred) { "Fit cannot be used with RemoteViews." }
Expand Down Expand Up @@ -531,7 +534,7 @@ class RequestCreator internal constructor(
remoteViews: RemoteViews,
@IdRes viewId: Int,
appWidgetId: Int,
callback: Callback? = null,
callback: Callback? = null
) {
into(remoteViews, viewId, intArrayOf(appWidgetId), callback)
}
Expand All @@ -545,7 +548,7 @@ class RequestCreator internal constructor(
remoteViews: RemoteViews,
@IdRes viewId: Int,
appWidgetIds: IntArray,
callback: Callback? = null,
callback: Callback? = null
) {
val started = System.nanoTime()
check(!deferred) { "Fit cannot be used with remote views." }
Expand Down
15 changes: 12 additions & 3 deletions picasso/src/test/java/com/squareup/picasso3/BitmapHunterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations.initMocks
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
Expand All @@ -87,6 +87,7 @@ import java.util.concurrent.FutureTask
@RunWith(RobolectricTestRunner::class)
class BitmapHunterTest {
@Mock internal lateinit var context: Context

@Mock internal lateinit var dispatcher: Dispatcher
private lateinit var picasso: Picasso

Expand Down Expand Up @@ -123,7 +124,12 @@ class BitmapHunterTest {
@Test fun responseExceptionDispatchFailed() {
val action = mockAction(picasso, URI_KEY_1, URI_1)
val hunter = TestableBitmapHunter(
picasso, dispatcher, cache, action, null, ResponseException(504, 0)
picasso,
dispatcher,
cache,
action,
null,
ResponseException(504, 0)
)
hunter.run()
verify(dispatcher).dispatchFailed(hunter)
Expand Down Expand Up @@ -1039,7 +1045,10 @@ class BitmapHunterTest {
shouldRetry: Boolean = false,
supportsReplay: Boolean = false
) : BitmapHunter(
picasso, dispatcher, cache, action,
picasso,
dispatcher,
cache,
action,
TestableRequestHandler(result, exception, shouldRetry, supportsReplay)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import com.squareup.picasso3.TestUtils.mockPicasso
import org.junit.Assert.fail
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import com.squareup.picasso3.TestUtils.mockPicasso
import com.squareup.picasso3.TestUtils.mockRequestCreator
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.`when`
import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyNoMoreInteractions
import org.mockito.Mockito.`when`
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment

Expand Down
Loading

0 comments on commit 7091672

Please sign in to comment.