mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-30 18:34:50 +01:00
Update playback position in all episodes list
This commit is contained in:
parent
66cb923e9d
commit
8c1e6206da
@ -1,6 +1,7 @@
|
|||||||
package de.danoeh.antennapod.adapter;
|
package de.danoeh.antennapod.adapter;
|
||||||
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@ -23,10 +24,12 @@ import android.widget.TextView;
|
|||||||
import com.joanzapata.iconify.Iconify;
|
import com.joanzapata.iconify.Iconify;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.activity.MainActivity;
|
import de.danoeh.antennapod.activity.MainActivity;
|
||||||
import de.danoeh.antennapod.adapter.actionbutton.ItemActionButton;
|
import de.danoeh.antennapod.adapter.actionbutton.ItemActionButton;
|
||||||
|
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||||
@ -50,6 +53,7 @@ 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;
|
||||||
@ -165,8 +169,9 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
|||||||
holder.progress.setVisibility(View.INVISIBLE);
|
holder.progress.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -196,6 +201,22 @@ 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;
|
||||||
|
@ -24,6 +24,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
|
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
@ -384,6 +385,13 @@ public abstract class EpisodesListFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
public void onEventMainThread(PlaybackPositionEvent event) {
|
||||||
|
if (listAdapter != null) {
|
||||||
|
listAdapter.notifyCurrentlyPlayingItemChanged(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean shouldUpdatedItemRemainInList(FeedItem item) {
|
protected boolean shouldUpdatedItemRemainInList(FeedItem item) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user