Merge pull request #3600 from ByteHamster/fix-currently-playing-update
Fixed position sometimes updated in wrong item
This commit is contained in:
commit
36a1842659
@ -54,7 +54,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
|||||||
private final boolean showOnlyNewEpisodes;
|
private final boolean showOnlyNewEpisodes;
|
||||||
|
|
||||||
private FeedItem selectedItem;
|
private FeedItem selectedItem;
|
||||||
private Holder currentlyPlayingItem = null;
|
|
||||||
|
|
||||||
private final int playingBackGroundColor;
|
private final int playingBackGroundColor;
|
||||||
private final int normalBackGroundColor;
|
private final int normalBackGroundColor;
|
||||||
@ -172,7 +171,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
|||||||
|
|
||||||
if (media.isCurrentlyPlaying()) {
|
if (media.isCurrentlyPlaying()) {
|
||||||
holder.container.setBackgroundColor(playingBackGroundColor);
|
holder.container.setBackgroundColor(playingBackGroundColor);
|
||||||
currentlyPlayingItem = holder;
|
|
||||||
} else {
|
} else {
|
||||||
holder.container.setBackgroundColor(normalBackGroundColor);
|
holder.container.setBackgroundColor(normalBackGroundColor);
|
||||||
}
|
}
|
||||||
@ -202,22 +200,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
|||||||
.load();
|
.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
|
@Nullable
|
||||||
public FeedItem getSelectedItem() {
|
public FeedItem getSelectedItem() {
|
||||||
return selectedItem;
|
return selectedItem;
|
||||||
@ -302,6 +284,14 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
|||||||
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item);
|
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 {
|
public interface ItemAccess {
|
||||||
|
@ -61,7 +61,6 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
|||||||
private boolean locked;
|
private boolean locked;
|
||||||
|
|
||||||
private FeedItem selectedItem;
|
private FeedItem selectedItem;
|
||||||
private ViewHolder currentlyPlayingItem = null;
|
|
||||||
|
|
||||||
private final int playingBackGroundColor;
|
private final int playingBackGroundColor;
|
||||||
private final int normalBackGroundColor;
|
private final int normalBackGroundColor;
|
||||||
@ -84,11 +83,13 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
|||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.queue_listitem, parent, false);
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.queue_listitem, parent, false);
|
||||||
return new ViewHolder(view);
|
return new ViewHolder(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder holder, int pos) {
|
public void onBindViewHolder(ViewHolder holder, int pos) {
|
||||||
FeedItem item = itemAccess.getItem(pos);
|
FeedItem item = itemAccess.getItem(pos);
|
||||||
holder.bind(item);
|
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
|
@Nullable
|
||||||
public FeedItem getSelectedItem() {
|
public FeedItem getSelectedItem() {
|
||||||
return selectedItem;
|
return selectedItem;
|
||||||
@ -125,12 +114,6 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
|||||||
return itemAccess.getCount();
|
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
|
public class ViewHolder extends RecyclerView.ViewHolder
|
||||||
implements View.OnClickListener,
|
implements View.OnClickListener,
|
||||||
View.OnCreateContextMenuListener,
|
View.OnCreateContextMenuListener,
|
||||||
@ -310,7 +293,6 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
|||||||
|
|
||||||
if(media.isCurrentlyPlaying()) {
|
if(media.isCurrentlyPlaying()) {
|
||||||
container.setBackgroundColor(playingBackGroundColor);
|
container.setBackgroundColor(playingBackGroundColor);
|
||||||
currentlyPlayingItem = this;
|
|
||||||
} else {
|
} else {
|
||||||
container.setBackgroundColor(normalBackGroundColor);
|
container.setBackgroundColor(normalBackGroundColor);
|
||||||
}
|
}
|
||||||
@ -330,6 +312,15 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
|||||||
.load();
|
.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 {
|
public interface ItemAccess {
|
||||||
|
@ -383,7 +383,14 @@ public abstract class EpisodesListFragment extends Fragment {
|
|||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void onEventMainThread(PlaybackPositionEvent event) {
|
public void onEventMainThread(PlaybackPositionEvent event) {
|
||||||
if (listAdapter != null) {
|
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)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void onEventMainThread(PlaybackPositionEvent event) {
|
public void onEventMainThread(PlaybackPositionEvent event) {
|
||||||
if (recyclerAdapter != null) {
|
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