Fixed position sometimes updated in wrong item
This commit is contained in:
parent
60a070b56c
commit
62722b2504
@ -54,7 +54,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
||||
private final boolean showOnlyNewEpisodes;
|
||||
|
||||
private FeedItem selectedItem;
|
||||
private Holder currentlyPlayingItem = null;
|
||||
|
||||
private final int playingBackGroundColor;
|
||||
private final int normalBackGroundColor;
|
||||
@ -172,7 +171,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
||||
|
||||
if (media.isCurrentlyPlaying()) {
|
||||
holder.container.setBackgroundColor(playingBackGroundColor);
|
||||
currentlyPlayingItem = holder;
|
||||
} else {
|
||||
holder.container.setBackgroundColor(normalBackGroundColor);
|
||||
}
|
||||
@ -202,22 +200,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
||||
.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull Holder holder, int pos, List<Object> payload) {
|
||||
onBindViewHolder(holder, pos);
|
||||
|
||||
if (holder == currentlyPlayingItem && payload.size() == 1 && payload.get(0) instanceof PlaybackPositionEvent) {
|
||||
PlaybackPositionEvent event = (PlaybackPositionEvent) payload.get(0);
|
||||
holder.progress.setProgress((int) (100.0 * event.getPosition() / event.getDuration()));
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyCurrentlyPlayingItemChanged(PlaybackPositionEvent event) {
|
||||
if (currentlyPlayingItem != null && currentlyPlayingItem.getAdapterPosition() != RecyclerView.NO_POSITION) {
|
||||
notifyItemChanged(currentlyPlayingItem.getAdapterPosition(), event);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FeedItem getSelectedItem() {
|
||||
return selectedItem;
|
||||
@ -302,6 +284,14 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
||||
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item);
|
||||
}
|
||||
|
||||
public boolean isCurrentlyPlayingItem() {
|
||||
return item.getMedia() != null && item.getMedia().isCurrentlyPlaying();
|
||||
}
|
||||
|
||||
public void notifyPlaybackPositionUpdated(PlaybackPositionEvent event) {
|
||||
progress.setProgress((int) (100.0 * event.getPosition() / event.getDuration()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface ItemAccess {
|
||||
|
@ -61,7 +61,6 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
||||
private boolean locked;
|
||||
|
||||
private FeedItem selectedItem;
|
||||
private ViewHolder currentlyPlayingItem = null;
|
||||
|
||||
private final int playingBackGroundColor;
|
||||
private final int normalBackGroundColor;
|
||||
@ -84,11 +83,13 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.queue_listitem, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int pos) {
|
||||
FeedItem item = itemAccess.getItem(pos);
|
||||
holder.bind(item);
|
||||
@ -98,18 +99,6 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int pos, List<Object> payload) {
|
||||
onBindViewHolder(holder, pos);
|
||||
|
||||
if (holder == currentlyPlayingItem && payload.size() == 1 && payload.get(0) instanceof PlaybackPositionEvent) {
|
||||
PlaybackPositionEvent event = (PlaybackPositionEvent) payload.get(0);
|
||||
holder.progressBar.setProgress((int) (100.0 * event.getPosition() / event.getDuration()));
|
||||
holder.progressLeft.setText(Converter.getDurationStringLong(event.getPosition()));
|
||||
holder.progressRight.setText(Converter.getDurationStringLong(event.getDuration()));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FeedItem getSelectedItem() {
|
||||
return selectedItem;
|
||||
@ -125,12 +114,6 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
||||
return itemAccess.getCount();
|
||||
}
|
||||
|
||||
public void notifyCurrentlyPlayingItemChanged(PlaybackPositionEvent event) {
|
||||
if (currentlyPlayingItem != null && currentlyPlayingItem.getAdapterPosition() != RecyclerView.NO_POSITION) {
|
||||
notifyItemChanged(currentlyPlayingItem.getAdapterPosition(), event);
|
||||
}
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder
|
||||
implements View.OnClickListener,
|
||||
View.OnCreateContextMenuListener,
|
||||
@ -310,7 +293,6 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
||||
|
||||
if(media.isCurrentlyPlaying()) {
|
||||
container.setBackgroundColor(playingBackGroundColor);
|
||||
currentlyPlayingItem = this;
|
||||
} else {
|
||||
container.setBackgroundColor(normalBackGroundColor);
|
||||
}
|
||||
@ -330,6 +312,15 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
||||
.load();
|
||||
}
|
||||
|
||||
public boolean isCurrentlyPlayingItem() {
|
||||
return item.getMedia() != null && item.getMedia().isCurrentlyPlaying();
|
||||
}
|
||||
|
||||
public void notifyPlaybackPositionUpdated(PlaybackPositionEvent event) {
|
||||
progressBar.setProgress((int) (100.0 * event.getPosition() / event.getDuration()));
|
||||
progressLeft.setText(Converter.getDurationStringLong(event.getPosition()));
|
||||
progressRight.setText(Converter.getDurationStringLong(event.getDuration()));
|
||||
}
|
||||
}
|
||||
|
||||
public interface ItemAccess {
|
||||
|
@ -383,7 +383,14 @@ public abstract class EpisodesListFragment extends Fragment {
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(PlaybackPositionEvent event) {
|
||||
if (listAdapter != null) {
|
||||
listAdapter.notifyCurrentlyPlayingItemChanged(event);
|
||||
for (int i = 0; i < listAdapter.getItemCount(); i++) {
|
||||
AllEpisodesRecycleAdapter.Holder holder = (AllEpisodesRecycleAdapter.Holder)
|
||||
recyclerView.findViewHolderForAdapterPosition(i);
|
||||
if (holder != null && holder.isCurrentlyPlayingItem()) {
|
||||
holder.notifyPlaybackPositionUpdated(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,14 @@ public class QueueFragment extends Fragment {
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(PlaybackPositionEvent event) {
|
||||
if (recyclerAdapter != null) {
|
||||
recyclerAdapter.notifyCurrentlyPlayingItemChanged(event);
|
||||
for (int i = 0; i < recyclerAdapter.getItemCount(); i++) {
|
||||
QueueRecyclerAdapter.ViewHolder holder = (QueueRecyclerAdapter.ViewHolder)
|
||||
recyclerView.findViewHolderForAdapterPosition(i);
|
||||
if (holder != null && holder.isCurrentlyPlayingItem()) {
|
||||
holder.notifyPlaybackPositionUpdated(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user