i have recyclerview with room database. and this recyclerview contains Native ads on very 4th position. the problem is when i observe the room data recyclerview automatically refresh Ads position.
Hear is my code viewmodel observer code.
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)
}
}
Please give me any solution.
i have tried paging 3 library for that issue.