mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Add "New releases" view in library page
This commit is contained in:
parent
46dc173958
commit
9ae9873326
9 changed files with 116 additions and 14 deletions
|
|
@ -103,6 +103,8 @@ public class AlbumHorizontalAdapter extends RecyclerView.Adapter<AlbumHorizontal
|
|||
Navigation.findNavController(view).navigate(R.id.action_albumListPageFragment_to_albumPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.downloadFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_downloadFragment_to_albumPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_albumPageFragment, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.cappielloantonio.play.subsonic.models.AlbumInfo;
|
|||
import com.cappielloantonio.play.subsonic.models.AlbumWithSongsID3;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Album implements Parcelable {
|
||||
|
|
@ -32,6 +33,7 @@ public class Album implements Parcelable {
|
|||
private boolean favorite;
|
||||
private List<Song> songs;
|
||||
private String notes;
|
||||
private Date created;
|
||||
|
||||
public Album(AlbumID3 albumID3) {
|
||||
this.id = albumID3.getId();
|
||||
|
|
@ -41,6 +43,7 @@ public class Album implements Parcelable {
|
|||
this.artistName = albumID3.getArtist();
|
||||
this.primary = albumID3.getCoverArtId();
|
||||
this.favorite = albumID3.getStarred() != null;
|
||||
this.created = albumID3.getCreated();
|
||||
}
|
||||
|
||||
public Album(AlbumWithSongsID3 albumWithSongsID3) {
|
||||
|
|
@ -52,6 +55,7 @@ public class Album implements Parcelable {
|
|||
this.primary = albumWithSongsID3.getCoverArtId();
|
||||
this.favorite = albumWithSongsID3.getStarred() != null;
|
||||
this.songs = MappingUtil.mapSong(albumWithSongsID3.getSongs());
|
||||
this.created = albumWithSongsID3.getCreated();
|
||||
}
|
||||
|
||||
public Album(Download download) {
|
||||
|
|
@ -146,6 +150,14 @@ public class Album implements Parcelable {
|
|||
this.notes = notes;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ public class AlbumRepository {
|
|||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Album>> getAlbums(String type, int size) {
|
||||
public MutableLiveData<List<Album>> getAlbums(String type, int size, Integer fromYear, Integer toYear) {
|
||||
MutableLiveData<List<Album>> listLiveAlbums = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getAlbumList2(type, size, 0, null, null)
|
||||
.getAlbumList2(type, size, 0, fromYear, toYear)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
|
|
|
|||
|
|
@ -15,17 +15,22 @@ import androidx.fragment.app.Fragment;
|
|||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.PagerSnapHelper;
|
||||
import androidx.recyclerview.widget.SnapHelper;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.adapter.AlbumAdapter;
|
||||
import com.cappielloantonio.play.adapter.AlbumHorizontalAdapter;
|
||||
import com.cappielloantonio.play.adapter.ArtistAdapter;
|
||||
import com.cappielloantonio.play.adapter.GenreAdapter;
|
||||
import com.cappielloantonio.play.adapter.PlaylistAdapter;
|
||||
import com.cappielloantonio.play.databinding.FragmentLibraryBinding;
|
||||
import com.cappielloantonio.play.helper.recyclerview.CustomLinearSnapHelper;
|
||||
import com.cappielloantonio.play.helper.recyclerview.DotsIndicatorDecoration;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.UIUtil;
|
||||
import com.cappielloantonio.play.viewmodel.LibraryViewModel;
|
||||
|
||||
import java.util.Objects;
|
||||
|
|
@ -37,6 +42,7 @@ public class LibraryFragment extends Fragment {
|
|||
private MainActivity activity;
|
||||
private LibraryViewModel libraryViewModel;
|
||||
|
||||
private AlbumHorizontalAdapter newRelesesAlbumAdapter;
|
||||
private AlbumAdapter albumAdapter;
|
||||
private ArtistAdapter artistAdapter;
|
||||
private GenreAdapter genreAdapter;
|
||||
|
|
@ -73,6 +79,7 @@ public class LibraryFragment extends Fragment {
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
initAppBar();
|
||||
initNewReleasesView();
|
||||
initAlbumView();
|
||||
initArtistView();
|
||||
initGenreView();
|
||||
|
|
@ -136,6 +143,37 @@ public class LibraryFragment extends Fragment {
|
|||
Objects.requireNonNull(bind.toolbar.getOverflowIcon()).setTint(requireContext().getResources().getColor(R.color.titleTextColor, null));
|
||||
}
|
||||
|
||||
private void initNewReleasesView() {
|
||||
bind.newReleasesRecyclerView.setHasFixedSize(true);
|
||||
|
||||
newRelesesAlbumAdapter = new AlbumHorizontalAdapter(requireContext());
|
||||
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() {
|
||||
bind.albumRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
bind.albumRecyclerView.setHasFixedSize(true);
|
||||
|
|
|
|||
|
|
@ -39,17 +39,17 @@ public class AlbumListPageViewModel extends AndroidViewModel {
|
|||
|
||||
switch (title) {
|
||||
case Album.RECENTLY_PLAYED:
|
||||
albumRepository.getAlbums("recent", 500).observe(activity, albums -> {
|
||||
albumRepository.getAlbums("recent", 500, null, null).observe(activity, albums -> {
|
||||
albumList.setValue(albums);
|
||||
});
|
||||
break;
|
||||
case Album.MOST_PLAYED:
|
||||
albumRepository.getAlbums("frequent", 500).observe(activity, albums -> {
|
||||
albumRepository.getAlbums("frequent", 500, null, null).observe(activity, albums -> {
|
||||
albumList.setValue(albums);
|
||||
});
|
||||
break;
|
||||
case Album.RECENTLY_ADDED:
|
||||
albumRepository.getAlbums("newest", 500).observe(activity, albums -> {
|
||||
albumRepository.getAlbums("newest", 500, null, null).observe(activity, albums -> {
|
||||
albumList.setValue(albums);
|
||||
});
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -77,17 +77,17 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Album>> getMostPlayedAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("frequent", 20).observe(owner, mostPlayedAlbumSample::postValue);
|
||||
albumRepository.getAlbums("frequent", 20, null, null).observe(owner, mostPlayedAlbumSample::postValue);
|
||||
return mostPlayedAlbumSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getMostRecentlyAddedAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("newest", 20).observe(owner, recentlyAddedAlbumSample::postValue);
|
||||
albumRepository.getAlbums("newest", 20, null, null).observe(owner, recentlyAddedAlbumSample::postValue);
|
||||
return recentlyAddedAlbumSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getRecentlyPlayedAlbumList(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("recent", 20).observe(owner, recentlyPlayedAlbumSample::postValue);
|
||||
albumRepository.getAlbums("recent", 20, null, null).observe(owner, recentlyPlayedAlbumSample::postValue);
|
||||
return recentlyPlayedAlbumSample;
|
||||
}
|
||||
|
||||
|
|
@ -112,14 +112,14 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public void refreshMostPlayedAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("frequent", 20).observe(owner, mostPlayedAlbumSample::postValue);
|
||||
albumRepository.getAlbums("frequent", 20, null, null).observe(owner, mostPlayedAlbumSample::postValue);
|
||||
}
|
||||
|
||||
public void refreshMostRecentlyAddedAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("newest", 20).observe(owner, recentlyAddedAlbumSample::postValue);
|
||||
albumRepository.getAlbums("newest", 20, null, null).observe(owner, recentlyAddedAlbumSample::postValue);
|
||||
}
|
||||
|
||||
public void refreshRecentlyPlayedAlbumList(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("recent", 20).observe(owner, recentlyPlayedAlbumSample::postValue);
|
||||
albumRepository.getAlbums("recent", 20, null, null).observe(owner, recentlyPlayedAlbumSample::postValue);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,14 @@ import com.cappielloantonio.play.repository.ArtistRepository;
|
|||
import com.cappielloantonio.play.repository.GenreRepository;
|
||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class LibraryViewModel extends AndroidViewModel {
|
||||
private static final String TAG = "LibraryViewModel";
|
||||
|
||||
private final AlbumRepository albumRepository;
|
||||
private final ArtistRepository artistRepository;
|
||||
private final GenreRepository genreRepository;
|
||||
|
|
@ -27,6 +32,7 @@ public class LibraryViewModel extends AndroidViewModel {
|
|||
|
||||
private final MutableLiveData<List<Playlist>> playlistSample = 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<Genre>> sampleGenres = new MutableLiveData<>(null);
|
||||
|
||||
|
|
@ -40,12 +46,23 @@ public class LibraryViewModel extends AndroidViewModel {
|
|||
|
||||
// Inizializzate all'interno del costruttore, in modo da rimanere immutabili per tutto il
|
||||
// ciclo di vita dell'applicazione
|
||||
albumRepository.getAlbums("random", 20).observeForever(sampleAlbum::postValue);
|
||||
albumRepository.getAlbums("random", 20, null, null).observeForever(sampleAlbum::postValue);
|
||||
artistRepository.getArtists(true, 20).observeForever(sampleArtist::postValue);
|
||||
genreRepository.getGenres(true, 15).observeForever(sampleGenres::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() {
|
||||
return sampleAlbum;
|
||||
}
|
||||
|
|
@ -63,7 +80,7 @@ public class LibraryViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public void refreshAlbumSample(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("random", 20).observe(owner, sampleAlbum::postValue);
|
||||
albumRepository.getAlbums("random", 20, null, null).observe(owner, sampleAlbum::postValue);
|
||||
}
|
||||
|
||||
public void refreshArtistSample(LifecycleOwner owner) {
|
||||
|
|
|
|||
|
|
@ -54,6 +54,38 @@
|
|||
android:orientation="vertical"
|
||||
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/HeadlineTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="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
|
||||
android:id="@+id/library_album_sector"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue