mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
78 lines
2.2 KiB
Java
78 lines
2.2 KiB
Java
|
|
package com.cappielloantonio.play.adapter;
|
||
|
|
|
||
|
|
import android.content.Context;
|
||
|
|
import android.view.LayoutInflater;
|
||
|
|
import android.view.View;
|
||
|
|
import android.view.ViewGroup;
|
||
|
|
import android.widget.TextView;
|
||
|
|
|
||
|
|
import androidx.recyclerview.widget.RecyclerView;
|
||
|
|
|
||
|
|
import com.cappielloantonio.play.R;
|
||
|
|
import com.cappielloantonio.play.model.Album;
|
||
|
|
import com.cappielloantonio.play.model.Artist;
|
||
|
|
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder> {
|
||
|
|
private static final String TAG = "ArtistAdapter";
|
||
|
|
private List<Artist> artists;
|
||
|
|
private LayoutInflater mInflater;
|
||
|
|
private Context context;
|
||
|
|
private ItemClickListener itemClickListener;
|
||
|
|
|
||
|
|
public ArtistAdapter(Context context, List<Artist> artists) {
|
||
|
|
this.context = context;
|
||
|
|
this.mInflater = LayoutInflater.from(context);
|
||
|
|
this.artists = artists;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||
|
|
View view = mInflater.inflate(R.layout.item_library_artist, parent, false);
|
||
|
|
return new ViewHolder(view);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||
|
|
Artist artist = artists.get(position);
|
||
|
|
|
||
|
|
holder.textArtistName.setText(artist.getName());
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public int getItemCount() {
|
||
|
|
return artists.size();
|
||
|
|
}
|
||
|
|
|
||
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||
|
|
TextView textArtistName;
|
||
|
|
|
||
|
|
ViewHolder(View itemView) {
|
||
|
|
super(itemView);
|
||
|
|
|
||
|
|
textArtistName = itemView.findViewById(R.id.artist_name_label);
|
||
|
|
|
||
|
|
itemView.setOnClickListener(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void onClick(View view) {
|
||
|
|
if (itemClickListener != null) itemClickListener.onItemClick(view, getAdapterPosition());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setItems(List<Artist> artists) {
|
||
|
|
this.artists = artists;
|
||
|
|
notifyDataSetChanged();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setClickListener(ItemClickListener itemClickListener) {
|
||
|
|
this.itemClickListener = itemClickListener;
|
||
|
|
}
|
||
|
|
|
||
|
|
public interface ItemClickListener {
|
||
|
|
void onItemClick(View view, int position);
|
||
|
|
}
|
||
|
|
}
|