I’ve a list of objects, lets say, tasks in an app. The
Task object has two member variables (among others, of course) namely isFavorite and isLocked. Each task list-item shows a star icon and a lock icon that can be tapped to toggle between favorite/unfavorite and locked/unlocked. On each tap, the icon changes its color to show whether the task is favorite or locked.
LiveData to get tasks list from Room and populate the
ListAdapter. Now what I’m doing is that on each tap of star or lock icon, I update the database with the new value of isFavorite or isLocked as the case may be, which eventually fires onChanged() of the observer, performs the diffing and changes the UI (icon color) accordingly.
While it all is happening seamlessly, for now at least, I wanted to know if it is the most efficient way of doing this? Should we be communicating with the database this frequently? I mean we are on the one hand, writing new values and on the other, getting a new list each time any of those icons is tapped. Also, the diffing is being performed on the whole list each time. Would the performance be hampered if the list grows in size in future, to let’s say a thousand tasks?