Merge pull request #3950 from ByteHamster/feedinfo-page

Feedinfo page improvements
This commit is contained in:
H. Lehmann 2020-03-20 20:15:21 +01:00 committed by GitHub
commit 1cdc8fc33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 15 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);
}
}
}
@ -407,7 +407,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
@Subscribe(threadMode = ThreadMode.MAIN)
public void onFeedListChanged(FeedListUpdateEvent event) {
if (event.contains(feed)) {
refreshHeaderView();
updateUi();
}
}
@ -441,7 +440,8 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
}
private void refreshHeaderView() {
if (recyclerView == null || feed == null || !headerCreated) {
setupHeaderView();
if (recyclerView == null || feed == null) {
Log.e(TAG, "Unable to refresh header view");
return;
}
@ -487,7 +487,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
}
});
headerCreated = true;
refreshHeaderView();
}
private void showFeedInfo() {
@ -528,7 +527,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
feed = result.orElse(null);
setupHeaderView();
refreshHeaderView();
displayList();
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}

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);
}
}
}