mirror of
https://github.com/gabehf/tempus.git
synced 2026-03-09 07:28:20 -07:00
Refactoring - Removed most of the click listeners from the adapters and moved them into the appropriate fragments
This commit is contained in:
parent
29f56945c2
commit
754fc69eab
54 changed files with 1143 additions and 1137 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,37 +9,35 @@ 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;
|
||||
|
||||
public class AlbumArtistPageOrSimilarAdapter extends RecyclerView.Adapter<AlbumArtistPageOrSimilarAdapter.ViewHolder> {
|
||||
private static final String TAG = "AlbumArtistPageAdapter";
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
|
||||
private List<Album> albums;
|
||||
|
||||
public AlbumArtistPageOrSimilarAdapter(Context context) {
|
||||
public AlbumArtistPageOrSimilarAdapter(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_artist_page_or_similar_album, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_library_artist_page_or_similar_album, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +69,7 @@ public class AlbumArtistPageOrSimilarAdapter extends RecyclerView.Adapter<AlbumA
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textAlbumName;
|
||||
TextView textArtistName;
|
||||
ImageView cover;
|
||||
|
|
@ -83,27 +81,28 @@ public class AlbumArtistPageOrSimilarAdapter extends RecyclerView.Adapter<AlbumA
|
|||
textArtistName = itemView.findViewById(R.id.artist_name_label);
|
||||
cover = itemView.findViewById(R.id.artist_page_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);
|
||||
Navigation.findNavController(view).navigate(R.id.albumPageFragment, bundle);
|
||||
|
||||
click.onAlbumClick(bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
private boolean onLongClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("album_object", albums.get(getBindingAdapterPosition()));
|
||||
Navigation.findNavController(view).navigate(R.id.albumBottomSheetDialog, bundle);
|
||||
return true;
|
||||
|
||||
click.onAlbumLongClick(bundle);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,36 +5,30 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
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.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAdapter.ViewHolder> implements Filterable {
|
||||
private static final String TAG = "AlbumCatalogueAdapter";
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
private final MainActivity activity;
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
private final Filter filtering = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
|
|
@ -69,17 +63,16 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
|
|||
private List<Album> albums;
|
||||
private List<Album> albumsFull;
|
||||
|
||||
public AlbumCatalogueAdapter(MainActivity activity, Context context) {
|
||||
this.activity = activity;
|
||||
public AlbumCatalogueAdapter(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_catalogue_album, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_library_catalogue_album, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +120,7 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
|
|||
return filtering;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textAlbumName;
|
||||
TextView textArtistName;
|
||||
ImageView cover;
|
||||
|
|
@ -139,37 +132,28 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
|
|||
textArtistName = itemView.findViewById(R.id.artist_name_label);
|
||||
cover = itemView.findViewById(R.id.album_catalogue_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);
|
||||
}
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,39 +9,37 @@ 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 AlbumHorizontalAdapter extends RecyclerView.Adapter<AlbumHorizontalAdapter.ViewHolder> {
|
||||
private static final String TAG = "AlbumHorizontalAdapter";
|
||||
|
||||
private List<Album> albums;
|
||||
private final LayoutInflater mInflater;
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
private final boolean isOffline;
|
||||
|
||||
public AlbumHorizontalAdapter(Context context, boolean isOffline) {
|
||||
private List<Album> albums;
|
||||
|
||||
public AlbumHorizontalAdapter(Context context, ClickCallback click, boolean isOffline) {
|
||||
this.context = context;
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.albums = new ArrayList<>();
|
||||
this.click = click;
|
||||
this.isOffline = isOffline;
|
||||
this.albums = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_horizontal_album, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_horizontal_album, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +71,7 @@ public class AlbumHorizontalAdapter extends RecyclerView.Adapter<AlbumHorizontal
|
|||
return albums.get(id);
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView albumTitle;
|
||||
TextView albumArtist;
|
||||
ImageView more;
|
||||
|
|
@ -87,41 +85,29 @@ public class AlbumHorizontalAdapter extends RecyclerView.Adapter<AlbumHorizontal
|
|||
more = itemView.findViewById(R.id.album_more_button);
|
||||
cover = itemView.findViewById(R.id.album_cover_image_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
|
||||
more.setOnClickListener(this::openMore);
|
||||
|
||||
albumTitle.setSelected(true);
|
||||
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
itemView.setOnLongClickListener(v -> onLongClick());
|
||||
|
||||
more.setOnClickListener(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", isOffline);
|
||||
bundle.putBoolean("is_offline", false);
|
||||
|
||||
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.homeFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_homeFragment_to_albumPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.albumListPageFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_albumListPageFragment_to_albumPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.downloadFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_downloadFragment_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);
|
||||
}
|
||||
click.onAlbumClick(bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
openMore(v);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void openMore(View view) {
|
||||
private boolean onLongClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("album_object", albums.get(getBindingAdapterPosition()));
|
||||
Navigation.findNavController(view).navigate(R.id.albumBottomSheetDialog, bundle);
|
||||
|
||||
click.onAlbumLongClick(bundle);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,16 @@ package com.cappielloantonio.play.adapter;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
|
@ -22,42 +21,36 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
|||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.service.MediaManager;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@UnstableApi
|
||||
public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder> {
|
||||
private static final String TAG = "ArtistAdapter";
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
private final MainActivity mainActivity;
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
private final boolean mix;
|
||||
|
||||
private List<Artist> artists;
|
||||
|
||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||
|
||||
public ArtistAdapter(MainActivity mainActivity, Context context) {
|
||||
this.mainActivity = mainActivity;
|
||||
public ArtistAdapter(Context context, ClickCallback click, Boolean mix) {
|
||||
this.context = context;
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
this.artists = new ArrayList<>();
|
||||
this.click = click;
|
||||
this.mix = mix;
|
||||
this.artists = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = inflater.inflate(R.layout.item_library_artist, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_library_artist, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -94,10 +87,6 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
|||
return position;
|
||||
}
|
||||
|
||||
public void setMediaBrowserListenableFuture(ListenableFuture<MediaBrowser> mediaBrowserListenableFuture) {
|
||||
this.mediaBrowserListenableFuture = mediaBrowserListenableFuture;
|
||||
}
|
||||
|
||||
private void setArtistCover(Artist artist, ImageView cover) {
|
||||
ArtistRepository artistRepository = new ArtistRepository(App.getInstance());
|
||||
LiveData<Artist> livedata = artistRepository.getArtistFullInfo(artist.getId());
|
||||
|
|
@ -115,7 +104,7 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
|||
});
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textArtistName;
|
||||
ImageView cover;
|
||||
|
||||
|
|
@ -125,56 +114,27 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
|||
textArtistName = itemView.findViewById(R.id.artist_name_label);
|
||||
cover = itemView.findViewById(R.id.artist_cover_image_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
|
||||
textArtistName.setSelected(true);
|
||||
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
itemView.setOnLongClickListener(v -> onLongClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
bundle.putBoolean("is_mix", mix);
|
||||
|
||||
click.onArtistClick(bundle);
|
||||
}
|
||||
|
||||
public boolean onLongClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
|
||||
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.searchFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_searchFragment_to_artistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_artistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistCatalogueFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_artistCatalogueFragment_to_artistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.homeFragment) {
|
||||
Snackbar.make(mainActivity.bind.getRoot(), R.string.artist_adapter_radio_station_starting, Snackbar.LENGTH_LONG)
|
||||
.setAnchorView(mainActivity.bind.playerBottomSheet)
|
||||
.show();
|
||||
click.onArtistLongClick(bundle);
|
||||
|
||||
if (mediaBrowserListenableFuture != null) {
|
||||
ArtistRepository artistRepository = new ArtistRepository(App.getInstance());
|
||||
artistRepository.getInstantMix(artists.get(getBindingAdapterPosition()), 20, new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
Log.e(TAG, "onError() " + exception.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
if (media.size() > 0) {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, context, (ArrayList<Media>) media, 0);
|
||||
mainActivity.setBottomSheetInPeek(true);
|
||||
} else {
|
||||
Toast.makeText(context, context.getString(R.string.artist_error_retrieving_radio), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
Navigation.findNavController(v).navigate(R.id.artistBottomSheetDialog, bundle);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
|
|
@ -14,29 +13,25 @@ import android.widget.TextView;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogueAdapter.ViewHolder> implements Filterable {
|
||||
private static final String TAG = "ArtistCatalogueAdapter";
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
private final MainActivity activity;
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
|
||||
private final Filter filtering = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
|
|
@ -71,17 +66,16 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogue
|
|||
private List<Artist> artists;
|
||||
private List<Artist> artistFull;
|
||||
|
||||
public ArtistCatalogueAdapter(MainActivity activity, Context context) {
|
||||
this.activity = activity;
|
||||
public ArtistCatalogueAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
this.artists = new ArrayList<>();
|
||||
this.click = click;
|
||||
this.artists = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = inflater.inflate(R.layout.item_library_catalogue_artist, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_library_catalogue_artist, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +139,7 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogue
|
|||
});
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textArtistName;
|
||||
ImageView cover;
|
||||
|
||||
|
|
@ -155,35 +149,26 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogue
|
|||
textArtistName = itemView.findViewById(R.id.artist_name_label);
|
||||
cover = itemView.findViewById(R.id.artist_catalogue_cover_image_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
|
||||
textArtistName.setSelected(true);
|
||||
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
itemView.setOnLongClickListener(v -> onLongClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
|
||||
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.searchFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_searchFragment_to_artistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_artistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistCatalogueFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_artistCatalogueFragment_to_artistPageFragment, bundle);
|
||||
}
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
click.onArtistClick(bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
public boolean onLongClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
Navigation.findNavController(v).navigate(R.id.artistBottomSheetDialog, bundle);
|
||||
return true;
|
||||
|
||||
click.onArtistLongClick(bundle);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import android.widget.TextView;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
|
|
@ -19,33 +18,30 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
|||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ArtistHorizontalAdapter extends RecyclerView.Adapter<ArtistHorizontalAdapter.ViewHolder> {
|
||||
private static final String TAG = "ArtistHorizontalAdapter";
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
|
||||
private List<Artist> artists;
|
||||
private final LayoutInflater mInflater;
|
||||
private final Context context;
|
||||
private final boolean isDownloaded;
|
||||
|
||||
public ArtistHorizontalAdapter(Context context, boolean isDownloaded) {
|
||||
public ArtistHorizontalAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.artists = new ArrayList<>();
|
||||
this.isDownloaded = isDownloaded;
|
||||
this.click = click;
|
||||
this.artists = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_horizontal_artist, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_horizontal_artist, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +106,7 @@ public class ArtistHorizontalAdapter extends RecyclerView.Adapter<ArtistHorizont
|
|||
});
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView artistName;
|
||||
TextView artistInfo;
|
||||
|
||||
|
|
@ -125,40 +121,28 @@ public class ArtistHorizontalAdapter extends RecyclerView.Adapter<ArtistHorizont
|
|||
more = itemView.findViewById(R.id.artist_more_button);
|
||||
cover = itemView.findViewById(R.id.artist_cover_image_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
|
||||
more.setOnClickListener(this::openMore);
|
||||
artistName.setSelected(true);
|
||||
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
itemView.setOnLongClickListener(v -> onLongClick());
|
||||
|
||||
more.setOnClickListener(v -> onLongClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
private void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
|
||||
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.homeFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_homeFragment_to_artistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistListPageFragment) {
|
||||
if (!isDownloaded)
|
||||
Navigation.findNavController(view).navigate(R.id.action_artistListPageFragment_to_artistPageFragment, bundle);
|
||||
else
|
||||
Navigation.findNavController(view).navigate(R.id.action_artistListPageFragment_to_albumListPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.downloadFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_downloadFragment_to_albumListPageFragment, bundle);
|
||||
}
|
||||
click.onArtistClick(bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
openMore(v);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void openMore(View view) {
|
||||
public boolean onLongClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
Navigation.findNavController(view).navigate(R.id.artistBottomSheetDialog, bundle);
|
||||
|
||||
click.onArtistLongClick(bundle);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,31 +20,31 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
|||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ArtistSimilarAdapter extends RecyclerView.Adapter<ArtistSimilarAdapter.ViewHolder> {
|
||||
private static final String TAG = "AlbumArtistPageAdapter";
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
|
||||
private List<Artist> artists;
|
||||
|
||||
public ArtistSimilarAdapter(Context context) {
|
||||
public ArtistSimilarAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
this.artists = new ArrayList<>();
|
||||
this.click = click;
|
||||
this.artists = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = inflater.inflate(R.layout.item_library_similar_artist, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_library_similar_artist, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -133,5 +133,21 @@ public class ArtistSimilarAdapter extends RecyclerView.Adapter<ArtistSimilarAdap
|
|||
Navigation.findNavController(view).navigate(R.id.artistBottomSheetDialog, bundle);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
|
||||
click.onArtistClick(bundle);
|
||||
}
|
||||
|
||||
public boolean onLongClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
|
||||
click.onArtistLongClick(bundle);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.cappielloantonio.play.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -10,44 +10,33 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.service.MediaManager;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
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 DiscoverSongAdapter extends RecyclerView.Adapter<DiscoverSongAdapter.ViewHolder> {
|
||||
private static final String TAG = "DiscoverSongAdapter";
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
private final Context context;
|
||||
private final MainActivity activity;
|
||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||
private final ClickCallback click;
|
||||
|
||||
private List<Media> songs;
|
||||
|
||||
public DiscoverSongAdapter(MainActivity activity, Context context) {
|
||||
this.activity = activity;
|
||||
public DiscoverSongAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.inflater = 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 = inflater.inflate(R.layout.item_home_discover_song, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_home_discover_song, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -80,11 +69,7 @@ public class DiscoverSongAdapter extends RecyclerView.Adapter<DiscoverSongAdapte
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setMediaBrowserListenableFuture(ListenableFuture<MediaBrowser> mediaBrowserListenableFuture) {
|
||||
this.mediaBrowserListenableFuture = mediaBrowserListenableFuture;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textTitle;
|
||||
TextView textAlbum;
|
||||
ImageView cover;
|
||||
|
|
@ -96,26 +81,15 @@ public class DiscoverSongAdapter extends RecyclerView.Adapter<DiscoverSongAdapte
|
|||
textAlbum = itemView.findViewById(R.id.album_discover_song_label);
|
||||
cover = itemView.findViewById(R.id.discover_song_cover_image_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, context, songs.get(getBindingAdapterPosition()));
|
||||
activity.setBottomSheetInPeek(true);
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("song_object", songs.get(getBindingAdapterPosition()));
|
||||
bundle.putBoolean("is_mix", true);
|
||||
|
||||
SongRepository songRepository = new SongRepository(App.getInstance());
|
||||
songRepository.getInstantMix(songs.get(getBindingAdapterPosition()), 20, new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
Log.e(TAG, "onError() " + exception.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
MediaManager.enqueue(mediaBrowserListenableFuture, context, (List<Media>) media,false);
|
||||
}
|
||||
});
|
||||
click.onMediaClick(bundle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -10,29 +11,30 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Genre;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GenreAdapter extends RecyclerView.Adapter<GenreAdapter.ViewHolder> {
|
||||
private static final String TAG = "GenreAdapter";
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private final Context context;
|
||||
private ClickCallback click;
|
||||
|
||||
private List<Genre> genres;
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
public GenreAdapter(Context context) {
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.genres = new ArrayList<>();
|
||||
public GenreAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.click = click;
|
||||
this.genres = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_library_genre, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_library_genre, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -57,15 +59,7 @@ public class GenreAdapter extends RecyclerView.Adapter<GenreAdapter.ViewHolder>
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setClickListener(ItemClickListener itemClickListener) {
|
||||
this.itemClickListener = itemClickListener;
|
||||
}
|
||||
|
||||
public interface ItemClickListener {
|
||||
void onItemClick(View view, int position);
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textGenre;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
|
|
@ -73,13 +67,15 @@ public class GenreAdapter extends RecyclerView.Adapter<GenreAdapter.ViewHolder>
|
|||
|
||||
textGenre = itemView.findViewById(R.id.genre_label);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (itemClickListener != null)
|
||||
itemClickListener.onItemClick(view, getBindingAdapterPosition());
|
||||
private void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Media.BY_GENRE, Media.BY_GENRE);
|
||||
bundle.putParcelable("genre_object", genres.get(getBindingAdapterPosition()));
|
||||
|
||||
click.onGenreClick(bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
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;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.TextView;
|
||||
|
|
@ -13,8 +13,9 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Genre;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
|
||||
|
|
@ -24,10 +25,9 @@ import java.util.Comparator;
|
|||
import java.util.List;
|
||||
|
||||
public class GenreCatalogueAdapter extends RecyclerView.Adapter<GenreCatalogueAdapter.ViewHolder> implements Filterable {
|
||||
private static final String TAG = "GenreCatalogueAdapter";
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private final MainActivity activity;
|
||||
private final Filter filtering = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
|
|
@ -61,18 +61,17 @@ public class GenreCatalogueAdapter extends RecyclerView.Adapter<GenreCatalogueAd
|
|||
|
||||
private List<Genre> genres;
|
||||
private List<Genre> genresFull;
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
public GenreCatalogueAdapter(MainActivity activity, Context context) {
|
||||
this.activity = activity;
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.genres = new ArrayList<>();
|
||||
public GenreCatalogueAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.click = click;
|
||||
this.genres = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_library_catalogue_genre, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_library_catalogue_genre, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -98,20 +97,12 @@ public class GenreCatalogueAdapter extends RecyclerView.Adapter<GenreCatalogueAd
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setClickListener(ItemClickListener itemClickListener) {
|
||||
this.itemClickListener = itemClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return filtering;
|
||||
}
|
||||
|
||||
public interface ItemClickListener {
|
||||
void onItemClick(View view, int position);
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textGenre;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
|
|
@ -119,17 +110,13 @@ public class GenreCatalogueAdapter extends RecyclerView.Adapter<GenreCatalogueAd
|
|||
|
||||
textGenre = itemView.findViewById(R.id.genre_label);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
}
|
||||
itemView.setOnClickListener(v -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Media.BY_GENRE, Media.BY_GENRE);
|
||||
bundle.putParcelable("genre_object", genres.get(getBindingAdapterPosition()));
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (itemClickListener != null) {
|
||||
itemClickListener.onItemClick(view, getBindingAdapterPosition());
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
click.onGenreClick(bundle);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,50 +1,42 @@
|
|||
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;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
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.Chronology;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.service.MediaManager;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GridTrackAdapter extends RecyclerView.Adapter<GridTrackAdapter.ViewHolder> {
|
||||
private static final String TAG = "SimilarTrackAdapter";
|
||||
|
||||
private final MainActivity activity;
|
||||
private final Context context;
|
||||
private final LayoutInflater mInflater;
|
||||
private final ClickCallback click;
|
||||
|
||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||
private List<Chronology> items;
|
||||
|
||||
public GridTrackAdapter(MainActivity activity, Context context) {
|
||||
this.activity = activity;
|
||||
public GridTrackAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.items = new ArrayList<>();
|
||||
this.click = click;
|
||||
this.items = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_home_grid_track, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_home_grid_track, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -73,11 +65,7 @@ public class GridTrackAdapter extends RecyclerView.Adapter<GridTrackAdapter.View
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setMediaBrowserListenableFuture(ListenableFuture<MediaBrowser> mediaBrowserListenableFuture) {
|
||||
this.mediaBrowserListenableFuture = mediaBrowserListenableFuture;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView cover;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
|
|
@ -85,14 +73,16 @@ public class GridTrackAdapter extends RecyclerView.Adapter<GridTrackAdapter.View
|
|||
|
||||
cover = itemView.findViewById(R.id.track_cover_image_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
List<Media> media = MappingUtil.mapChronology(items);
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, context, media, getBindingAdapterPosition());
|
||||
activity.setBottomSheetInPeek(true);
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelableArrayList("songs_object", new ArrayList<>(items));
|
||||
bundle.putBoolean("is_chronology", true);
|
||||
bundle.putInt("position", getBindingAdapterPosition());
|
||||
|
||||
click.onMediaClick(bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,122 +0,0 @@
|
|||
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;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.ui.dialog.PlaylistEditorDialog;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHolder> {
|
||||
private static final String TAG = "PlaylistAdapter";
|
||||
|
||||
private final MainActivity activity;
|
||||
private final Context context;
|
||||
private final LayoutInflater mInflater;
|
||||
private final boolean isDownloaded;
|
||||
|
||||
private List<Playlist> playlists;
|
||||
|
||||
public PlaylistAdapter(MainActivity activity, Context context, boolean isDownloaded) {
|
||||
this.activity = activity;
|
||||
this.context = context;
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.playlists = new ArrayList<>();
|
||||
this.isDownloaded = isDownloaded;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_library_playlist, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
Playlist playlist = playlists.get(position);
|
||||
|
||||
holder.textPlaylistName.setText(MusicUtil.getReadableString(playlist.getName()));
|
||||
holder.textPlaylistSongCount.setText(context.getString(R.string.playlist_info_song_count, playlist.getSongCount()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, playlist.getPrimary(), CustomGlideRequest.PLAYLIST_PIC, null)
|
||||
.build()
|
||||
.into(holder.cover);
|
||||
|
||||
if (isDownloaded) holder.textPlaylistSongCount.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return playlists.size();
|
||||
}
|
||||
|
||||
public Playlist getItem(int position) {
|
||||
return playlists.get(position);
|
||||
}
|
||||
|
||||
public void setItems(List<Playlist> playlists) {
|
||||
this.playlists = playlists;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
TextView textPlaylistName;
|
||||
TextView textPlaylistSongCount;
|
||||
ImageView cover;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
textPlaylistName = itemView.findViewById(R.id.playlist_name_text);
|
||||
textPlaylistSongCount = itemView.findViewById(R.id.playlist_song_counter_text);
|
||||
cover = itemView.findViewById(R.id.playlist_cover_image_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
if (!isDownloaded) itemView.setOnLongClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("playlist_object", playlists.get(getBindingAdapterPosition()));
|
||||
|
||||
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
|
||||
bundle.putBoolean("is_offline", false);
|
||||
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_playlistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.downloadFragment) {
|
||||
bundle.putBoolean("is_offline", true);
|
||||
Navigation.findNavController(view).navigate(R.id.action_downloadFragment_to_playlistPageFragment, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("playlist_object", playlists.get(getBindingAdapterPosition()));
|
||||
|
||||
PlaylistEditorDialog dialog = new PlaylistEditorDialog();
|
||||
dialog.setArguments(bundle);
|
||||
dialog.show(activity.getSupportFragmentManager(), null);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
@ -10,38 +11,32 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.ui.dialog.PlaylistChooserDialog;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
import com.cappielloantonio.play.viewmodel.PlaylistChooserViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PlaylistDialogHorizontalAdapter extends RecyclerView.Adapter<PlaylistDialogHorizontalAdapter.ViewHolder> {
|
||||
private static final String TAG = "PlaylistDialogHorizontalAdapter";
|
||||
|
||||
private final Context context;
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
private final PlaylistChooserViewModel playlistChooserViewModel;
|
||||
private final PlaylistChooserDialog playlistChooserDialog;
|
||||
private final ClickCallback click;
|
||||
|
||||
private List<Playlist> playlists;
|
||||
|
||||
public PlaylistDialogHorizontalAdapter(Context context, PlaylistChooserViewModel playlistChooserViewModel, PlaylistChooserDialog playlistChooserDialog) {
|
||||
public PlaylistDialogHorizontalAdapter(Context context,ClickCallback click) {
|
||||
this.context = context;
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.playlists = new ArrayList<>();
|
||||
|
||||
this.playlistChooserViewModel = playlistChooserViewModel;
|
||||
this.playlistChooserDialog = playlistChooserDialog;
|
||||
this.click = click;
|
||||
this.playlists = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_horizontal_playlist_dialog, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_horizontal_playlist_dialog, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +63,7 @@ public class PlaylistDialogHorizontalAdapter extends RecyclerView.Adapter<Playli
|
|||
return playlists.get(id);
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView playlistTitle;
|
||||
TextView playlistTrackCount;
|
||||
TextView playlistDuration;
|
||||
|
|
@ -80,15 +75,18 @@ public class PlaylistDialogHorizontalAdapter extends RecyclerView.Adapter<Playli
|
|||
playlistTrackCount = itemView.findViewById(R.id.playlist_dialog_count_text_view);
|
||||
playlistDuration = itemView.findViewById(R.id.playlist_dialog_duration_text_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
|
||||
playlistTitle.setSelected(true);
|
||||
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
playlistChooserViewModel.addSongToPlaylist(playlists.get(getBindingAdapterPosition()).getId());
|
||||
playlistChooserDialog.dismiss();
|
||||
public void onClick() {
|
||||
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("playlist_object", playlists.get(getBindingAdapterPosition()));
|
||||
|
||||
click.onPlaylistClick(bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,26 +17,23 @@ import com.cappielloantonio.play.glide.CustomGlideRequest;
|
|||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PlaylistDialogSongHorizontalAdapter extends RecyclerView.Adapter<PlaylistDialogSongHorizontalAdapter.ViewHolder> {
|
||||
private static final String TAG = "PlaylistDialogSongHorizontalAdapter";
|
||||
private final Context context;
|
||||
|
||||
private List<Media> songs;
|
||||
private final LayoutInflater mInflater;
|
||||
private final Context context;
|
||||
|
||||
public PlaylistDialogSongHorizontalAdapter(Context context) {
|
||||
this.context = context;
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.songs = new ArrayList<>();
|
||||
this.songs = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_horizontal_playlist_dialog_track, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_horizontal_playlist_dialog_track, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,38 +5,30 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.model.Genre;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.ui.dialog.PlaylistEditorDialog;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PlaylistHorizontalAdapter extends RecyclerView.Adapter<PlaylistHorizontalAdapter.ViewHolder> implements Filterable {
|
||||
private static final String TAG = "PlaylistDialogHorizontalAdapter";
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
|
||||
private List<Playlist> playlists;
|
||||
private List<Playlist> playlistsFull;
|
||||
|
||||
private final MainActivity activity;
|
||||
private final Context context;
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
private final Filter filtering = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
|
|
@ -68,17 +60,16 @@ public class PlaylistHorizontalAdapter extends RecyclerView.Adapter<PlaylistHori
|
|||
}
|
||||
};
|
||||
|
||||
public PlaylistHorizontalAdapter(MainActivity activity, Context context) {
|
||||
this.activity = activity;
|
||||
public PlaylistHorizontalAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.playlists = new ArrayList<>();
|
||||
this.click = click;
|
||||
this.playlists = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_horizontal_playlist, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_horizontal_playlist, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +102,7 @@ public class PlaylistHorizontalAdapter extends RecyclerView.Adapter<PlaylistHori
|
|||
return filtering;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView playlistTitle;
|
||||
TextView playlistTrackCount;
|
||||
TextView playlistDuration;
|
||||
|
|
@ -123,42 +114,26 @@ public class PlaylistHorizontalAdapter extends RecyclerView.Adapter<PlaylistHori
|
|||
playlistTrackCount = itemView.findViewById(R.id.playlist_dialog_count_text_view);
|
||||
playlistDuration = itemView.findViewById(R.id.playlist_dialog_duration_text_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
|
||||
playlistTitle.setSelected(true);
|
||||
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
itemView.setOnLongClickListener(v -> onLongClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("playlist_object", playlists.get(getBindingAdapterPosition()));
|
||||
|
||||
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
|
||||
bundle.putBoolean("is_offline", false);
|
||||
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_playlistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.downloadFragment) {
|
||||
bundle.putBoolean("is_offline", true);
|
||||
Navigation.findNavController(view).navigate(R.id.action_downloadFragment_to_playlistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.playlistCatalogueFragment) {
|
||||
bundle.putBoolean("is_offline", false);
|
||||
Navigation.findNavController(view).navigate(R.id.action_playlistCatalogueFragment_to_playlistPageFragment, bundle);
|
||||
}
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
click.onPlaylistClick(bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
public boolean onLongClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("playlist_object", playlists.get(getBindingAdapterPosition()));
|
||||
|
||||
PlaylistEditorDialog dialog = new PlaylistEditorDialog();
|
||||
dialog.setArguments(bundle);
|
||||
dialog.show(activity.getSupportFragmentManager(), null);
|
||||
click.onPlaylistLongClick(bundle);
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,45 +10,36 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
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.Media;
|
||||
import com.cappielloantonio.play.service.MediaManager;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAdapter.ViewHolder> {
|
||||
private static final String TAG = "DiscoverSongAdapter";
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
private final Context context;
|
||||
private final MainActivity activity;
|
||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||
private final ClickCallback click;
|
||||
|
||||
private List<Media> podcastEpisodes;
|
||||
|
||||
public PodcastEpisodeAdapter(MainActivity activity, Context context) {
|
||||
this.activity = activity;
|
||||
public PodcastEpisodeAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
this.podcastEpisodes = new ArrayList<>();
|
||||
this.click = click;
|
||||
this.podcastEpisodes = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = inflater.inflate(R.layout.item_home_podcast_episode, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_home_podcast_episode, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -79,11 +70,7 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAd
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setMediaBrowserListenableFuture(ListenableFuture<MediaBrowser> mediaBrowserListenableFuture) {
|
||||
this.mediaBrowserListenableFuture = mediaBrowserListenableFuture;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textTitle;
|
||||
TextView textSubtitle;
|
||||
TextView textReleaseAndDuration;
|
||||
|
|
@ -103,21 +90,25 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAd
|
|||
playButton = itemView.findViewById(R.id.podcast_play_button);
|
||||
moreButton = itemView.findViewById(R.id.podcast_more_button);
|
||||
|
||||
playButton.setOnClickListener(this);
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
|
||||
moreButton.setOnClickListener(this::openMore);
|
||||
moreButton.setOnLongClickListener(v -> openMore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, context, podcastEpisodes.get(getBindingAdapterPosition()));
|
||||
activity.setBottomSheetInPeek(true);
|
||||
}
|
||||
|
||||
private void openMore(View view) {
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("podcast_object", podcastEpisodes.get(getBindingAdapterPosition()));
|
||||
Navigation.findNavController(view).navigate(R.id.podcastBottomSheetDialog, bundle);
|
||||
|
||||
click.onPodcastClick(bundle);
|
||||
}
|
||||
|
||||
private boolean openMore() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("podcast_object", podcastEpisodes.get(getBindingAdapterPosition()));
|
||||
|
||||
click.onPodcastLongClick(bundle);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,43 +6,33 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.interfaces.SystemCallback;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Server;
|
||||
import com.cappielloantonio.play.repository.SystemRepository;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.ui.dialog.ServerSignupDialog;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.ViewHolder> {
|
||||
private static final String TAG = "ServerAdapter";
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private final MainActivity mainActivity;
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
|
||||
private List<Server> servers;
|
||||
|
||||
public ServerAdapter(MainActivity mainActivity, Context context) {
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.servers = new ArrayList<>();
|
||||
this.mainActivity = mainActivity;
|
||||
public ServerAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.click = click;
|
||||
this.servers = new ArrayList<>();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_login_server, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_login_server, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +58,7 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.ViewHolder
|
|||
return servers.get(id);
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView serverName;
|
||||
TextView serverAddress;
|
||||
|
||||
|
|
@ -78,68 +68,26 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.ViewHolder
|
|||
serverName = itemView.findViewById(R.id.server_name_text_view);
|
||||
serverAddress = itemView.findViewById(R.id.server_address_text_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
|
||||
serverName.setSelected(true);
|
||||
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
itemView.setOnLongClickListener(v -> onLongClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Server server = servers.get(getBindingAdapterPosition());
|
||||
saveServerPreference(server.getServerId(), server.getAddress(), server.getUsername(), server.getPassword(), server.isLowSecurity());
|
||||
|
||||
SystemRepository systemRepository = new SystemRepository(App.getInstance());
|
||||
systemRepository.checkUserCredential(new SystemCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
resetServerPreference();
|
||||
Toast.makeText(context, exception.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String password, String token, String salt) {
|
||||
enter();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("server_object", servers.get(getBindingAdapterPosition()));
|
||||
|
||||
ServerSignupDialog dialog = new ServerSignupDialog();
|
||||
dialog.setArguments(bundle);
|
||||
dialog.show(mainActivity.getSupportFragmentManager(), null);
|
||||
|
||||
return true;
|
||||
click.onServerClick(bundle);
|
||||
}
|
||||
|
||||
private void enter() {
|
||||
mainActivity.goFromLogin();
|
||||
}
|
||||
public boolean onLongClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("server_object", servers.get(getBindingAdapterPosition()));
|
||||
|
||||
private void saveServerPreference(String serverId, String server, String user, String password, boolean isLowSecurity) {
|
||||
PreferenceUtil.getInstance(context).setServerId(serverId);
|
||||
PreferenceUtil.getInstance(context).setServer(server);
|
||||
PreferenceUtil.getInstance(context).setUser(user);
|
||||
PreferenceUtil.getInstance(context).setPassword(password);
|
||||
PreferenceUtil.getInstance(context).setLowSecurity(isLowSecurity);
|
||||
click.onServerLongClick(bundle);
|
||||
|
||||
App.getSubsonicClientInstance(context, true);
|
||||
}
|
||||
|
||||
private void resetServerPreference() {
|
||||
PreferenceUtil.getInstance(context).setServerId(null);
|
||||
PreferenceUtil.getInstance(context).setServer(null);
|
||||
PreferenceUtil.getInstance(context).setUser(null);
|
||||
PreferenceUtil.getInstance(context).setPassword(null);
|
||||
PreferenceUtil.getInstance(context).setToken(null);
|
||||
PreferenceUtil.getInstance(context).setSalt(null);
|
||||
PreferenceUtil.getInstance(context).setLowSecurity(false);
|
||||
|
||||
App.getSubsonicClientInstance(context, true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.cappielloantonio.play.adapter;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -10,47 +9,36 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
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.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.service.MediaManager;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
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 SimilarTrackAdapter extends RecyclerView.Adapter<SimilarTrackAdapter.ViewHolder> {
|
||||
private static final String TAG = "SimilarTrackAdapter";
|
||||
|
||||
private final MainActivity activity;
|
||||
private final Context context;
|
||||
private final LayoutInflater mInflater;
|
||||
private final ClickCallback click;
|
||||
|
||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||
private List<Media> songs;
|
||||
|
||||
public SimilarTrackAdapter(MainActivity activity, Context context) {
|
||||
this.activity = activity;
|
||||
public SimilarTrackAdapter(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_home_similar_track, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_home_similar_track, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -81,11 +69,7 @@ public class SimilarTrackAdapter extends RecyclerView.Adapter<SimilarTrackAdapte
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setMediaBrowserListenableFuture(ListenableFuture<MediaBrowser> mediaBrowserListenableFuture) {
|
||||
this.mediaBrowserListenableFuture = mediaBrowserListenableFuture;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textTitle;
|
||||
ImageView cover;
|
||||
|
||||
|
|
@ -95,35 +79,25 @@ public class SimilarTrackAdapter extends RecyclerView.Adapter<SimilarTrackAdapte
|
|||
textTitle = itemView.findViewById(R.id.title_track_label);
|
||||
cover = itemView.findViewById(R.id.track_cover_image_view);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
itemView.setOnLongClickListener(v -> onLongClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, context, songs.get(getBindingAdapterPosition()));
|
||||
activity.setBottomSheetInPeek(true);
|
||||
|
||||
SongRepository songRepository = new SongRepository(App.getInstance());
|
||||
songRepository.getInstantMix(songs.get(getBindingAdapterPosition()), 20, new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
Log.e(TAG, "onError() " + exception.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
MediaManager.enqueue(mediaBrowserListenableFuture, context, (List<Media>) media, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("song_object", songs.get(getBindingAdapterPosition()));
|
||||
Navigation.findNavController(view).navigate(R.id.songBottomSheetDialog, bundle);
|
||||
return true;
|
||||
bundle.putBoolean("is_mix", true);
|
||||
|
||||
click.onMediaClick(bundle);
|
||||
}
|
||||
|
||||
public boolean onLongClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("song_object", songs.get(getBindingAdapterPosition()));
|
||||
|
||||
click.onMediaLongClick(bundle);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ 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.ui.activity.MainActivity;
|
||||
|
|
@ -27,32 +28,28 @@ 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;
|
||||
|
||||
@UnstableApi
|
||||
public class SongHorizontalAdapter extends RecyclerView.Adapter<SongHorizontalAdapter.ViewHolder> {
|
||||
private static final String TAG = "SongHorizontalAdapter";
|
||||
|
||||
private final MainActivity mainActivity;
|
||||
private final Context context;
|
||||
private final LayoutInflater mInflater;
|
||||
private final ClickCallback click;
|
||||
private final boolean isCoverVisible;
|
||||
|
||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||
private List<Media> songs;
|
||||
|
||||
public SongHorizontalAdapter(MainActivity mainActivity, Context context, boolean isCoverVisible) {
|
||||
this.mainActivity = mainActivity;
|
||||
public SongHorizontalAdapter(Context context, ClickCallback click, boolean isCoverVisible) {
|
||||
this.context = context;
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.songs = new ArrayList<>();
|
||||
this.click = click;
|
||||
this.isCoverVisible = isCoverVisible;
|
||||
this.songs = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_horizontal_track, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_horizontal_track, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -95,15 +92,11 @@ public class SongHorizontalAdapter extends RecyclerView.Adapter<SongHorizontalAd
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setMediaBrowserListenableFuture(ListenableFuture<MediaBrowser> mediaBrowserListenableFuture) {
|
||||
this.mediaBrowserListenableFuture = mediaBrowserListenableFuture;
|
||||
}
|
||||
|
||||
public Media getItem(int id) {
|
||||
return songs.get(id);
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
View differentDiscDivider;
|
||||
TextView songTitle;
|
||||
TextView songSubtitle;
|
||||
|
|
@ -125,31 +118,30 @@ public class SongHorizontalAdapter extends RecyclerView.Adapter<SongHorizontalAd
|
|||
cover = itemView.findViewById(R.id.song_cover_image_view);
|
||||
coverSeparator = itemView.findViewById(R.id.cover_image_separator);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
|
||||
more.setOnClickListener(this::openMore);
|
||||
|
||||
songTitle.setSelected(true);
|
||||
songSubtitle.setSelected(true);
|
||||
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
itemView.setOnLongClickListener(v -> onLongClick());
|
||||
|
||||
more.setOnClickListener(v -> onLongClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, context, songs, getBindingAdapterPosition());
|
||||
mainActivity.setBottomSheetInPeek(true);
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelableArrayList("songs_object", new ArrayList<>(songs));
|
||||
bundle.putInt("position", getBindingAdapterPosition());
|
||||
|
||||
click.onMediaClick(bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
openMore(v);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void openMore(View view) {
|
||||
private boolean onLongClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("song_object", songs.get(getBindingAdapterPosition()));
|
||||
Navigation.findNavController(view).navigate(R.id.songBottomSheetDialog, bundle);
|
||||
|
||||
click.onMediaLongClick(bundle);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -10,27 +11,28 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class YearAdapter extends RecyclerView.Adapter<YearAdapter.ViewHolder> {
|
||||
private static final String TAG = "YearAdapter";
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
|
||||
private List<Integer> years;
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
public YearAdapter(Context context) {
|
||||
this.mInflater = LayoutInflater.from(context);
|
||||
this.years = new ArrayList<>();
|
||||
public YearAdapter(Context context, ClickCallback click) {
|
||||
this.context = context;
|
||||
this.click = click;
|
||||
this.years = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = mInflater.inflate(R.layout.item_home_year, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_home_year, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
|
|
@ -55,15 +57,7 @@ public class YearAdapter extends RecyclerView.Adapter<YearAdapter.ViewHolder> {
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setClickListener(ItemClickListener itemClickListener) {
|
||||
this.itemClickListener = itemClickListener;
|
||||
}
|
||||
|
||||
public interface ItemClickListener {
|
||||
void onItemClick(View view, int position);
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textYear;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
|
|
@ -71,13 +65,15 @@ public class YearAdapter extends RecyclerView.Adapter<YearAdapter.ViewHolder> {
|
|||
|
||||
textYear = itemView.findViewById(R.id.year_label);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnClickListener(v -> onClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (itemClickListener != null)
|
||||
itemClickListener.onItemClick(view, getBindingAdapterPosition());
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Media.BY_YEAR, Media.BY_YEAR);
|
||||
bundle.putInt("year_object", years.get(getBindingAdapterPosition()));
|
||||
|
||||
click.onYearClick(bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue