Fixed item flickering while downloading

This commit is contained in:
ByteHamster 2020-03-20 19:54:55 +01:00
parent 8e10b986b2
commit 1f4801b3b2
7 changed files with 24 additions and 11 deletions

View File

@ -68,6 +68,19 @@ public class EpisodeItemListAdapter extends RecyclerView.Adapter<EpisodeItemView
holder.hideSeparatorIfNecessary();
}
/**
* {@link #notifyItemChanged(int)} is final, so we can not override.
* Calling {@link #notifyItemChanged(int)} may bind the item to a new ViewHolder and execute a transition.
* This causes flickering and breaks the download animation that stores the old progress in the View.
* Instead, we tell the adapter to use partial binding by calling {@link #notifyItemChanged(int, Object)}.
* We actually ignore the payload and always do a full bind but calling the partial bind method ensures
* that ViewHolders are always re-used.
* @param position Position of the item that has changed
*/
public void notifyItemChangedCompat(int position) {
notifyItemChanged(position, "foo");
}
@Nullable
public FeedItem getSelectedItem() {
return selectedItem;

View File

@ -151,7 +151,7 @@ public class CompletedDownloadsFragment extends Fragment {
items.remove(pos);
if (item.getMedia().isDownloaded()) {
items.add(pos, item);
adapter.notifyItemChanged(pos);
adapter.notifyItemChangedCompat(pos);
} else {
adapter.notifyItemRemoved(pos);
}

View File

@ -358,7 +358,7 @@ public abstract class EpisodesListFragment extends Fragment {
episodes.remove(pos);
if (shouldUpdatedItemRemainInList(item)) {
episodes.add(pos, item);
listAdapter.notifyItemChanged(pos);
listAdapter.notifyItemChangedCompat(pos);
} else {
listAdapter.notifyItemRemoved(pos);
}
@ -394,7 +394,7 @@ public abstract class EpisodesListFragment extends Fragment {
for (long mediaId : update.mediaIds) {
int pos = FeedItemUtil.indexOfItemWithMediaId(episodes, mediaId);
if (pos >= 0) {
listAdapter.notifyItemChanged(pos);
listAdapter.notifyItemChangedCompat(pos);
}
}
}

View File

@ -354,7 +354,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
if (pos >= 0) {
feed.getItems().remove(pos);
feed.getItems().add(pos, item);
adapter.notifyItemChanged(pos);
adapter.notifyItemChangedCompat(pos);
}
}
}
@ -370,7 +370,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
for (long mediaId : update.mediaIds) {
int pos = FeedItemUtil.indexOfItemWithMediaId(feed.getItems(), mediaId);
if (pos >= 0) {
adapter.notifyItemChanged(pos);
adapter.notifyItemChangedCompat(pos);
}
}
}

View File

@ -115,7 +115,7 @@ public class PlaybackHistoryFragment extends Fragment {
if (pos >= 0) {
playbackHistory.remove(pos);
playbackHistory.add(pos, item);
adapter.notifyItemChanged(pos);
adapter.notifyItemChangedCompat(pos);
}
}
}
@ -128,7 +128,7 @@ public class PlaybackHistoryFragment extends Fragment {
for (long mediaId : update.mediaIds) {
int pos = FeedItemUtil.indexOfItemWithMediaId(playbackHistory, mediaId);
if (pos >= 0) {
adapter.notifyItemChanged(pos);
adapter.notifyItemChangedCompat(pos);
}
}
}

View File

@ -178,7 +178,7 @@ public class QueueFragment extends Fragment {
if (pos >= 0) {
queue.remove(pos);
queue.add(pos, item);
recyclerAdapter.notifyItemChanged(pos);
recyclerAdapter.notifyItemChangedCompat(pos);
refreshInfoBar();
}
}
@ -195,7 +195,7 @@ public class QueueFragment extends Fragment {
for (long mediaId : update.mediaIds) {
int pos = FeedItemUtil.indexOfItemWithMediaId(queue, mediaId);
if (pos >= 0) {
recyclerAdapter.notifyItemChanged(pos);
recyclerAdapter.notifyItemChangedCompat(pos);
}
}
}

View File

@ -215,7 +215,7 @@ public class SearchFragment extends Fragment {
if (pos >= 0) {
results.remove(pos);
results.add(pos, item);
adapter.notifyItemChanged(pos);
adapter.notifyItemChangedCompat(pos);
}
}
}
@ -228,7 +228,7 @@ public class SearchFragment extends Fragment {
for (long mediaId : update.mediaIds) {
int pos = FeedItemUtil.indexOfItemWithMediaId(results, mediaId);
if (pos >= 0) {
adapter.notifyItemChanged(pos);
adapter.notifyItemChangedCompat(pos);
}
}
}