Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ import kotlinx.parcelize.Parcelize
class ArtistWithAlbumsID3(
@SerializedName("album")
var albums: List<AlbumID3>? = null,
@SerializedName("appearsOn")
var appearsOn: List<AlbumID3>? = null,
) : ArtistID3(), Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.cappielloantonio.tempo.ui.adapter;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.cappielloantonio.tempo.databinding.ItemAlbumCarouselBinding;
import com.cappielloantonio.tempo.glide.CustomGlideRequest;
import com.cappielloantonio.tempo.interfaces.ClickCallback;
import com.cappielloantonio.tempo.subsonic.models.AlbumID3;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.TileSizeManager;

import java.util.Collections;
import java.util.List;

public class AlbumCarouselAdapter extends RecyclerView.Adapter<AlbumCarouselAdapter.ViewHolder> {
private final ClickCallback click;
private List<AlbumID3> albums;
private boolean showArtist;
private int sizePx = 400;

public AlbumCarouselAdapter(ClickCallback click, boolean showArtist) {
this.click = click;
this.albums = Collections.emptyList();
this.showArtist = showArtist;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemAlbumCarouselBinding view = ItemAlbumCarouselBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
TileSizeManager.getInstance().calculateTileSize(parent.getContext());
sizePx = TileSizeManager.getInstance().getTileSizePx(parent.getContext());
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

ViewGroup.LayoutParams lp = holder.item.albumCoverImageView.getLayoutParams();
lp.width = sizePx;
lp.height = sizePx;
holder.item.albumCoverImageView.setLayoutParams(lp);

AlbumID3 album = albums.get(position);

holder.item.albumNameLabel.setText(album.getName());
holder.item.artistNameLabel.setText(album.getArtist());
holder.item.artistNameLabel.setVisibility(showArtist ? View.VISIBLE : View.GONE);

CustomGlideRequest.Builder
.from(holder.itemView.getContext(), album.getCoverArtId(), CustomGlideRequest.ResourceType.Album)
.build()
.into(holder.item.albumCoverImageView);
}

@Override
public int getItemCount() {
return albums.size();
}

public void setItems(List<AlbumID3> albums) {
this.albums = albums;
notifyDataSetChanged();
}

public class ViewHolder extends RecyclerView.ViewHolder {
ItemAlbumCarouselBinding item;

ViewHolder(ItemAlbumCarouselBinding item) {
super(item.getRoot());
this.item = item;

itemView.setOnClickListener(v -> {
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.ALBUM_OBJECT, albums.get(getBindingAdapterPosition()));
click.onAlbumClick(bundle);
});

itemView.setOnLongClickListener(v -> {
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.ALBUM_OBJECT, albums.get(getBindingAdapterPosition()));
click.onAlbumLongClick(bundle);
return true;
});

item.albumNameLabel.setSelected(true);
item.artistNameLabel.setSelected(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.cappielloantonio.tempo.ui.adapter;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.cappielloantonio.tempo.databinding.ItemArtistCarouselBinding;
import com.cappielloantonio.tempo.glide.CustomGlideRequest;
import com.cappielloantonio.tempo.interfaces.ClickCallback;
import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.TileSizeManager;

import java.util.Collections;
import java.util.List;

public class ArtistCarouselAdapter extends RecyclerView.Adapter<ArtistCarouselAdapter.ViewHolder> {
private final ClickCallback click;
private List<ArtistID3> artists;
private int sizePx = 400;

public ArtistCarouselAdapter(ClickCallback click) {
this.click = click;
this.artists = Collections.emptyList();
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemArtistCarouselBinding view = ItemArtistCarouselBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
TileSizeManager.getInstance().calculateTileSize(parent.getContext());
sizePx = TileSizeManager.getInstance().getTileSizePx(parent.getContext());
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

ViewGroup.LayoutParams lp = holder.item.artistCoverImageView.getLayoutParams();
lp.width = sizePx;
lp.height = sizePx;
holder.item.artistCoverImageView.setLayoutParams(lp);

ArtistID3 artist = artists.get(position);

holder.item.artistNameLabel.setText(artist.getName());

CustomGlideRequest.Builder
.from(holder.itemView.getContext(), artist.getCoverArtId(), CustomGlideRequest.ResourceType.Artist)
.build()
.into(holder.item.artistCoverImageView);
}

@Override
public int getItemCount() {
return artists.size();
}

public void setItems(List<ArtistID3> artists) {
this.artists = artists;
notifyDataSetChanged();
}

public class ViewHolder extends RecyclerView.ViewHolder {
ItemArtistCarouselBinding item;

ViewHolder(ItemArtistCarouselBinding item) {
super(item.getRoot());
this.item = item;

itemView.setOnClickListener(v -> {
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.ARTIST_OBJECT, artists.get(getBindingAdapterPosition()));
click.onArtistClick(bundle);
});

itemView.setOnLongClickListener(v -> {
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.ARTIST_OBJECT, artists.get(getBindingAdapterPosition()));
click.onArtistLongClick(bundle);
return true;
});

item.artistNameLabel.setSelected(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ private void init() {
albumListPageViewModel.artist = requireArguments().getParcelable(Constants.ARTIST_OBJECT);
albumListPageViewModel.title = Constants.ALBUM_FROM_ARTIST;
bind.pageTitleLabel.setText(albumListPageViewModel.artist.getName());
} else if (requireArguments().getParcelableArrayList(Constants.ALBUMS_OBJECT) != null) {
albumListPageViewModel.albums = requireArguments().getParcelableArrayList(Constants.ALBUMS_OBJECT);
albumListPageViewModel.title = requireArguments().getString(Constants.ALBUM_LIST_TITLE, "");
bind.pageTitleLabel.setText(albumListPageViewModel.title);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
import com.cappielloantonio.tempo.subsonic.models.Child;
import com.cappielloantonio.tempo.ui.activity.MainActivity;
import com.cappielloantonio.tempo.ui.adapter.AlbumCatalogueAdapter;
import com.cappielloantonio.tempo.ui.adapter.AlbumCarouselAdapter;
import com.cappielloantonio.tempo.ui.adapter.ArtistCarouselAdapter;
import com.cappielloantonio.tempo.ui.adapter.ArtistCatalogueAdapter;
import com.cappielloantonio.tempo.ui.adapter.SongHorizontalAdapter;
import com.cappielloantonio.tempo.util.Constants;
Expand All @@ -60,8 +61,11 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
private PlaybackViewModel playbackViewModel;

private SongHorizontalAdapter songHorizontalAdapter;
private AlbumCatalogueAdapter albumCatalogueAdapter;
private ArtistCatalogueAdapter artistCatalogueAdapter;
private AlbumCarouselAdapter mainAlbumAdapter;
private AlbumCarouselAdapter epAdapter;
private AlbumCarouselAdapter singleAdapter;
private AlbumCarouselAdapter appearsOnAdapter;
private ArtistCarouselAdapter similarArtistAdapter;

private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;

Expand All @@ -86,7 +90,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
initArtistInfo();
initPlayButtons();
initTopSongsView();
initAlbumsView();
initCategorizedAlbumsView();
initSimilarArtistsView();

return view;
Expand Down Expand Up @@ -120,6 +124,7 @@ public void onDestroyView() {

private void init(View view) {
artistPageViewModel.setArtist(requireArguments().getParcelable(Constants.ARTIST_OBJECT));
artistPageViewModel.fetchCategorizedAlbums(getViewLifecycleOwner());

bind.mostStreamedSongTextViewClickable.setOnClickListener(v -> {
Bundle bundle = new Bundle();
Expand Down Expand Up @@ -277,40 +282,96 @@ private void initTopSongsView() {
if (songs == null) {
if (bind != null) bind.artistPageTopSongsSector.setVisibility(View.GONE);
} else {
if (bind != null)
if (bind != null) {
bind.artistPageTopSongsSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE);
songHorizontalAdapter.setItems(songs);
bind.mostStreamedSongTextViewClickable.setVisibility(songs.size() > 3 ? View.VISIBLE : View.GONE);
}
songHorizontalAdapter.setItems(songs.stream().limit(3).collect(java.util.stream.Collectors.toList()));
reapplyPlayback();
}
});
}

private void initAlbumsView() {
bind.albumsRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), spanCount));
bind.albumsRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, tileSpacing, false));
bind.albumsRecyclerView.setHasFixedSize(true);
private void initCategorizedAlbumsView() {
// Main Albums
bind.mainAlbumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.mainAlbumsRecyclerView.setHasFixedSize(true);
mainAlbumAdapter = new AlbumCarouselAdapter(this, false);
bind.mainAlbumsRecyclerView.setAdapter(mainAlbumAdapter);
artistPageViewModel.getMainAlbums().observe(getViewLifecycleOwner(), albums -> {
if (bind != null) {
bind.artistPageMainAlbumsSector.setVisibility(albums != null && !albums.isEmpty() ? View.VISIBLE : View.GONE);
if (albums != null) {
bind.mainAlbumsSeeAllTextView.setVisibility(albums.size() > 5 ? View.VISIBLE : View.GONE);
mainAlbumAdapter.setItems(albums);
bind.mainAlbumsSeeAllTextView.setOnClickListener(v -> navigateToAlbumList(getString(R.string.artist_page_title_album_section), albums));
}
}
});

// EPs
bind.epsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.epsRecyclerView.setHasFixedSize(true);
epAdapter = new AlbumCarouselAdapter(this, false);
bind.epsRecyclerView.setAdapter(epAdapter);
artistPageViewModel.getEPs().observe(getViewLifecycleOwner(), albums -> {
if (bind != null) {
bind.artistPageEpsSector.setVisibility(albums != null && !albums.isEmpty() ? View.VISIBLE : View.GONE);
if (albums != null) {
bind.epsSeeAllTextView.setVisibility(albums.size() > 5 ? View.VISIBLE : View.GONE);
epAdapter.setItems(albums);
bind.epsSeeAllTextView.setOnClickListener(v -> navigateToAlbumList(getString(R.string.artist_page_title_ep_section), albums));
}
}
});

albumCatalogueAdapter = new AlbumCatalogueAdapter(this, false);
bind.albumsRecyclerView.setAdapter(albumCatalogueAdapter);
// Singles
bind.singlesRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.singlesRecyclerView.setHasFixedSize(true);
singleAdapter = new AlbumCarouselAdapter(this, false);
bind.singlesRecyclerView.setAdapter(singleAdapter);
artistPageViewModel.getSingles().observe(getViewLifecycleOwner(), albums -> {
if (bind != null) {
bind.artistPageSinglesSector.setVisibility(albums != null && !albums.isEmpty() ? View.VISIBLE : View.GONE);
if (albums != null) {
bind.singlesSeeAllTextView.setVisibility(albums.size() > 5 ? View.VISIBLE : View.GONE);
singleAdapter.setItems(albums);
bind.singlesSeeAllTextView.setOnClickListener(v -> navigateToAlbumList(getString(R.string.artist_page_title_single_section), albums));
}
}
});

artistPageViewModel.getAlbumList().observe(getViewLifecycleOwner(), albums -> {
if (albums == null) {
if (bind != null) bind.artistPageAlbumsSector.setVisibility(View.GONE);
} else {
if (bind != null)
bind.artistPageAlbumsSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE);
albumCatalogueAdapter.setItems(albums);
// Appears On
bind.appearsOnRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.appearsOnRecyclerView.setHasFixedSize(true);
appearsOnAdapter = new AlbumCarouselAdapter(this, true); // Show artist name for Appears On
bind.appearsOnRecyclerView.setAdapter(appearsOnAdapter);
artistPageViewModel.getAppearsOn().observe(getViewLifecycleOwner(), albums -> {
if (bind != null) {
bind.artistPageAppearsOnSector.setVisibility(albums != null && !albums.isEmpty() ? View.VISIBLE : View.GONE);
if (albums != null) {
bind.appearsOnSeeAllTextView.setVisibility(albums.size() > 5 ? View.VISIBLE : View.GONE);
appearsOnAdapter.setItems(albums);
bind.appearsOnSeeAllTextView.setOnClickListener(v -> navigateToAlbumList(getString(R.string.artist_page_title_appears_on_section), albums));
}
}
});
}

private void navigateToAlbumList(String title, List<com.cappielloantonio.tempo.subsonic.models.AlbumID3> albums) {
Bundle bundle = new Bundle();
bundle.putString(Constants.ALBUM_LIST_TITLE, title);
bundle.putParcelableArrayList(Constants.ALBUMS_OBJECT, new ArrayList<>(albums));
Navigation.findNavController(requireView()).navigate(R.id.albumListPageFragment, bundle);
}

private void initSimilarArtistsView() {
bind.similarArtistsRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), spanCount));
bind.similarArtistsRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, tileSpacing, false));
bind.similarArtistsRecyclerView.setHasFixedSize(true);

artistCatalogueAdapter = new ArtistCatalogueAdapter(this);
bind.similarArtistsRecyclerView.setAdapter(artistCatalogueAdapter);
similarArtistAdapter = new ArtistCarouselAdapter(this);
bind.similarArtistsRecyclerView.setAdapter(similarArtistAdapter);

artistPageViewModel.getArtistInfo(artistPageViewModel.getArtist().getId()).observe(getViewLifecycleOwner(), artist -> {
if (artist == null) {
Expand All @@ -325,7 +386,7 @@ private void initSimilarArtistsView() {
artists.addAll(artist.getSimilarArtists());
}

artistCatalogueAdapter.setItems(artists);
similarArtistAdapter.setItems(artists);
}
});

Expand Down Expand Up @@ -398,4 +459,4 @@ private void reapplyPlayback() {
private void setMediaBrowserListenableFuture() {
songHorizontalAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture);
}
}
}
Loading