From 302458e76b10f97102e7c9742299160637198a26 Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Sat, 16 Mar 2024 15:50:06 +0100 Subject: [PATCH] feat: added additional information about the album on the dedicated detail page --- .../tempo/repository/AlbumRepository.java | 24 ++++++ .../tempo/ui/fragment/AlbumPageFragment.java | 24 ++++++ .../tempo/viewmodel/AlbumPageViewModel.java | 5 ++ app/src/main/res/drawable/ic_arrow_down.xml | 9 +++ .../main/res/layout/fragment_album_page.xml | 81 +++++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 6 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable/ic_arrow_down.xml diff --git a/app/src/main/java/com/cappielloantonio/tempo/repository/AlbumRepository.java b/app/src/main/java/com/cappielloantonio/tempo/repository/AlbumRepository.java index 76a55220..2d82fe18 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/repository/AlbumRepository.java +++ b/app/src/main/java/com/cappielloantonio/tempo/repository/AlbumRepository.java @@ -8,6 +8,7 @@ import com.cappielloantonio.tempo.interfaces.DecadesCallback; import com.cappielloantonio.tempo.interfaces.MediaCallback; import com.cappielloantonio.tempo.subsonic.base.ApiResponse; import com.cappielloantonio.tempo.subsonic.models.AlbumID3; +import com.cappielloantonio.tempo.subsonic.models.AlbumInfo; import com.cappielloantonio.tempo.subsonic.models.Child; import java.util.ArrayList; @@ -170,6 +171,29 @@ public class AlbumRepository { return album; } + public MutableLiveData getAlbumInfo(String id) { + MutableLiveData albumInfo = new MutableLiveData<>(); + + App.getSubsonicClientInstance(false) + .getBrowsingClient() + .getAlbumInfo2(id) + .enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getAlbumInfo() != null) { + albumInfo.setValue(response.body().getSubsonicResponse().getAlbumInfo()); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + + } + }); + + return albumInfo; + } + public void getInstantMix(AlbumID3 album, int count, MediaCallback callback) { App.getSubsonicClientInstance(false) .getBrowsingClient() diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/AlbumPageFragment.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/AlbumPageFragment.java index 1bba506b..99b797fe 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/AlbumPageFragment.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/AlbumPageFragment.java @@ -34,6 +34,7 @@ import com.cappielloantonio.tempo.util.DownloadUtil; import com.cappielloantonio.tempo.util.MappingUtil; import com.cappielloantonio.tempo.util.MusicUtil; import com.cappielloantonio.tempo.viewmodel.AlbumPageViewModel; +import com.google.android.material.chip.Chip; import com.google.common.util.concurrent.ListenableFuture; import java.util.Collections; @@ -73,6 +74,7 @@ public class AlbumPageFragment extends Fragment implements ClickCallback { init(); initAppBar(); initAlbumInfoTextButton(); + initAlbumNotes(); initMusicButton(); initBackCover(); initSongsView(); @@ -131,10 +133,20 @@ public class AlbumPageFragment extends Fragment implements ClickCallback { bind.albumNameLabel.setText(MusicUtil.getReadableString(albumPageViewModel.getAlbum().getName())); bind.albumArtistLabel.setText(MusicUtil.getReadableString(albumPageViewModel.getAlbum().getArtist())); bind.albumReleaseYearLabel.setText(albumPageViewModel.getAlbum().getYear() != 0 ? String.valueOf(albumPageViewModel.getAlbum().getYear()) : ""); + bind.albumSongCountDurationTextview.setText(getString(R.string.album_page_tracks_count_and_duration, albumPageViewModel.getAlbum().getSongCount(), albumPageViewModel.getAlbum().getDuration() != null ? albumPageViewModel.getAlbum().getDuration() / 60 : 0)); + bind.albumGenresTextview.setText(albumPageViewModel.getAlbum().getGenre()); bind.animToolbar.setNavigationOnClickListener(v -> activity.navController.navigateUp()); Objects.requireNonNull(bind.animToolbar.getOverflowIcon()).setTint(requireContext().getResources().getColor(R.color.titleTextColor, null)); + + bind.albumOtherInfoButton.setOnClickListener(v -> { + if (bind.albumDetailView.getVisibility() == View.GONE) { + bind.albumDetailView.setVisibility(View.VISIBLE); + } else if (bind.albumDetailView.getVisibility() == View.VISIBLE) { + bind.albumDetailView.setVisibility(View.GONE); + } + }); } private void initAlbumInfoTextButton() { @@ -148,6 +160,18 @@ public class AlbumPageFragment extends Fragment implements ClickCallback { })); } + private void initAlbumNotes() { + albumPageViewModel.getAlbumInfo().observe(getViewLifecycleOwner(), albumInfo -> { + if (albumInfo != null) { + if (bind != null) bind.albumNotesTextview.setVisibility(View.VISIBLE); + if (bind != null) + bind.albumNotesTextview.setText(MusicUtil.getReadableString(albumInfo.getNotes())); + } else { + if (bind != null) bind.albumNotesTextview.setVisibility(View.GONE); + } + }); + } + private void initMusicButton() { albumPageViewModel.getAlbumSongLiveList().observe(getViewLifecycleOwner(), songs -> { if (bind != null && !songs.isEmpty()) { diff --git a/app/src/main/java/com/cappielloantonio/tempo/viewmodel/AlbumPageViewModel.java b/app/src/main/java/com/cappielloantonio/tempo/viewmodel/AlbumPageViewModel.java index 5aa40e51..e5c30894 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/viewmodel/AlbumPageViewModel.java +++ b/app/src/main/java/com/cappielloantonio/tempo/viewmodel/AlbumPageViewModel.java @@ -9,6 +9,7 @@ import androidx.lifecycle.LiveData; import com.cappielloantonio.tempo.repository.AlbumRepository; import com.cappielloantonio.tempo.repository.ArtistRepository; import com.cappielloantonio.tempo.subsonic.models.AlbumID3; +import com.cappielloantonio.tempo.subsonic.models.AlbumInfo; import com.cappielloantonio.tempo.subsonic.models.ArtistID3; import com.cappielloantonio.tempo.subsonic.models.Child; @@ -42,4 +43,8 @@ public class AlbumPageViewModel extends AndroidViewModel { public LiveData getArtist() { return artistRepository.getArtistInfo(album.getArtistId()); } + + public LiveData getAlbumInfo() { + return albumRepository.getAlbumInfo(album.getId()); + } } diff --git a/app/src/main/res/drawable/ic_arrow_down.xml b/app/src/main/res/drawable/ic_arrow_down.xml new file mode 100644 index 00000000..59ec8149 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_down.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/fragment_album_page.xml b/app/src/main/res/layout/fragment_album_page.xml index 55539e62..9be9398d 100644 --- a/app/src/main/res/layout/fragment_album_page.xml +++ b/app/src/main/res/layout/fragment_album_page.xml @@ -48,18 +48,33 @@ style="@style/LabelExtraLarge" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginStart="18dp" - android:layout_marginEnd="18dp" android:ellipsize="end" android:maxLines="2" android:paddingTop="8dp" android:singleLine="false" android:text="@string/label_placeholder" android:textAlignment="center" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="@+id/album_cover_image_view" + app:layout_constraintStart_toStartOf="@+id/album_cover_image_view" app:layout_constraintTop_toBottomOf="@+id/album_cover_image_view" /> + + + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/album_detail_view" /> More like this Play Shuffle + %1$d songs • %2$d minutes Tempo Searching… Instant mix