I am using liveData in my application. I do a DB Query which returns a LiveData<PagedList<Contact>>
of contacts stored in DB.
I want to modify this livedata before giving it to observers. Suppose there are ten contacts in the LiveData list, i want to do some comparison with another list and set which contacts are primary in the LiveData list.
After doing this i want to give it to observers .
e.g -
val allContacts: LiveData<PagedList<Contact>> = getFromDB()
val list: ArrayList<String>() = list of some primary contacts
traverse allContacts
and list
and set which values in allContacts
match the values in list
.
which ever values in allContacts
match, their isPrimary
property will be set to true.
Now after modifying allContacts
, i want to submit it to observers like:
allContacts.observe(this, Observer(adapter::submitList))
I tried LiveData.transform, But not able to use it properly.Can anyone suggest me how to achieve it using transform method or some other way.