我有带有房间数据库的回收视图。此回收视图在第四个位置包含原生广告。问题是当我观察房间数据回收器视图时自动刷新广告位置。
听到的是我的代码视图模型观察者代码。
smsViewModel.getConversation().observe(this@HomeScreenActivity) { conversations ->
clearSelection()
CoroutineScope(Dispatchers.IO).launch {
for (conversation in conversations) {
for (resIds in conversation.recipientsIds) {
val recipients = ArrayList(smsViewModel.getRecipientById(resIds))
CoroutineScope(Dispatchers.Main).launch {
if (recipients.isNotEmpty()) {
Log.i(TAG, "Recipients if: $resIds ${recipients.size}")
conversation.recipients.addAll(recipients)
}else{
Log.i(TAG, "Recipients else: $resIds ${recipients.size}")
}
conversationAdapter.notifyDataSetChanged()
}
}
}
}
val conversationList = when (cat) {
resources.getString(R.string.cat_all) -> {
val sortList =
conversations.sortedWith(compareByDescending<Conversation> { conversation ->
conversation.pinned || !conversation.archived
}.thenByDescending { it.date })
.toMutableList()
getListWithAds(sortList)
}
resources.getString(R.string.cat_personal) -> {
conversations.filter { conversation ->
isMobileNumberWithPlus(conversation.lastMessage!!.address)
}.sortedByDescending { it.date }
}
resources.getString(R.string.cat_transaction) -> {
getConversationType(conversations, 1)
}
resources.getString(R.string.cat_otps) -> {
getConversationType(conversations, 2)
}
resources.getString(R.string.cat_offers) -> {
getConversationType(conversations, 3)
}
resources.getString(R.string.menu_archived) -> {
val sortList = conversations.filter { it.archived }
.sortedWith(compareByDescending<Conversation> { it.archived }
.thenByDescending { it.date })
.toMutableList()
getListWithAds(sortList)
}
else -> {
conversations.sortedByDescending { it.date }
}
}
convList.clear()
convList.addAll(conversationList)
conversationAdapter.notifyDataSetChanged()
updateVisibility(cat)
}
}
请给我任何解决方案。
我已经尝试使用 paging 3 库来解决这个问题。