mirror of
https://github.com/CappielloAntonio/tempo.git
synced 2026-01-31 06:42:06 +00:00
Refactoring - Removed most of the click listeners from the adapters and moved them into the appropriate fragments
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -15,33 +16,33 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.service.MediaManager;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueueAdapter.ViewHolder> {
|
||||
private static final String TAG = "SongResultSearchAdapter";
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
|
||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||
private List<Media> songs;
|
||||
|
||||
public PlayerSongQueueAdapter(Context context) {
|
||||
public PlayerSongQueueAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.songs = new ArrayList<>();
|
||||
this.click = click;
|
||||
this.songs = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_player_queue_song, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_player_queue_song, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@@ -59,10 +60,7 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
|
||||
.into(holder.cover);
|
||||
|
||||
MediaManager.getCurrentIndex(mediaBrowserListenableFuture, index -> {
|
||||
if (position < index) {
|
||||
holder.songTitle.setTextColor(context.getResources().getColor(R.color.songToPlayTextColor, null));
|
||||
holder.songSubtitle.setTextColor(context.getResources().getColor(R.color.songToPlayTextColor, null));
|
||||
}
|
||||
holder.play.setVisibility(position == index ? View.VISIBLE : View.INVISIBLE);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -88,10 +86,11 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
|
||||
return songs.get(id);
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView songTitle;
|
||||
TextView songSubtitle;
|
||||
ImageView cover;
|
||||
ImageView play;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@@ -99,16 +98,20 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
|
||||
songTitle = itemView.findViewById(R.id.queue_song_title_text_view);
|
||||
songSubtitle = itemView.findViewById(R.id.queue_song_subtitle_text_view);
|
||||
cover = itemView.findViewById(R.id.queue_song_cover_image_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
play = itemView.findViewById(R.id.queue_song_play_image_view);
|
||||
|
||||
songTitle.setSelected(true);
|
||||
songSubtitle.setSelected(true);
|
||||
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, context, songs, getBindingAdapterPosition());
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelableArrayList("songs_object", new ArrayList<>(songs));
|
||||
bundle.putInt("position", getBindingAdapterPosition());
|
||||
|
||||
click.onMediaClick(bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user