The move animation laggs if the item's view is being updated simultaneously. Why is this happening?
fileViewModel.getAllfiles().observe(this, new Observer<List<File>>() {
@Override
public void onChanged(List<File> files) {
adapter.submitList(files);
}
});
Progress being update like this, which updates the database and triggers the observer
executor = Executors.newFixedThreadPool(1);
executor.execute(() -> {
fileRecycler.post(new Runnable() {
@Override
public void run () {
fileViewModel.setDownloadProgress(file.getFileId(), percentage);
}
});
});
Only the move animation of the item with the download progress being updated laggs. It moves as there is time between the updates, and completely stalls if the updates are frequent enough until they are done.
If i remove the holder.view.determinateBar.setProgress(file.getDownloadProgress(), true); from the ViewHolder there is no lagg in the movement.
It seems that you are replacing the entire list of files whenever there is a change occuring. This practice is not recommended as it increases the time complexity.
You should instead notifying the RecyclerView adaptor only for the actual change that occurs. In your case you're changing only one item.
Reference from the official docs and best practices: https://developer.android.com/topic/performance/vitals/render#recyclerview_notifydatasetchanged