refactor: Destructure maps for more idiomatic code (#388)

This commit is contained in:
Nik Clayton 2024-01-26 12:32:45 +01:00 committed by GitHub
parent fc81e8bad7
commit 355244a8e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 16 deletions

View File

@ -156,8 +156,8 @@ class EditFilterActivity : BaseActivity() {
} }
lifecycleScope.launch { lifecycleScope.launch {
viewModel.contexts.collect { contexts -> viewModel.contexts.collect { contexts ->
for (entry in contextSwitches) { for ((key, value) in contextSwitches) {
entry.key.isChecked = contexts.contains(entry.value) key.isChecked = contexts.contains(value)
} }
} }
} }

View File

@ -213,9 +213,9 @@ class ClickableSpanTextView @JvmOverloads constructor(
val y = event.y val y = event.y
// If the user has clicked directly on a span then use it, ignoring any overlap // If the user has clicked directly on a span then use it, ignoring any overlap
for (entry in spanRects) { for ((rect, span) in spanRects) {
if (!entry.key.contains(x, y)) continue if (!rect.contains(x, y)) continue
clickedSpan = entry.value clickedSpan = span
Timber.v("span click: ${(clickedSpan as URLSpan).url}") Timber.v("span click: ${(clickedSpan as URLSpan).url}")
return super.onTouchEvent(event) return super.onTouchEvent(event)
} }
@ -354,12 +354,12 @@ class ClickableSpanTextView @JvmOverloads constructor(
// showSpanBoundaries is false. // showSpanBoundaries is false.
if (BuildConfig.DEBUG && showSpanBoundaries) { if (BuildConfig.DEBUG && showSpanBoundaries) {
canvas.save() canvas.save()
for (entry in delegateRects) { for (rect in delegateRects.keys) {
canvas.drawRect(entry.key, paddingDebugPaint) canvas.drawRect(rect, paddingDebugPaint)
} }
for (entry in spanRects) { for (rect in spanRects.keys) {
canvas.drawRect(entry.key, spanDebugPaint) canvas.drawRect(rect, spanDebugPaint)
} }
canvas.restore() canvas.restore()
} }

View File

@ -305,11 +305,11 @@ class ServerVersionTest() {
.that(serverVersions.size) .that(serverVersions.size)
.isGreaterThan(5) .isGreaterThan(5)
for (entry in serverVersions.entries) { for ((name, versions) in serverVersions.entries) {
for (version in entry.value) { for (version in versions) {
val serverKind = ServerKind.from( val serverKind = ServerKind.from(
NodeInfo.Software( NodeInfo.Software(
name = entry.key, name = name,
version = version, version = version,
), ),
) )
@ -323,7 +323,7 @@ class ServerVersionTest() {
version, version,
) )
assertWithMessage("${entry.key} : $version") assertWithMessage("$name : $version")
.that(result) .that(result)
.isInstanceOf(Ok::class.java) .isInstanceOf(Ok::class.java)
} }

View File

@ -123,9 +123,9 @@ class InMemorySharedPreferences(
listeners.forEach { it.onSharedPreferenceChanged(sharedPreferences, key) } listeners.forEach { it.onSharedPreferenceChanged(sharedPreferences, key) }
} }
edits.forEach { entry -> edits.forEach { (key, value) ->
store[entry.key] = entry.value store[key] = value
listeners.forEach { it.onSharedPreferenceChanged(sharedPreferences, entry.key) } listeners.forEach { it.onSharedPreferenceChanged(sharedPreferences, key) }
} }
deletes.clear() deletes.clear()