First implementation of PodcastEpisodeAdapter

This commit is contained in:
CappielloAntonio 2022-02-05 18:37:34 +01:00
parent 11d76fa290
commit 1ed6603a76
2 changed files with 235 additions and 0 deletions

View file

@ -0,0 +1,111 @@
package com.cappielloantonio.play.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.media3.session.MediaBrowser;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.glide.CustomGlideRequest;
import com.cappielloantonio.play.model.PodcastEpisode;
import com.cappielloantonio.play.ui.activity.MainActivity;
import com.cappielloantonio.play.util.MusicUtil;
import com.google.common.util.concurrent.ListenableFuture;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAdapter.ViewHolder> {
private static final String TAG = "DiscoverSongAdapter";
private final LayoutInflater inflater;
private final Context context;
private final MainActivity activity;
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
private List<PodcastEpisode> podcastEpisodes;
public PodcastEpisodeAdapter(MainActivity activity, Context context) {
this.activity = activity;
this.context = context;
this.inflater = LayoutInflater.from(context);
this.podcastEpisodes = new ArrayList<>();
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.item_home_podcast_episode, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
PodcastEpisode podcastEpisode = podcastEpisodes.get(position);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM d");
holder.textTitle.setText(MusicUtil.getReadableString(podcastEpisode.getTitle()));
holder.textSubtitle.setText(MusicUtil.getReadableString(podcastEpisode.getArtist()));
holder.textReleaseAndDuration.setText(context.getString(R.string.podcast_release_date_duration_formatter, simpleDateFormat.format(podcastEpisode.getPublishDate()), MusicUtil.getReadablePodcastDurationString(podcastEpisode.getDuration())));
holder.textDescription.setText(MusicUtil.getReadableString(podcastEpisode.getDescription()));
CustomGlideRequest.Builder
.from(context, podcastEpisode.getCoverArtId(), CustomGlideRequest.SONG_PIC, null)
.build()
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.cover);
}
@Override
public int getItemCount() {
return podcastEpisodes.size();
}
public void setItems(List<PodcastEpisode> podcastEpisodes) {
this.podcastEpisodes = podcastEpisodes;
notifyDataSetChanged();
}
public void setMediaBrowserListenableFuture(ListenableFuture<MediaBrowser> mediaBrowserListenableFuture) {
this.mediaBrowserListenableFuture = mediaBrowserListenableFuture;
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textTitle;
TextView textSubtitle;
TextView textReleaseAndDuration;
TextView textDescription;
ImageView cover;
Button playButton;
Button moreButton;
ViewHolder(View itemView) {
super(itemView);
textTitle = itemView.findViewById(R.id.podcast_title_label);
textSubtitle = itemView.findViewById(R.id.podcast_subtitle_label);
textReleaseAndDuration = itemView.findViewById(R.id.podcast_releases_and_duration_label);
textDescription = itemView.findViewById(R.id.podcast_description_label);
cover = itemView.findViewById(R.id.podcast_cover_image_view);
playButton = itemView.findViewById(R.id.podcast_play_button);
moreButton = itemView.findViewById(R.id.podcast_more_button);
playButton.setOnClickListener(this);
}
@Override
public void onClick(View view) {
// MediaManager.startQueue(mediaBrowserListenableFuture, context, podcastEpisodes.get(getBindingAdapterPosition()));
// activity.setBottomSheetInPeek(true);
}
}
}

View file

@ -0,0 +1,124 @@
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/Widget.Material3.CardView.Outlined"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="4dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/podcast_cover_image_view"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center"
android:layout_margin="12dp"
app:layout_constraintBottom_toTopOf="@+id/podcast_upper_divider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/podcast_title_label"
style="@style/LabelLarge"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
android:paddingStart="12dp"
android:paddingEnd="16dp"
android:text="@string/label_placeholder"
app:layout_constraintBottom_toTopOf="@+id/podcast_subtitle_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/podcast_cover_image_view"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/podcast_subtitle_label"
style="@style/LabelMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
android:paddingStart="12dp"
android:paddingEnd="16dp"
android:text="@string/label_placeholder"
app:layout_constraintBottom_toTopOf="@id/podcast_upper_divider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/podcast_cover_image_view"
app:layout_constraintTop_toBottomOf="@+id/podcast_title_label" />
<View
android:id="@+id/podcast_upper_divider"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/podcast_cover_image_view"/>
<TextView
android:id="@+id/podcast_description_label"
style="@style/LabelSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:singleLine="false"
android:text="@string/label_placeholder"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/podcast_upper_divider" />
<Button
android:id="@+id/podcast_play_button"
style="@style/Widget.Material3.Button.TonalButton.Icon"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
app:icon="@drawable/ic_play"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
app:cornerRadius="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/podcast_description_label"/>
<TextView
android:id="@+id/podcast_releases_and_duration_label"
style="@style/LabelSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:text="@string/label_placeholder"
app:layout_constraintBottom_toBottomOf="@+id/podcast_play_button"
app:layout_constraintStart_toEndOf="@+id/podcast_play_button"
app:layout_constraintTop_toTopOf="@+id/podcast_play_button" />
<Button
android:id="@+id/podcast_more_button"
style="@style/Widget.Material3.Button.IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:icon="@drawable/ic_more_vert"
app:layout_constraintBottom_toBottomOf="@+id/podcast_play_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/podcast_play_button" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>