mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
104 lines
3.8 KiB
Java
104 lines
3.8 KiB
Java
package com.cappielloantonio.play.adapter;
|
|
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.navigation.Navigation;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.cappielloantonio.play.R;
|
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
|
import com.cappielloantonio.play.model.Artist;
|
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder> {
|
|
private static final String TAG = "ArtistAdapter";
|
|
|
|
private List<Artist> artists;
|
|
private LayoutInflater inflater;
|
|
private Context context;
|
|
|
|
public ArtistAdapter(Context context) {
|
|
this.context = context;
|
|
this.inflater = LayoutInflater.from(context);
|
|
this.artists = new ArrayList<>();
|
|
}
|
|
|
|
@Override
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
View view = inflater.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());
|
|
|
|
CustomGlideRequest.Builder
|
|
.from(context, artist.getPrimary(), artist.getPrimaryBlurHash(), CustomGlideRequest.PRIMARY, PreferenceUtil.getInstance(context).getImageQuality(), CustomGlideRequest.ARTIST_PIC)
|
|
.build()
|
|
.into(holder.cover);
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return artists.size();
|
|
}
|
|
|
|
public Artist getItem(int position) {
|
|
return artists.get(position);
|
|
}
|
|
|
|
public void setItems(List<Artist> artists) {
|
|
this.artists = artists;
|
|
notifyDataSetChanged();
|
|
}
|
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
|
TextView textArtistName;
|
|
ImageView cover;
|
|
|
|
ViewHolder(View itemView) {
|
|
super(itemView);
|
|
|
|
textArtistName = itemView.findViewById(R.id.artist_name_label);
|
|
cover = itemView.findViewById(R.id.artist_cover_image_view);
|
|
|
|
itemView.setOnClickListener(this);
|
|
itemView.setOnLongClickListener(this);
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View view) {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
|
|
|
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.searchFragment) {
|
|
Navigation.findNavController(view).navigate(R.id.action_searchFragment_to_artistPageFragment, bundle);
|
|
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
|
|
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_artistPageFragment, bundle);
|
|
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistCatalogueFragment) {
|
|
Navigation.findNavController(view).navigate(R.id.action_artistCatalogueFragment_to_artistPageFragment, bundle);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean onLongClick(View v) {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
|
Navigation.findNavController(v).navigate(R.id.artistBottomSheetDialog, bundle);
|
|
return true;
|
|
}
|
|
}
|
|
}
|