@@ -15,7 +15,10 @@ import com.google.gson.JsonObject
1515import fisk.chipcloud.ChipCloud
1616import fisk.chipcloud.ChipCloudConfig
1717import java.util.Locale
18+ import kotlinx.coroutines.Dispatchers
19+ import kotlinx.coroutines.isActive
1820import kotlinx.coroutines.launch
21+ import kotlinx.coroutines.withContext
1922import org.ole.planet.myplanet.R
2023import org.ole.planet.myplanet.callback.OnHomeItemClickListener
2124import 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