mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Added similar items in artist page
This commit is contained in:
parent
214c803984
commit
9312d0e203
4 changed files with 180 additions and 0 deletions
|
|
@ -0,0 +1,96 @@
|
||||||
|
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.navigation.Navigation;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.R;
|
||||||
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||||
|
import com.cappielloantonio.play.model.Album;
|
||||||
|
import com.cappielloantonio.play.model.Artist;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ArtistSimilarAdapter extends RecyclerView.Adapter<ArtistSimilarAdapter.ViewHolder> {
|
||||||
|
private static final String TAG = "AlbumArtistPageAdapter";
|
||||||
|
|
||||||
|
private List<Artist> artists;
|
||||||
|
private LayoutInflater inflater;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public ArtistSimilarAdapter(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
this.inflater = LayoutInflater.from(context);
|
||||||
|
this.artists = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View view = inflater.inflate(R.layout.item_library_similar_artist, parent, false);
|
||||||
|
return new ViewHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||||
|
Artist artist = artists.get(position);
|
||||||
|
|
||||||
|
holder.textArtistName.setText(artist.getName());
|
||||||
|
|
||||||
|
CustomGlideRequest.Builder
|
||||||
|
.from(context, artist.getPrimary(), artist.getPrimaryBlurHash(), CustomGlideRequest.PRIMARY, CustomGlideRequest.LOW_QUALITY, CustomGlideRequest.ALBUM_PIC)
|
||||||
|
.build()
|
||||||
|
.into(holder.cover);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return artists.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Artist getItem(int position) {
|
||||||
|
return artists.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItems(List<Artist> artists) {
|
||||||
|
this.artists = artists;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
|
TextView textArtistName;
|
||||||
|
ImageView cover;
|
||||||
|
|
||||||
|
ViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
textArtistName = itemView.findViewById(R.id.artist_name_label);
|
||||||
|
cover = itemView.findViewById(R.id.similar_artist_cover_image_view);
|
||||||
|
|
||||||
|
itemView.setOnClickListener(this);
|
||||||
|
itemView.setOnLongClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||||
|
Navigation.findNavController(view).navigate(R.id.artistPageFragment, bundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View view) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||||
|
Navigation.findNavController(view).navigate(R.id.artistBottomSheetDialog, bundle);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,10 +17,13 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.adapter.AlbumArtistPageOrSimilarAdapter;
|
import com.cappielloantonio.play.adapter.AlbumArtistPageOrSimilarAdapter;
|
||||||
|
import com.cappielloantonio.play.adapter.ArtistSimilarAdapter;
|
||||||
import com.cappielloantonio.play.adapter.SongResultSearchAdapter;
|
import com.cappielloantonio.play.adapter.SongResultSearchAdapter;
|
||||||
import com.cappielloantonio.play.databinding.FragmentArtistPageBinding;
|
import com.cappielloantonio.play.databinding.FragmentArtistPageBinding;
|
||||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||||
|
import com.cappielloantonio.play.model.Album;
|
||||||
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.repository.QueueRepository;
|
import com.cappielloantonio.play.repository.QueueRepository;
|
||||||
|
|
@ -40,6 +43,7 @@ public class ArtistPageFragment extends Fragment {
|
||||||
|
|
||||||
private SongResultSearchAdapter songResultSearchAdapter;
|
private SongResultSearchAdapter songResultSearchAdapter;
|
||||||
private AlbumArtistPageOrSimilarAdapter albumArtistPageOrSimilarAdapter;
|
private AlbumArtistPageOrSimilarAdapter albumArtistPageOrSimilarAdapter;
|
||||||
|
private ArtistSimilarAdapter artistSimilarAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||||
|
|
@ -61,6 +65,7 @@ public class ArtistPageFragment extends Fragment {
|
||||||
initPlayButtons();
|
initPlayButtons();
|
||||||
initTopSongsView();
|
initTopSongsView();
|
||||||
initAlbumsView();
|
initAlbumsView();
|
||||||
|
initSimilarArtistsView();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
@ -162,4 +167,24 @@ public class ArtistPageFragment extends Fragment {
|
||||||
bind.albumsRecyclerView.setAdapter(albumArtistPageOrSimilarAdapter);
|
bind.albumsRecyclerView.setAdapter(albumArtistPageOrSimilarAdapter);
|
||||||
artistPageViewModel.getAlbumList().observe(requireActivity(), songs -> albumArtistPageOrSimilarAdapter.setItems(songs));
|
artistPageViewModel.getAlbumList().observe(requireActivity(), songs -> albumArtistPageOrSimilarAdapter.setItems(songs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initSimilarArtistsView() {
|
||||||
|
SyncUtil.getSimilarItems(requireContext(), new MediaCallback() {
|
||||||
|
@Override
|
||||||
|
public void onError(Exception exception) {
|
||||||
|
Toast.makeText(requireContext(), "Error retrieving similar items", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadMedia(List<?> media) {
|
||||||
|
bind.similarArtistSector.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
bind.similarArtistsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||||
|
|
||||||
|
artistSimilarAdapter = new ArtistSimilarAdapter(requireContext());
|
||||||
|
bind.similarArtistsRecyclerView.setAdapter(artistSimilarAdapter);
|
||||||
|
artistSimilarAdapter.setItems((ArrayList<Artist>) media);
|
||||||
|
}
|
||||||
|
}, SyncUtil.ARTIST, artistPageViewModel.getArtist().getId(), PreferenceUtil.getInstance(requireContext()).getSimilarItemsNumber());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -169,6 +169,35 @@
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="8dp"
|
||||||
android:paddingBottom="8dp" />
|
android:paddingBottom="8dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/similar_artist_sector"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/HeadlineTextView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
|
android:text="More like this" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/similar_artists_recycler_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:paddingBottom="8dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
30
app/src/main/res/layout/item_library_similar_artist.xml
Normal file
30
app/src/main/res/layout/item_library_similar_artist.xml
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingEnd="8dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/similar_artist_cover_image_view"
|
||||||
|
android:layout_width="256dp"
|
||||||
|
android:layout_height="256dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/artist_name_label"
|
||||||
|
style="@style/ItemTitleTextView"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxWidth="256dp"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:singleLine="false"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/similar_artist_cover_image_view" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue