mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
113 lines
3.4 KiB
Java
113 lines
3.4 KiB
Java
package com.cappielloantonio.play.adapter;
|
|
|
|
import android.os.Bundle;
|
|
import android.view.LayoutInflater;
|
|
import android.view.ViewGroup;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.media3.common.util.UnstableApi;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
|
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
|
import com.cappielloantonio.play.databinding.ItemLibraryArtistBinding;
|
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
|
import com.cappielloantonio.play.interfaces.ClickCallback;
|
|
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
|
import com.cappielloantonio.play.util.MusicUtil;
|
|
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
@UnstableApi
|
|
public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder> {
|
|
private final ClickCallback click;
|
|
private final boolean mix;
|
|
private final boolean bestOf;
|
|
|
|
private List<ArtistID3> artists;
|
|
|
|
public ArtistAdapter(ClickCallback click, Boolean mix, Boolean bestOf) {
|
|
this.click = click;
|
|
this.mix = mix;
|
|
this.bestOf = bestOf;
|
|
this.artists = Collections.emptyList();
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
ItemLibraryArtistBinding view = ItemLibraryArtistBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
|
return new ViewHolder(view);
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
|
ArtistID3 artist = artists.get(position);
|
|
|
|
holder.item.artistNameLabel.setText(MusicUtil.getReadableString(artist.getName()));
|
|
|
|
CustomGlideRequest.Builder
|
|
.from(holder.itemView.getContext(), artist.getCoverArtId(), CustomGlideRequest.ARTIST_PIC, null)
|
|
.build()
|
|
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
|
.into(holder.item.artistCoverImageView);
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return artists.size();
|
|
}
|
|
|
|
public ArtistID3 getItem(int position) {
|
|
return artists.get(position);
|
|
}
|
|
|
|
public void setItems(List<ArtistID3> artists) {
|
|
this.artists = artists;
|
|
notifyDataSetChanged();
|
|
}
|
|
|
|
@Override
|
|
public int getItemViewType(int position) {
|
|
return position;
|
|
}
|
|
|
|
@Override
|
|
public long getItemId(int position) {
|
|
return position;
|
|
}
|
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
|
ItemLibraryArtistBinding item;
|
|
|
|
ViewHolder(ItemLibraryArtistBinding item) {
|
|
super(item.getRoot());
|
|
|
|
this.item = item;
|
|
|
|
item.artistNameLabel.setSelected(true);
|
|
|
|
itemView.setOnClickListener(v -> onClick());
|
|
itemView.setOnLongClickListener(v -> onLongClick());
|
|
}
|
|
|
|
public void onClick() {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
|
bundle.putBoolean("is_mix", mix);
|
|
bundle.putBoolean("is_best_of", bestOf);
|
|
|
|
click.onArtistClick(bundle);
|
|
}
|
|
|
|
public boolean onLongClick() {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
|
|
|
click.onArtistLongClick(bundle);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|