feat: updated the horizontal song adapter with the disc name information

This commit is contained in:
CappielloAntonio 2024-05-25 22:33:26 +02:00
parent 25900c848a
commit b3b1c5b006
9 changed files with 66 additions and 15 deletions

View file

@ -14,7 +14,9 @@ import com.cappielloantonio.tempo.R;
import com.cappielloantonio.tempo.databinding.ItemHorizontalTrackBinding;
import com.cappielloantonio.tempo.glide.CustomGlideRequest;
import com.cappielloantonio.tempo.interfaces.ClickCallback;
import com.cappielloantonio.tempo.subsonic.models.AlbumID3;
import com.cappielloantonio.tempo.subsonic.models.Child;
import com.cappielloantonio.tempo.subsonic.models.DiscTitle;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.DownloadUtil;
import com.cappielloantonio.tempo.util.MusicUtil;
@ -23,20 +25,24 @@ import com.cappielloantonio.tempo.util.Preferences;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@UnstableApi
public class SongHorizontalAdapter extends RecyclerView.Adapter<SongHorizontalAdapter.ViewHolder> {
private final ClickCallback click;
private final boolean showCoverArt;
private final boolean showAlbum;
private final AlbumID3 album;
private List<Child> songs;
public SongHorizontalAdapter(ClickCallback click, boolean showCoverArt, boolean showAlbum) {
public SongHorizontalAdapter(ClickCallback click, boolean showCoverArt, boolean showAlbum, AlbumID3 album) {
this.click = click;
this.showCoverArt = showCoverArt;
this.showAlbum = showAlbum;
this.songs = Collections.emptyList();
this.album = album;
}
@NonNull
@ -81,8 +87,25 @@ public class SongHorizontalAdapter extends RecyclerView.Adapter<SongHorizontalAd
holder.item.trackNumberTextView.setVisibility(showCoverArt ? View.INVISIBLE : View.VISIBLE);
holder.item.songCoverImageView.setVisibility(showCoverArt ? View.VISIBLE : View.INVISIBLE);
if (!showCoverArt && (position > 0 && songs.get(position - 1) != null && songs.get(position - 1).getDiscNumber() != null && songs.get(position).getDiscNumber() != null && songs.get(position - 1).getDiscNumber() < songs.get(position).getDiscNumber())) {
holder.item.differentDiskDivider.setVisibility(View.VISIBLE);
if (!showCoverArt &&
(position == 0 ||
(position > 0 && songs.get(position - 1) != null &&
songs.get(position - 1).getDiscNumber() != null &&
songs.get(position).getDiscNumber() != null &&
songs.get(position - 1).getDiscNumber() < songs.get(position).getDiscNumber()
)
)
) {
holder.item.differentDiskDividerSector.setVisibility(View.VISIBLE);
holder.item.discTitleTextView.setText(holder.itemView.getContext().getString(R.string.disc_titleless, songs.get(position).getDiscNumber().toString()));
if (album.getDiscTitles() != null) {
Optional<DiscTitle> discTitle = album.getDiscTitles().stream().filter(title -> Objects.equals(title.getDisc(), songs.get(position).getDiscNumber())).findFirst();
if (discTitle.isPresent() && discTitle.get().getTitle() != null) {
holder.item.discTitleTextView.setText(holder.itemView.getContext().getString(R.string.disc_titleless, discTitle.get().getTitle()));
}
}
}
if (Preferences.showItemRating()) {