2020-12-05 21:31:12 +01:00
|
|
|
package com.cappielloantonio.play.adapter;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
|
|
|
|
import com.cappielloantonio.play.R;
|
|
|
|
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
2021-03-18 16:20:20 +01:00
|
|
|
import com.cappielloantonio.play.helper.MusicPlayerRemote;
|
2020-12-05 21:31:12 +01:00
|
|
|
import com.cappielloantonio.play.model.Song;
|
2020-12-08 11:12:44 +01:00
|
|
|
import com.cappielloantonio.play.ui.fragment.PlayerBottomSheetFragment;
|
2021-04-18 10:10:53 +02:00
|
|
|
import com.cappielloantonio.play.util.MusicUtil;
|
2020-12-05 21:31:12 +01:00
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adapter per i brani ritrovati nella ricerca
|
|
|
|
|
*/
|
|
|
|
|
public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueueAdapter.ViewHolder> {
|
|
|
|
|
private static final String TAG = "SongResultSearchAdapter";
|
|
|
|
|
|
|
|
|
|
private List<Song> songs;
|
|
|
|
|
private LayoutInflater mInflater;
|
2020-12-08 11:12:44 +01:00
|
|
|
private PlayerBottomSheetFragment playerBottomSheetFragment;
|
2020-12-05 21:31:12 +01:00
|
|
|
private Context context;
|
|
|
|
|
|
2020-12-08 11:12:44 +01:00
|
|
|
public PlayerSongQueueAdapter(Context context, PlayerBottomSheetFragment playerBottomSheetFragment) {
|
2020-12-05 21:31:12 +01:00
|
|
|
this.context = context;
|
2020-12-08 11:12:44 +01:00
|
|
|
this.playerBottomSheetFragment = playerBottomSheetFragment;
|
2020-12-05 21:31:12 +01:00
|
|
|
this.mInflater = LayoutInflater.from(context);
|
|
|
|
|
this.songs = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
|
View view = mInflater.inflate(R.layout.item_player_queue_song, parent, false);
|
|
|
|
|
return new ViewHolder(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
|
|
|
|
Song song = songs.get(position);
|
|
|
|
|
|
|
|
|
|
holder.songTitle.setText(song.getTitle());
|
|
|
|
|
holder.songArtist.setText(song.getArtistName());
|
2021-04-18 10:10:53 +02:00
|
|
|
holder.songDuration.setText(MusicUtil.getReadableDurationString(song.getDuration()));
|
2020-12-05 21:31:12 +01:00
|
|
|
|
|
|
|
|
CustomGlideRequest.Builder
|
2021-04-14 14:06:35 +02:00
|
|
|
.from(context, song.getPrimary(), song.getBlurHash(), CustomGlideRequest.PRIMARY, CustomGlideRequest.TOP_QUALITY, CustomGlideRequest.SONG_PIC)
|
2020-12-05 21:31:12 +01:00
|
|
|
.build()
|
|
|
|
|
.into(holder.cover);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemCount() {
|
|
|
|
|
return songs.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
|
|
|
TextView songTitle;
|
|
|
|
|
TextView songArtist;
|
2021-04-18 10:10:53 +02:00
|
|
|
TextView songDuration;
|
2020-12-05 21:31:12 +01:00
|
|
|
ImageView cover;
|
|
|
|
|
|
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
|
super(itemView);
|
|
|
|
|
|
|
|
|
|
songTitle = itemView.findViewById(R.id.queue_song_title_text_view);
|
|
|
|
|
songArtist = itemView.findViewById(R.id.queue_song_artist_text_view);
|
2021-04-18 10:10:53 +02:00
|
|
|
songDuration = itemView.findViewById(R.id.queue_song_duration_text_view);
|
2020-12-05 21:31:12 +01:00
|
|
|
cover = itemView.findViewById(R.id.queue_song_cover_image_view);
|
|
|
|
|
|
|
|
|
|
itemView.setOnClickListener(this);
|
2021-04-15 08:45:48 +02:00
|
|
|
|
|
|
|
|
songTitle.setSelected(true);
|
2020-12-05 21:31:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
2021-04-13 18:13:22 +02:00
|
|
|
playerBottomSheetFragment.scrollPager(songs.get(getBindingAdapterPosition()), getBindingAdapterPosition(), false);
|
2021-04-12 14:51:25 +02:00
|
|
|
MusicPlayerRemote.openQueue(songs, getBindingAdapterPosition(), true);
|
2020-12-05 21:31:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setItems(List<Song> songs) {
|
|
|
|
|
this.songs = songs;
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-16 10:08:31 +02:00
|
|
|
public List<Song> getItems() {
|
|
|
|
|
return this.songs;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-05 21:31:12 +01:00
|
|
|
public Song getItem(int id) {
|
|
|
|
|
return songs.get(id);
|
|
|
|
|
}
|
|
|
|
|
}
|