Refactoring - Removed most of the click listeners from the adapters and moved them into the appropriate fragments

This commit is contained in:
antonio
2023-01-04 09:14:15 +01:00
parent 29f56945c2
commit 754fc69eab
54 changed files with 1143 additions and 1137 deletions

View File

@@ -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);
}
}
}