mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Moved newReleases view from library to home
This commit is contained in:
parent
994ee1e2f7
commit
e5229dd48b
7 changed files with 85 additions and 88 deletions
|
|
@ -59,6 +59,7 @@ public class HomeFragment extends Fragment {
|
||||||
private HomeViewModel homeViewModel;
|
private HomeViewModel homeViewModel;
|
||||||
|
|
||||||
private DiscoverSongAdapter discoverSongAdapter;
|
private DiscoverSongAdapter discoverSongAdapter;
|
||||||
|
private AlbumHorizontalAdapter newRelesesAlbumAdapter;
|
||||||
private AlbumAdapter recentlyAddedAlbumAdapter;
|
private AlbumAdapter recentlyAddedAlbumAdapter;
|
||||||
private AlbumAdapter recentlyPlayedAlbumAdapter;
|
private AlbumAdapter recentlyPlayedAlbumAdapter;
|
||||||
private AlbumAdapter mostPlayedAlbumAdapter;
|
private AlbumAdapter mostPlayedAlbumAdapter;
|
||||||
|
|
@ -104,6 +105,7 @@ public class HomeFragment extends Fragment {
|
||||||
initAppBar();
|
initAppBar();
|
||||||
initDiscoverSongSlideView();
|
initDiscoverSongSlideView();
|
||||||
initSimilarSongView();
|
initSimilarSongView();
|
||||||
|
initNewReleasesView();
|
||||||
initMostPlayedAlbumView();
|
initMostPlayedAlbumView();
|
||||||
initRecentPlayedAlbumView();
|
initRecentPlayedAlbumView();
|
||||||
initStarredTracksView();
|
initStarredTracksView();
|
||||||
|
|
@ -281,6 +283,39 @@ public class HomeFragment extends Fragment {
|
||||||
similarSongSnapHelper.attachToRecyclerView(bind.similarTracksRecyclerView);
|
similarSongSnapHelper.attachToRecyclerView(bind.similarTracksRecyclerView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initNewReleasesView() {
|
||||||
|
bind.newReleasesRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
|
newRelesesAlbumAdapter = new AlbumHorizontalAdapter(requireContext(), false);
|
||||||
|
bind.newReleasesRecyclerView.setAdapter(newRelesesAlbumAdapter);
|
||||||
|
homeViewModel.getRecentlyReleasedAlbums(requireActivity()).observe(requireActivity(), albums -> {
|
||||||
|
if (albums == null) {
|
||||||
|
if (bind != null) bind.homeNewReleasesPlaceholder.placeholder.setVisibility(View.VISIBLE);
|
||||||
|
if (bind != null) bind.homeNewReleasesSector.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
if (bind != null) bind.homeNewReleasesPlaceholder.placeholder.setVisibility(View.GONE);
|
||||||
|
if (bind != null) bind.homeNewReleasesSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
if (bind != null)
|
||||||
|
bind.newReleasesRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(albums.size(), 5), GridLayoutManager.HORIZONTAL, false));
|
||||||
|
|
||||||
|
newRelesesAlbumAdapter.setItems(albums);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
SnapHelper starredAlbumSnapHelper = new PagerSnapHelper();
|
||||||
|
starredAlbumSnapHelper.attachToRecyclerView(bind.newReleasesRecyclerView);
|
||||||
|
|
||||||
|
bind.newReleasesRecyclerView.addItemDecoration(
|
||||||
|
new DotsIndicatorDecoration(
|
||||||
|
getResources().getDimensionPixelSize(R.dimen.radius),
|
||||||
|
getResources().getDimensionPixelSize(R.dimen.radius) * 4,
|
||||||
|
getResources().getDimensionPixelSize(R.dimen.dots_height),
|
||||||
|
requireContext().getResources().getColor(R.color.titleTextColor, null),
|
||||||
|
requireContext().getResources().getColor(R.color.titleTextColor, null))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private void initMostPlayedAlbumView() {
|
private void initMostPlayedAlbumView() {
|
||||||
bind.mostPlayedAlbumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
bind.mostPlayedAlbumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||||
bind.mostPlayedAlbumsRecyclerView.setHasFixedSize(true);
|
bind.mostPlayedAlbumsRecyclerView.setHasFixedSize(true);
|
||||||
|
|
@ -487,18 +522,12 @@ public class HomeFragment extends Fragment {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Il layout di default prevede questa sequenza:
|
|
||||||
* - Discovery - Most_played - Last_played - Year - Favorite - Downloaded - Recently_added
|
|
||||||
*
|
|
||||||
* Se però non ho ancora ascoltato nessuna canzone e quindi Most_played e Last_played sono vuoti, modifico come segue
|
|
||||||
* - Discovery - Recently_added - Year - Favorite - Downloaded - Most_played - Last_played
|
|
||||||
*/
|
|
||||||
public void reorder() {
|
public void reorder() {
|
||||||
if (bind != null) {
|
if (bind != null) {
|
||||||
bind.homeLinearLayoutContainer.removeAllViews();
|
bind.homeLinearLayoutContainer.removeAllViews();
|
||||||
bind.homeLinearLayoutContainer.addView(bind.homeDiscoverSector);
|
bind.homeLinearLayoutContainer.addView(bind.homeDiscoverSector);
|
||||||
bind.homeLinearLayoutContainer.addView(bind.homeSimilarTracksSector);
|
bind.homeLinearLayoutContainer.addView(bind.homeSimilarTracksSector);
|
||||||
|
bind.homeLinearLayoutContainer.addView(bind.homeNewReleasesSector);
|
||||||
bind.homeLinearLayoutContainer.addView(bind.homeRecentlyAddedAlbumsSector);
|
bind.homeLinearLayoutContainer.addView(bind.homeRecentlyAddedAlbumsSector);
|
||||||
bind.homeLinearLayoutContainer.addView(bind.homeFlashbackSector);
|
bind.homeLinearLayoutContainer.addView(bind.homeFlashbackSector);
|
||||||
bind.homeLinearLayoutContainer.addView(bind.homeStarredTracksSector);
|
bind.homeLinearLayoutContainer.addView(bind.homeStarredTracksSector);
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ public class LibraryFragment extends Fragment {
|
||||||
private MainActivity activity;
|
private MainActivity activity;
|
||||||
private LibraryViewModel libraryViewModel;
|
private LibraryViewModel libraryViewModel;
|
||||||
|
|
||||||
private AlbumHorizontalAdapter newRelesesAlbumAdapter;
|
|
||||||
private AlbumAdapter albumAdapter;
|
private AlbumAdapter albumAdapter;
|
||||||
private ArtistAdapter artistAdapter;
|
private ArtistAdapter artistAdapter;
|
||||||
private GenreAdapter genreAdapter;
|
private GenreAdapter genreAdapter;
|
||||||
|
|
@ -86,7 +85,6 @@ public class LibraryFragment extends Fragment {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
initAppBar();
|
initAppBar();
|
||||||
initNewReleasesView();
|
|
||||||
initAlbumView();
|
initAlbumView();
|
||||||
initArtistView();
|
initArtistView();
|
||||||
initGenreView();
|
initGenreView();
|
||||||
|
|
@ -151,38 +149,6 @@ public class LibraryFragment extends Fragment {
|
||||||
Objects.requireNonNull(bind.toolbar.getOverflowIcon()).setTint(requireContext().getResources().getColor(R.color.titleTextColor, null));
|
Objects.requireNonNull(bind.toolbar.getOverflowIcon()).setTint(requireContext().getResources().getColor(R.color.titleTextColor, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initNewReleasesView() {
|
|
||||||
bind.newReleasesRecyclerView.setHasFixedSize(true);
|
|
||||||
|
|
||||||
newRelesesAlbumAdapter = new AlbumHorizontalAdapter(requireContext(), false);
|
|
||||||
bind.newReleasesRecyclerView.setAdapter(newRelesesAlbumAdapter);
|
|
||||||
libraryViewModel.getRecentlyReleasedAlbums(requireActivity()).observe(requireActivity(), albums -> {
|
|
||||||
if (albums == null) {
|
|
||||||
if (bind != null) bind.libraryNewReleasesPlaceholder.placeholder.setVisibility(View.VISIBLE);
|
|
||||||
if (bind != null) bind.libraryNewReleasesSector.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
if (bind != null) bind.libraryNewReleasesPlaceholder.placeholder.setVisibility(View.GONE);
|
|
||||||
if (bind != null) bind.libraryNewReleasesSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE);
|
|
||||||
if (bind != null)
|
|
||||||
bind.newReleasesRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(albums.size(), 5), GridLayoutManager.HORIZONTAL, false));
|
|
||||||
|
|
||||||
newRelesesAlbumAdapter.setItems(albums);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
SnapHelper starredAlbumSnapHelper = new PagerSnapHelper();
|
|
||||||
starredAlbumSnapHelper.attachToRecyclerView(bind.newReleasesRecyclerView);
|
|
||||||
|
|
||||||
bind.newReleasesRecyclerView.addItemDecoration(
|
|
||||||
new DotsIndicatorDecoration(
|
|
||||||
getResources().getDimensionPixelSize(R.dimen.radius),
|
|
||||||
getResources().getDimensionPixelSize(R.dimen.radius) * 4,
|
|
||||||
getResources().getDimensionPixelSize(R.dimen.dots_height),
|
|
||||||
requireContext().getResources().getColor(R.color.titleTextColor, null),
|
|
||||||
requireContext().getResources().getColor(R.color.titleTextColor, null))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initAlbumView() {
|
private void initAlbumView() {
|
||||||
bind.albumRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
bind.albumRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||||
bind.albumRecyclerView.setHasFixedSize(true);
|
bind.albumRecyclerView.setHasFixedSize(true);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||||
import com.cappielloantonio.play.repository.SongRepository;
|
import com.cappielloantonio.play.repository.SongRepository;
|
||||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class HomeViewModel extends AndroidViewModel {
|
public class HomeViewModel extends AndroidViewModel {
|
||||||
|
|
@ -31,8 +33,8 @@ public class HomeViewModel extends AndroidViewModel {
|
||||||
private final PlaylistRepository playlistRepository;
|
private final PlaylistRepository playlistRepository;
|
||||||
|
|
||||||
private final MutableLiveData<List<Song>> dicoverSongSample = new MutableLiveData<>(null);
|
private final MutableLiveData<List<Song>> dicoverSongSample = new MutableLiveData<>(null);
|
||||||
|
private final MutableLiveData<List<Album>> newReleasedAlbum = new MutableLiveData<>(null);
|
||||||
private final MutableLiveData<List<Song>> starredTracksSample = new MutableLiveData<>(null);
|
private final MutableLiveData<List<Song>> starredTracksSample = new MutableLiveData<>(null);
|
||||||
|
|
||||||
private final MutableLiveData<List<Album>> mostPlayedAlbumSample = new MutableLiveData<>(null);
|
private final MutableLiveData<List<Album>> mostPlayedAlbumSample = new MutableLiveData<>(null);
|
||||||
private final MutableLiveData<List<Album>> recentlyPlayedAlbumSample = new MutableLiveData<>(null);
|
private final MutableLiveData<List<Album>> recentlyPlayedAlbumSample = new MutableLiveData<>(null);
|
||||||
private final MutableLiveData<List<Integer>> years = new MutableLiveData<>(null);
|
private final MutableLiveData<List<Integer>> years = new MutableLiveData<>(null);
|
||||||
|
|
@ -58,6 +60,17 @@ public class HomeViewModel extends AndroidViewModel {
|
||||||
return dicoverSongSample;
|
return dicoverSongSample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<List<Album>> getRecentlyReleasedAlbums(LifecycleOwner owner) {
|
||||||
|
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
|
||||||
|
|
||||||
|
albumRepository.getAlbums("byYear", 500, currentYear, currentYear).observe(owner, albums -> {
|
||||||
|
albums.sort(Comparator.comparing(Album::getCreated).reversed());
|
||||||
|
newReleasedAlbum.postValue(albums.subList(0, Math.min(20, albums.size())));
|
||||||
|
});
|
||||||
|
|
||||||
|
return newReleasedAlbum;
|
||||||
|
}
|
||||||
|
|
||||||
public LiveData<List<Song>> getStarredTracksSample() {
|
public LiveData<List<Song>> getStarredTracksSample() {
|
||||||
return starredTracksSample;
|
return starredTracksSample;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ public class LibraryViewModel extends AndroidViewModel {
|
||||||
|
|
||||||
private final MutableLiveData<List<Playlist>> playlistSample = new MutableLiveData<>(null);
|
private final MutableLiveData<List<Playlist>> playlistSample = new MutableLiveData<>(null);
|
||||||
private final MutableLiveData<List<Album>> sampleAlbum = new MutableLiveData<>(null);
|
private final MutableLiveData<List<Album>> sampleAlbum = new MutableLiveData<>(null);
|
||||||
private final MutableLiveData<List<Album>> newReleasedAlbum = new MutableLiveData<>(null);
|
|
||||||
private final MutableLiveData<List<Artist>> sampleArtist = new MutableLiveData<>(null);
|
private final MutableLiveData<List<Artist>> sampleArtist = new MutableLiveData<>(null);
|
||||||
private final MutableLiveData<List<Genre>> sampleGenres = new MutableLiveData<>(null);
|
private final MutableLiveData<List<Genre>> sampleGenres = new MutableLiveData<>(null);
|
||||||
|
|
||||||
|
|
@ -51,17 +50,6 @@ public class LibraryViewModel extends AndroidViewModel {
|
||||||
playlistRepository.getPlaylists(true, 10).observeForever(playlistSample::postValue);
|
playlistRepository.getPlaylists(true, 10).observeForever(playlistSample::postValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Album>> getRecentlyReleasedAlbums(LifecycleOwner owner) {
|
|
||||||
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
|
|
||||||
|
|
||||||
albumRepository.getAlbums("byYear", 500, currentYear, currentYear).observe(owner, albums -> {
|
|
||||||
albums.sort(Comparator.comparing(Album::getCreated).reversed());
|
|
||||||
newReleasedAlbum.postValue(albums.subList(0, Math.min(20, albums.size())));
|
|
||||||
});
|
|
||||||
|
|
||||||
return newReleasedAlbum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveData<List<Album>> getAlbumSample() {
|
public LiveData<List<Album>> getAlbumSample() {
|
||||||
return sampleAlbum;
|
return sampleAlbum;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,40 @@
|
||||||
layout="@layout/item_placeholder_album"
|
layout="@layout/item_placeholder_album"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<!-- Most played albums -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/home_new_releases_sector"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="8dp">
|
||||||
|
|
||||||
|
<!-- New releases -->
|
||||||
|
<TextView
|
||||||
|
style="@style/TitleLarge"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:text="@string/home_title_new_releases" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/new_releases_recycler_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingBottom="8dp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/home_new_releases_placeholder"
|
||||||
|
layout="@layout/item_placeholder_horizontal"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<!-- Most played albums -->
|
<!-- Most played albums -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/home_most_played_albums_sector"
|
android:id="@+id/home_most_played_albums_sector"
|
||||||
|
|
|
||||||
|
|
@ -51,39 +51,6 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="@dimen/global_padding_bottom">
|
android:paddingBottom="@dimen/global_padding_bottom">
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/library_new_releases_sector"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingBottom="8dp">
|
|
||||||
|
|
||||||
<!-- New releases -->
|
|
||||||
<TextView
|
|
||||||
style="@style/TitleLarge"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingStart="16dp"
|
|
||||||
android:paddingTop="8dp"
|
|
||||||
android:paddingEnd="16dp"
|
|
||||||
android:text="@string/library_title_new_releases" />
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/new_releases_recycler_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:paddingTop="8dp"
|
|
||||||
android:paddingBottom="8dp" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/library_new_releases_placeholder"
|
|
||||||
layout="@layout/item_placeholder_horizontal"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/library_album_sector"
|
android:id="@+id/library_album_sector"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@
|
||||||
<string name="home_title_most_played">Most played</string>
|
<string name="home_title_most_played">Most played</string>
|
||||||
<string name="home_title_most_played_see_all_button">See all</string>
|
<string name="home_title_most_played_see_all_button">See all</string>
|
||||||
<string name="home_title_music_discovery">Music discovery</string>
|
<string name="home_title_music_discovery">Music discovery</string>
|
||||||
|
<string name="home_title_new_releases">New releases</string>
|
||||||
<string name="home_title_recently_added">Recently added</string>
|
<string name="home_title_recently_added">Recently added</string>
|
||||||
<string name="home_title_recently_added_see_all_button">See all</string>
|
<string name="home_title_recently_added_see_all_button">See all</string>
|
||||||
<string name="home_title_starred_albums">★ Starred albums</string>
|
<string name="home_title_starred_albums">★ Starred albums</string>
|
||||||
|
|
@ -90,7 +91,6 @@
|
||||||
<string name="library_title_artist_see_all_button">See all</string>
|
<string name="library_title_artist_see_all_button">See all</string>
|
||||||
<string name="library_title_genre">Genres</string>
|
<string name="library_title_genre">Genres</string>
|
||||||
<string name="library_title_genre_see_all_button">See all</string>
|
<string name="library_title_genre_see_all_button">See all</string>
|
||||||
<string name="library_title_new_releases">New releases</string>
|
|
||||||
<string name="library_title_playlist">Playlists</string>
|
<string name="library_title_playlist">Playlists</string>
|
||||||
<string name="library_title_playlist_see_all_button">See all</string>
|
<string name="library_title_playlist_see_all_button">See all</string>
|
||||||
<string name="login_empty">No server added</string>
|
<string name="login_empty">No server added</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue