private val _cat = MutableLiveData>() fun updateCat(new: Cat) { val currentCats = _cat.value ?: return val updatedCats = currentCats.toMutableList() .map { old -> if(old.id == new.id) new else old } _cat.postValue(updatedCats) // update storage and web service ... }
private val _cat = MutableLiveData>() fun updateCat(new: Cat) { val currentCats = _cat.value ?: return val updatedCats = currentCats.toMutableList() .map { old -> if(old.id == new.id) new else old } _cat.postValue(updatedCats) // update storage and web service ... }
private val _cat = MutableLiveData>() fun updateCat(new: Cat) { val currentCats = _cat.value ?: return val updatedCats = currentCats.toMutableList() .map { old -> if(old.id == new.id) new else old } _cat.postValue(updatedCats) // update storage and web service ... }
@Entity data class Cat( @PrimaryKey(autoGenerate = true) val id: Int = 0, val name: String, val age: Int, val description: String, val loved: Boolean )
Repository ViewModel Activity / Fragment What do I display? I need cats Give us ALL Cats OK, 1,000,000 cats here. Here you are Show this 1,000,000 cats ¯\_(π)_/¯
public abstract class PagedListAdapter ... { final AsyncPagedListDiffer mDiffer; @Nullable protected T getItem(int position) { return mDiffer.getItem(position); } }