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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,6 +129,51 @@
|
|||
layout="@layout/item_placeholder_album"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- Best of -->
|
||||
<LinearLayout
|
||||
android:id="@+id/home_best_of_artist_sector"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/most_streamed_song_pre_text_view"
|
||||
style="@style/TitleMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="20dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="@string/home_subtitle_best_of"
|
||||
android:textAllCaps="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/best_of_artist_text_view_refreshable"
|
||||
style="@style/TitleLarge"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="@string/home_title_best_of" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/best_of_artist_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingBottom="8dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<include
|
||||
android:id="@+id/home_best_of_artist_placeholder"
|
||||
layout="@layout/item_placeholder_album"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- Radio Artist -->
|
||||
<LinearLayout
|
||||
android:id="@+id/home_radio_artist_sector"
|
||||
|
|
@ -137,7 +182,7 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recently_radio_artist_text_view_refreshable"
|
||||
android:id="@+id/radio_artist_text_view_refreshable"
|
||||
style="@style/TitleLarge"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -246,7 +291,6 @@
|
|||
android:paddingEnd="8dp"
|
||||
android:text="@string/home_title_starred_tracks" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/starred_tracks_text_view_clickable"
|
||||
style="@style/TitleMedium"
|
||||
|
|
@ -255,7 +299,6 @@
|
|||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="@string/home_title_starred_tracks_see_all_button" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
|
@ -300,7 +343,6 @@
|
|||
android:paddingEnd="8dp"
|
||||
android:text="@string/home_title_starred_albums" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/starred_albums_text_view_clickable"
|
||||
style="@style/TitleMedium"
|
||||
|
|
@ -310,7 +352,6 @@
|
|||
android:paddingTop="12dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="@string/home_title_starred_albums_see_all_button" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
|
@ -355,7 +396,6 @@
|
|||
android:paddingEnd="8dp"
|
||||
android:text="@string/home_title_starred_artists" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/starred_artists_text_view_clickable"
|
||||
style="@style/TitleMedium"
|
||||
|
|
@ -365,7 +405,6 @@
|
|||
android:paddingTop="12dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="@string/home_title_starred_artists_see_all_button" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
|
@ -494,7 +533,6 @@
|
|||
android:paddingEnd="8dp"
|
||||
android:text="@string/home_title_most_played" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/most_played_albums_text_view_clickable"
|
||||
style="@style/TitleMedium"
|
||||
|
|
@ -504,7 +542,6 @@
|
|||
android:paddingTop="12dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="@string/home_title_most_played_see_all_button" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
|
|
|||
|
|
@ -210,6 +210,8 @@
|
|||
<string name="home_title_radio_artist_see_all_button">See all</string>
|
||||
<string name="home_title_radio_station">Radio stations</string>
|
||||
<string name="home_title_new_releases">New releases</string>
|
||||
<string name="home_title_best_of">Best of</string>
|
||||
<string name="home_subtitle_best_of">Top songs of your favorite artists</string>
|
||||
<string name="home_title_newest_podcasts">Newest podcasts</string>
|
||||
<string name="artist_adapter_radio_station_starting">Searching...</string>
|
||||
<string name="podcast_bottom_sheet_go_to_channel">Go to channel</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue