2020-11-20 15:38:08 +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.TextView;
|
|
|
|
|
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
2020-11-22 19:11:38 +01:00
|
|
|
import com.cappielloantonio.play.App;
|
2020-11-20 15:38:08 +01:00
|
|
|
import com.cappielloantonio.play.R;
|
|
|
|
|
import com.cappielloantonio.play.model.Song;
|
2020-11-22 19:11:38 +01:00
|
|
|
import com.cappielloantonio.play.repository.SongRepository;
|
2020-11-20 15:38:08 +01:00
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2020-11-21 13:54:49 +01:00
|
|
|
/**
|
|
|
|
|
* Adapter per i brani recenti in home
|
|
|
|
|
*/
|
2020-11-20 15:38:08 +01:00
|
|
|
public class RecentMusicAdapter extends RecyclerView.Adapter<RecentMusicAdapter.ViewHolder> {
|
|
|
|
|
private static final String TAG = "RecentMusicAdapter";
|
|
|
|
|
private List<Song> songs;
|
|
|
|
|
private LayoutInflater mInflater;
|
|
|
|
|
private Context context;
|
|
|
|
|
|
|
|
|
|
public RecentMusicAdapter(Context context, List<Song> songs) {
|
|
|
|
|
this.context = context;
|
|
|
|
|
this.mInflater = LayoutInflater.from(context);
|
|
|
|
|
this.songs = songs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
2020-11-21 13:54:49 +01:00
|
|
|
View view = mInflater.inflate(R.layout.item_home_recent_track, parent, false);
|
2020-11-20 15:38:08 +01:00
|
|
|
return new ViewHolder(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
|
|
|
|
Song song = songs.get(position);
|
|
|
|
|
|
|
|
|
|
holder.textTitle.setText(song.getTitle());
|
2020-11-25 15:12:07 +01:00
|
|
|
holder.textAlbum.setText(song.getAlbumName());
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemCount() {
|
|
|
|
|
return songs.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
|
|
|
TextView textTitle;
|
2020-11-25 15:12:07 +01:00
|
|
|
TextView textAlbum;
|
2020-11-20 15:38:08 +01:00
|
|
|
|
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
|
super(itemView);
|
|
|
|
|
|
|
|
|
|
textTitle = itemView.findViewById(R.id.title_track_label);
|
2020-11-25 15:12:07 +01:00
|
|
|
textAlbum = itemView.findViewById(R.id.album_track_label);
|
2020-11-20 15:38:08 +01:00
|
|
|
|
|
|
|
|
itemView.setOnClickListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
2020-11-22 19:11:38 +01:00
|
|
|
SongRepository songRepository = new SongRepository(App.getInstance());
|
|
|
|
|
songRepository.update(songs.get(getAdapterPosition()));
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-21 18:41:35 +01:00
|
|
|
public void setItems(List<Song> songs) {
|
|
|
|
|
this.songs = songs;
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
}
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|