Closed lelexdrugo closed 2 years ago
Slide 28 & 29 from a07-lists_adapters
https://medium.com/android-news/smart-way-to-update-recyclerview-using-diffutil-345941a160e0
It seems like the diffs have to be calculated in the set method of the adpater.
This method change the initial setted value (the list of data that fill the recycler view). Until now we never change this value: because we destroy and recreate a noe recycler view each time a chnage in the observed variable occured. Choose which way to follow and dispatchUpdate for animation accordingly
For example in the TimeSlotListBySkillFragment
timeSlotListBySkillViewModel.advList.observe(this.viewLifecycleOwner){
if (it.isEmpty()) {
recyclerViewAdv.visibility = View.GONE
emptyAdvText.visibility = View.VISIBLE
} else {
recyclerViewAdv.visibility = View.VISIBLE
emptyAdvText.visibility = View.GONE
}
val adapter = AdvertisementAdapter(it, timeSlotDetailsViewModel, true)
recyclerViewAdv.adapter = adapter
}
If we create the adapter before and when the observer is triggered we only call the adapter.setSkills(it) I think that it will works
Implement the animation that give user hint when changes are retrived from firestore. Use something like this
"Implementiamo una classe che estenda DiffUtil.Callback per far sì di avere le animazioni. Bisogna calcolare la differenza fra le due liste (la vecchia e la nuova ottenuta dal db) tramite l'algoritmo di Myers"
So, creating listener (TimeSlotListBySkillViewModel -> setAdvertisementsBySkill and TimeSlotListViewModel -> getAdvertisementList) we have also to calculate diffs using the old value contained in the ViewModel (mAdvList) and the new one (advertisements)