mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
feat: add filter to display podcast episodes not yet downloaded
This commit is contained in:
parent
4b07f37378
commit
68aae32d06
4 changed files with 53 additions and 8 deletions
|
|
@ -2,6 +2,7 @@ package com.cappielloantonio.tempo.ui.adapter;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
@ -18,11 +19,14 @@ import com.cappielloantonio.tempo.util.MusicUtil;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAdapter.ViewHolder> {
|
public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAdapter.ViewHolder> {
|
||||||
private final ClickCallback click;
|
private final ClickCallback click;
|
||||||
|
|
||||||
private List<PodcastEpisode> podcastEpisodes;
|
private List<PodcastEpisode> podcastEpisodes;
|
||||||
|
private List<PodcastEpisode> podcastEpisodesFull;
|
||||||
|
|
||||||
public PodcastEpisodeAdapter(ClickCallback click) {
|
public PodcastEpisodeAdapter(ClickCallback click) {
|
||||||
this.click = click;
|
this.click = click;
|
||||||
|
|
@ -50,6 +54,9 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAd
|
||||||
.from(holder.itemView.getContext(), podcastEpisode.getCoverArtId())
|
.from(holder.itemView.getContext(), podcastEpisode.getCoverArtId())
|
||||||
.build()
|
.build()
|
||||||
.into(holder.item.podcastCoverImageView);
|
.into(holder.item.podcastCoverImageView);
|
||||||
|
|
||||||
|
holder.item.podcastPlayButton.setEnabled(podcastEpisode.getStatus().equals("completed"));
|
||||||
|
holder.item.podcastMoreButton.setVisibility(podcastEpisode.getStatus().equals("completed") ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -58,7 +65,8 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAd
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItems(List<PodcastEpisode> podcastEpisodes) {
|
public void setItems(List<PodcastEpisode> podcastEpisodes) {
|
||||||
this.podcastEpisodes = podcastEpisodes;
|
this.podcastEpisodesFull = podcastEpisodes;
|
||||||
|
this.podcastEpisodes = podcastEpisodesFull.stream().filter(podcastEpisode -> Objects.equals(podcastEpisode.getStatus(), "completed")).collect(Collectors.toList());
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,19 +96,42 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAd
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
Bundle bundle = new Bundle();
|
PodcastEpisode podcastEpisode = podcastEpisodes.get(getBindingAdapterPosition());
|
||||||
bundle.putParcelable(Constants.PODCAST_OBJECT, podcastEpisodes.get(getBindingAdapterPosition()));
|
|
||||||
|
|
||||||
click.onPodcastEpisodeClick(bundle);
|
if (podcastEpisode.getStatus().equals("completed")) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable(Constants.PODCAST_OBJECT, podcastEpisodes.get(getBindingAdapterPosition()));
|
||||||
|
|
||||||
|
click.onPodcastEpisodeClick(bundle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean openMore() {
|
private boolean openMore() {
|
||||||
Bundle bundle = new Bundle();
|
PodcastEpisode podcastEpisode = podcastEpisodes.get(getBindingAdapterPosition());
|
||||||
bundle.putParcelable(Constants.PODCAST_OBJECT, podcastEpisodes.get(getBindingAdapterPosition()));
|
|
||||||
|
|
||||||
click.onPodcastEpisodeLongClick(bundle);
|
if (podcastEpisode.getStatus().equals("completed")) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable(Constants.PODCAST_OBJECT, podcastEpisodes.get(getBindingAdapterPosition()));
|
||||||
|
|
||||||
return true;
|
click.onPodcastEpisodeLongClick(bundle);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sort(String order) {
|
||||||
|
switch (order) {
|
||||||
|
case Constants.PODCAST_FILTER_BY_DOWNLOAD:
|
||||||
|
podcastEpisodes = podcastEpisodesFull.stream().filter(podcastEpisode -> Objects.equals(podcastEpisode.getStatus(), "completed")).collect(Collectors.toList());
|
||||||
|
break;
|
||||||
|
case Constants.PODCAST_FILTER_BY_ALL:
|
||||||
|
podcastEpisodes = podcastEpisodesFull;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -44,6 +44,9 @@ object Constants {
|
||||||
const val PLAYLIST_ORDER_BY_NAME = "ORDER_BY_NAME"
|
const val PLAYLIST_ORDER_BY_NAME = "ORDER_BY_NAME"
|
||||||
const val PLAYLIST_ORDER_BY_RANDOM = "ORDER_BY_RANDOM"
|
const val PLAYLIST_ORDER_BY_RANDOM = "ORDER_BY_RANDOM"
|
||||||
|
|
||||||
|
const val PODCAST_FILTER_BY_DOWNLOAD = "PODCAST_FILTER_BY_DOWNLOAD"
|
||||||
|
const val PODCAST_FILTER_BY_ALL = "PODCAST_FILTER_BY_ALL"
|
||||||
|
|
||||||
const val MEDIA_TYPE_MUSIC = "music"
|
const val MEDIA_TYPE_MUSIC = "music"
|
||||||
const val MEDIA_TYPE_PODCAST = "podcast"
|
const val MEDIA_TYPE_PODCAST = "podcast"
|
||||||
const val MEDIA_TYPE_AUDIOBOOK = "audiobook"
|
const val MEDIA_TYPE_AUDIOBOOK = "audiobook"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_podcast_filter_download"
|
||||||
|
android:title="@string/menu_filter_download" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_podcast_filter_all"
|
||||||
|
android:title="@string/menu_filter_all" />
|
||||||
|
</menu>
|
||||||
|
|
@ -265,4 +265,6 @@
|
||||||
<string name="menu_sort_name">Name</string>
|
<string name="menu_sort_name">Name</string>
|
||||||
<string name="menu_sort_random">Random</string>
|
<string name="menu_sort_random">Random</string>
|
||||||
<string name="description_empty_title">No description available</string>
|
<string name="description_empty_title">No description available</string>
|
||||||
|
<string name="menu_filter_download">Downloaded</string>
|
||||||
|
<string name="menu_filter_all">All</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue