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 androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
|
|
|
|
import com.cappielloantonio.play.R;
|
|
|
|
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
|
|
|
|
import com.cappielloantonio.play.model.Song;
|
2021-04-27 11:01:02 +02:00
|
|
|
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
2021-05-02 16:47:29 +02:00
|
|
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
2021-04-12 17:56:09 +02:00
|
|
|
|
2020-12-05 21:31:12 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class PlayerNowPlayingSongAdapter extends RecyclerView.Adapter<PlayerNowPlayingSongAdapter.ViewHolder> {
|
|
|
|
|
private static final String TAG = "DiscoverSongAdapter";
|
|
|
|
|
|
|
|
|
|
private List<Song> songs;
|
|
|
|
|
private LayoutInflater inflater;
|
|
|
|
|
private Context context;
|
|
|
|
|
|
|
|
|
|
public PlayerNowPlayingSongAdapter(Context context) {
|
|
|
|
|
this.context = context;
|
|
|
|
|
this.inflater = LayoutInflater.from(context);
|
|
|
|
|
this.songs = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
|
View view = inflater.inflate(R.layout.item_player_now_playing_song, parent, false);
|
|
|
|
|
return new ViewHolder(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
|
|
|
|
Song song = songs.get(position);
|
|
|
|
|
|
|
|
|
|
CustomGlideRequest.Builder
|
2021-07-28 15:28:32 +02:00
|
|
|
.from(context, song.getId(), song.getBlurHash(), CustomGlideRequest.SONG_PIC)
|
2020-12-05 21:31:12 +01:00
|
|
|
.build()
|
|
|
|
|
.into(holder.cover);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemCount() {
|
|
|
|
|
return songs.size();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 11:01:02 +02:00
|
|
|
public Song getItem(int position) {
|
|
|
|
|
try {
|
|
|
|
|
return songs.get(position);
|
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setItems(List<Song> songs) {
|
|
|
|
|
this.songs = songs;
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-05 21:31:12 +01:00
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
|
|
|
ImageView cover;
|
|
|
|
|
|
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
|
super(itemView);
|
|
|
|
|
|
2020-12-09 19:31:35 +01:00
|
|
|
cover = itemView.findViewById(R.id.now_playing_song_cover_image_view);
|
2020-12-05 21:31:12 +01:00
|
|
|
|
|
|
|
|
itemView.setOnClickListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
2021-03-18 16:20:20 +01:00
|
|
|
if (MusicPlayerRemote.isPlaying()) {
|
|
|
|
|
MusicPlayerRemote.pauseSong();
|
|
|
|
|
} else {
|
|
|
|
|
MusicPlayerRemote.resumePlaying();
|
|
|
|
|
}
|
2020-12-05 21:31:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|