Skip to content

Commit 49ede44

Browse files
authored
resources: smoother tags realm handling (fixes #8929) (#8914)
1 parent d63a3c9 commit 49ede44

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
applicationId "org.ole.planet.myplanet"
1010
minSdk = 26
1111
targetSdk = 36
12-
versionCode = 3683
13-
versionName = "0.36.83"
12+
versionCode = 3684
13+
versionName = "0.36.84"
1414
ndkVersion = '26.3.11579264'
1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
vectorDrawables.useSupportLibrary = true

app/src/main/java/org/ole/planet/myplanet/ui/resources/AdapterResource.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import com.google.gson.JsonObject
1515
import fisk.chipcloud.ChipCloud
1616
import fisk.chipcloud.ChipCloudConfig
1717
import java.util.Locale
18+
import kotlinx.coroutines.Dispatchers
19+
import kotlinx.coroutines.isActive
1820
import kotlinx.coroutines.launch
21+
import kotlinx.coroutines.withContext
1922
import org.ole.planet.myplanet.R
2023
import org.ole.planet.myplanet.callback.OnHomeItemClickListener
2124
import org.ole.planet.myplanet.callback.OnLibraryItemSelected
@@ -222,18 +225,18 @@ class AdapterResource(
222225
}
223226
lifecycleOwner.lifecycleScope.launch {
224227
try {
225-
val tags = tagRepository.getTagsForResource(resourceId)
228+
val tags = withContext(Dispatchers.IO) {
229+
tagRepository.getTagsForResource(resourceId)
230+
}
226231
tagCache[resourceId] = tags
227232

228-
val flexboxLayout = holder.rowLibraryBinding.flexboxDrawable
229-
holder.itemView.post {
233+
if (isActive) {
230234
val adapterPosition = holder.bindingAdapterPosition
231-
if (adapterPosition == RecyclerView.NO_POSITION) {
232-
return@post
233-
}
234-
val currentResourceId = libraryList.getOrNull(adapterPosition)?.id
235-
if (currentResourceId == resourceId) {
236-
renderTagCloud(flexboxLayout, tags)
235+
if (adapterPosition != RecyclerView.NO_POSITION) {
236+
val currentResourceId = libraryList.getOrNull(adapterPosition)?.id
237+
if (currentResourceId == resourceId) {
238+
renderTagCloud(holder.rowLibraryBinding.flexboxDrawable, tags)
239+
}
237240
}
238241
}
239242
} finally {

0 commit comments

Comments
 (0)