mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Added shortcuts to play top songs from user's favorite artists
This commit is contained in:
parent
754fc69eab
commit
5eed437c5b
7 changed files with 120 additions and 24 deletions
|
|
@ -37,13 +37,15 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
|||
private final Context context;
|
||||
private final ClickCallback click;
|
||||
private final boolean mix;
|
||||
private final boolean bestOf;
|
||||
|
||||
private List<Artist> artists;
|
||||
|
||||
public ArtistAdapter(Context context, ClickCallback click, Boolean mix) {
|
||||
public ArtistAdapter(Context context, ClickCallback click, Boolean mix, Boolean bestOf) {
|
||||
this.context = context;
|
||||
this.click = click;
|
||||
this.mix = mix;
|
||||
this.bestOf = bestOf;
|
||||
this.artists = Collections.emptyList();
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +126,7 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
|||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
bundle.putBoolean("is_mix", mix);
|
||||
bundle.putBoolean("is_best_of", bestOf);
|
||||
|
||||
click.onArtistClick(bundle);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
@ -58,7 +57,6 @@ import com.google.android.gms.cast.framework.CastButtonFactory;
|
|||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
|
@ -73,6 +71,7 @@ public class HomeFragment extends Fragment implements ClickCallback {
|
|||
private DiscoverSongAdapter discoverSongAdapter;
|
||||
private SimilarTrackAdapter similarMusicAdapter;
|
||||
private ArtistAdapter radioArtistAdapter;
|
||||
private ArtistAdapter bestOfArtistAdapter;
|
||||
private SongHorizontalAdapter starredSongAdapter;
|
||||
private AlbumHorizontalAdapter starredAlbumAdapter;
|
||||
private ArtistHorizontalAdapter starredArtistAdapter;
|
||||
|
|
@ -121,6 +120,7 @@ public class HomeFragment extends Fragment implements ClickCallback {
|
|||
initDiscoverSongSlideView();
|
||||
initSimilarSongView();
|
||||
initArtistRadio();
|
||||
initArtistBestOf();
|
||||
initStarredTracksView();
|
||||
initStarredAlbumsView();
|
||||
initStarredArtistsView();
|
||||
|
|
@ -179,11 +179,16 @@ public class HomeFragment extends Fragment implements ClickCallback {
|
|||
return true;
|
||||
});
|
||||
|
||||
bind.recentlyRadioArtistTextViewRefreshable.setOnLongClickListener(v -> {
|
||||
bind.radioArtistTextViewRefreshable.setOnLongClickListener(v -> {
|
||||
homeViewModel.refreshRadioArtistSample(getViewLifecycleOwner());
|
||||
return true;
|
||||
});
|
||||
|
||||
bind.bestOfArtistTextViewRefreshable.setOnLongClickListener(v -> {
|
||||
homeViewModel.refreshBestOfArtist(getViewLifecycleOwner());
|
||||
return true;
|
||||
});
|
||||
|
||||
bind.starredTracksTextViewClickable.setOnClickListener(v -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Media.STARRED, Media.STARRED);
|
||||
|
|
@ -309,7 +314,7 @@ public class HomeFragment extends Fragment implements ClickCallback {
|
|||
bind.radioArtistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.radioArtistRecyclerView.setHasFixedSize(true);
|
||||
|
||||
radioArtistAdapter = new ArtistAdapter(requireContext(), this, true);
|
||||
radioArtistAdapter = new ArtistAdapter(requireContext(), this, true, false);
|
||||
bind.radioArtistRecyclerView.setAdapter(radioArtistAdapter);
|
||||
homeViewModel.getStarredArtistsSample(getViewLifecycleOwner()).observe(getViewLifecycleOwner(), artists -> {
|
||||
if (artists == null) {
|
||||
|
|
@ -330,6 +335,31 @@ public class HomeFragment extends Fragment implements ClickCallback {
|
|||
artistRadioSnapHelper.attachToRecyclerView(bind.radioArtistRecyclerView);
|
||||
}
|
||||
|
||||
private void initArtistBestOf() {
|
||||
bind.bestOfArtistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.bestOfArtistRecyclerView.setHasFixedSize(true);
|
||||
|
||||
bestOfArtistAdapter = new ArtistAdapter(requireContext(), this, false, true);
|
||||
bind.bestOfArtistRecyclerView.setAdapter(bestOfArtistAdapter);
|
||||
homeViewModel.getBestOfArtists(getViewLifecycleOwner()).observe(getViewLifecycleOwner(), artists -> {
|
||||
if (artists == null) {
|
||||
if (bind != null)
|
||||
bind.homeBestOfArtistPlaceholder.placeholder.setVisibility(View.VISIBLE);
|
||||
if (bind != null) bind.homeBestOfArtistSector.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (bind != null)
|
||||
bind.homeBestOfArtistPlaceholder.placeholder.setVisibility(View.GONE);
|
||||
if (bind != null)
|
||||
bind.homeBestOfArtistSector.setVisibility(!artists.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
|
||||
bestOfArtistAdapter.setItems(artists);
|
||||
}
|
||||
});
|
||||
|
||||
CustomLinearSnapHelper artistBestOfSnapHelper = new CustomLinearSnapHelper();
|
||||
artistBestOfSnapHelper.attachToRecyclerView(bind.bestOfArtistRecyclerView);
|
||||
}
|
||||
|
||||
private void initStarredTracksView() {
|
||||
bind.starredTracksRecyclerView.setHasFixedSize(true);
|
||||
|
||||
|
|
@ -717,7 +747,7 @@ public class HomeFragment extends Fragment implements ClickCallback {
|
|||
if (mediaBrowserListenableFuture != null) {
|
||||
homeViewModel.getMediaInstantMix(getViewLifecycleOwner(), bundle.getParcelable("song_object")).observe(getViewLifecycleOwner(), songs -> {
|
||||
if (songs.size() > 0) {
|
||||
MediaManager.enqueue(mediaBrowserListenableFuture, requireContext(), (ArrayList<Media>) songs, true);
|
||||
MediaManager.enqueue(mediaBrowserListenableFuture, requireContext(), songs, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -754,9 +784,18 @@ public class HomeFragment extends Fragment implements ClickCallback {
|
|||
.show();
|
||||
|
||||
if (mediaBrowserListenableFuture != null) {
|
||||
homeViewModel.getArtistInstantMix(getViewLifecycleOwner(), bundle.getParcelable("artist_object")).observe(getViewLifecycleOwner(), songs -> {
|
||||
homeViewModel.getArtistInstantMix(bundle.getParcelable("artist_object")).observe(getViewLifecycleOwner(), songs -> {
|
||||
if (songs.size() > 0) {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, requireContext(), (ArrayList<Media>) songs, 0);
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, requireContext(), songs, 0);
|
||||
activity.setBottomSheetInPeek(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (bundle.containsKey("is_best_of") && bundle.getBoolean("is_best_of")) {
|
||||
if (mediaBrowserListenableFuture != null) {
|
||||
homeViewModel.getArtistBestOf(bundle.getParcelable("artist_object")).observe(getViewLifecycleOwner(), songs -> {
|
||||
if (songs.size() > 0) {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, requireContext(), songs, 0);
|
||||
activity.setBottomSheetInPeek(true);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ public class LibraryFragment extends Fragment implements ClickCallback {
|
|||
bind.artistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.artistRecyclerView.setHasFixedSize(true);
|
||||
|
||||
artistAdapter = new ArtistAdapter(requireContext(), this, false);
|
||||
artistAdapter = new ArtistAdapter(requireContext(), this, false, false);
|
||||
bind.artistRecyclerView.setAdapter(artistAdapter);
|
||||
libraryViewModel.getArtistSample(getViewLifecycleOwner()).observe(getViewLifecycleOwner(), artists -> {
|
||||
if (artists == null) {
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class SearchFragment extends Fragment implements ClickCallback {
|
|||
bind.searchResultArtistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.searchResultArtistRecyclerView.setHasFixedSize(true);
|
||||
|
||||
artistAdapter = new ArtistAdapter(requireContext(), this, false);
|
||||
artistAdapter = new ArtistAdapter(requireContext(), this, false, false);
|
||||
bind.searchResultArtistRecyclerView.setAdapter(artistAdapter);
|
||||
|
||||
CustomLinearSnapHelper artistSnapHelper = new CustomLinearSnapHelper();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import com.cappielloantonio.play.repository.PodcastRepository;
|
|||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
|
@ -41,6 +42,7 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
private final MutableLiveData<List<Album>> newReleasedAlbum = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Media>> starredTracksSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Artist>> starredArtistsSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Artist>> bestOfArtists = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Media>> starredTracks = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> starredAlbums = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>(null);
|
||||
|
|
@ -54,6 +56,7 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
private final MutableLiveData<List<Chronology>> thisGridTopSong = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Media>> mediaInstantMix = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Media>> artistInstantMix = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Media>> artistBestOf = new MutableLiveData<>(null);
|
||||
|
||||
public HomeViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -118,6 +121,14 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
return starredArtistsSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> getBestOfArtists(LifecycleOwner owner) {
|
||||
if (bestOfArtists.getValue() == null) {
|
||||
artistRepository.getStarredArtists(true, 20).observe(owner, bestOfArtists::postValue);
|
||||
}
|
||||
|
||||
return bestOfArtists;
|
||||
}
|
||||
|
||||
public LiveData<List<Media>> getStarredTracks(LifecycleOwner owner) {
|
||||
if (starredTracks.getValue() == null) {
|
||||
songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue);
|
||||
|
|
@ -204,12 +215,12 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
return mediaInstantMix;
|
||||
}
|
||||
|
||||
public LiveData<List<Media>> getArtistInstantMix(LifecycleOwner owner, Artist artist) {
|
||||
artistInstantMix.setValue(Collections.emptyList());
|
||||
public LiveData<ArrayList<Media>> getArtistInstantMix(Artist artist) {
|
||||
return artistRepository.getInstantMix(artist, 20);
|
||||
}
|
||||
|
||||
artistRepository.getInstantMix(artist, 20).observe(owner, artistInstantMix::postValue);
|
||||
|
||||
return artistInstantMix;
|
||||
public LiveData<List<Media>> getArtistBestOf(Artist artist) {
|
||||
return artistRepository.getTopSongs(artist.getName(), 10);
|
||||
}
|
||||
|
||||
public void refreshDiscoverySongSample(LifecycleOwner owner) {
|
||||
|
|
@ -224,6 +235,10 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
artistRepository.getStarredArtists(true, 10).observe(owner, starredArtistsSample::postValue);
|
||||
}
|
||||
|
||||
public void refreshBestOfArtist(LifecycleOwner owner) {
|
||||
artistRepository.getStarredArtists(true, 20).observe(owner, bestOfArtists::postValue);
|
||||
}
|
||||
|
||||
public void refreshStarredTracks(LifecycleOwner owner) {
|
||||
songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue