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

@ -9,38 +9,36 @@ import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;
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.Album;
import com.cappielloantonio.play.util.MusicUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder> {
private static final String TAG = "AlbumAdapter";
private final LayoutInflater inflater;
private final Context context;
private final ClickCallback click;
private List<Album> albums;
public AlbumAdapter(Context context) {
public AlbumAdapter(Context context, ClickCallback click) {
this.context = context;
this.inflater = LayoutInflater.from(context);
this.albums = new ArrayList<>();
this.click = click;
this.albums = Collections.emptyList();
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.item_library_album, parent, false);
View view = LayoutInflater.from(context).inflate(R.layout.item_library_album, parent, false);
return new ViewHolder(view);
}
@ -72,7 +70,7 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
public class ViewHolder extends RecyclerView.ViewHolder {
TextView textAlbumName;
TextView textArtistName;
ImageView cover;
@ -84,36 +82,28 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
textArtistName = itemView.findViewById(R.id.artist_name_label);
cover = itemView.findViewById(R.id.album_cover_image_view);
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
textAlbumName.setSelected(true);
textArtistName.setSelected(true);
itemView.setOnClickListener(v -> onClick());
itemView.setOnLongClickListener(v -> onLongClick());
}
@Override
public void onClick(View view) {
private void onClick() {
Bundle bundle = new Bundle();
bundle.putParcelable("album_object", albums.get(getBindingAdapterPosition()));
bundle.putBoolean("is_offline", false);
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.searchFragment) {
Navigation.findNavController(view).navigate(R.id.action_searchFragment_to_albumPageFragment, bundle);
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_albumPageFragment, bundle);
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.albumCatalogueFragment) {
Navigation.findNavController(view).navigate(R.id.action_albumCatalogueFragment_to_albumPageFragment, bundle);
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.homeFragment) {
Navigation.findNavController(view).navigate(R.id.action_homeFragment_to_albumPageFragment, bundle);
}
click.onAlbumClick(bundle);
}
@Override
public boolean onLongClick(View v) {
private boolean onLongClick() {
Bundle bundle = new Bundle();
bundle.putParcelable("album_object", albums.get(getBindingAdapterPosition()));
Navigation.findNavController(v).navigate(R.id.albumBottomSheetDialog, bundle);
return true;
click.onAlbumLongClick(bundle);
return false;
}
}
}