https://kotlinlang.org logo
Title
s

Smith

04/26/2020, 7:05 PM
PLEASE HELPP (StackOverflow does not have the answer) So i have a list(recycler view) of items which is loaded from a local db using room and pagination. Also i have used livedata for pagination. Now whenever i click an item, I want to highlight the text in it and save it to the database. But since this causes a change in the table, room triggers the livedata callback and the list is refreshed. So the problem is whenever i click “highlight text”, the list is refreshed and recycler view animation is fired leading to a bad ux. I want to avoid the room callback whenever i update the isHighlighted flag in the db. Also i want to keep using the pagination which uses live data observer, so i cannot remove the observer after the list is loaded.
:stackoverflow: 5
k

Kamil Kalisz

04/27/2020, 4:26 AM
I don’t know implementation details. But using DiffUtils to calculate change-set between list updates should help you. Check https://developer.android.com/reference/android/arch/paging/AsyncPagedListDiffer
t

ti4n

04/27/2020, 6:36 AM
You can disable the default animation
a

Antonio

04/27/2020, 7:43 AM
Create a new Room Entity containing itemId and isHighlighted: Boolean or text: String to store the values if item is highlighted. Then to retrieve values, use JOIN query in the DAO interface.
s

Smith

04/27/2020, 7:46 AM
@Antonio Yes that is exactly what I thought, but was an overkill to just highlight an item.. so I asked for help here. But I think that's the only decent way go about this.
👍 1