diff --git a/app/src/main/java/com/cappielloantonio/tempo/subsonic/models/ItemDate.kt b/app/src/main/java/com/cappielloantonio/tempo/subsonic/models/ItemDate.kt index 1202ca51..e32e9842 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/subsonic/models/ItemDate.kt +++ b/app/src/main/java/com/cappielloantonio/tempo/subsonic/models/ItemDate.kt @@ -3,6 +3,9 @@ package com.cappielloantonio.tempo.subsonic.models import android.os.Parcelable import androidx.annotation.Keep import kotlinx.parcelize.Parcelize +import java.text.SimpleDateFormat +import java.util.Calendar +import java.util.Locale @Keep @Parcelize @@ -10,4 +13,13 @@ open class ItemDate : Parcelable { var year: Int? = null var month: Int? = null var day: Int? = null + + fun getFormattedDate(): String { + val calendar = Calendar.getInstance() + val dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale.getDefault()) + + calendar.set(year ?: 0, month ?: 0, day ?: 0) + + return dateFormat.format(calendar.time) + } } \ No newline at end of file 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 23ff68bd..bda30b79 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 @@ -104,10 +104,7 @@ public class AlbumPageFragment extends Fragment implements ClickCallback { public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.action_download_album) { albumPageViewModel.getAlbumSongLiveList().observe(getViewLifecycleOwner(), songs -> { - DownloadUtil.getDownloadTracker(requireContext()).download( - MappingUtil.mapDownloads(songs), - songs.stream().map(Download::new).collect(Collectors.toList()) - ); + DownloadUtil.getDownloadTracker(requireContext()).download(MappingUtil.mapDownloads(songs), songs.stream().map(Download::new).collect(Collectors.toList())); }); return true; } @@ -137,6 +134,22 @@ public class AlbumPageFragment extends Fragment implements ClickCallback { bind.albumReleaseYearLabel.setText(album.getYear() != 0 ? String.valueOf(album.getYear()) : ""); bind.albumSongCountDurationTextview.setText(getString(R.string.album_page_tracks_count_and_duration, album.getSongCount(), album.getDuration() != null ? album.getDuration() / 60 : 0)); bind.albumGenresTextview.setText(album.getGenre()); + + if (album.getReleaseDate() != null && album.getOriginalReleaseDate() != null) { + bind.albumReleaseYearsTextview.setVisibility(View.VISIBLE); + + if (album.getReleaseDate() == null || album.getOriginalReleaseDate() == null) { + bind.albumReleaseYearsTextview.setText(getString(R.string.album_page_release_date_label, album.getReleaseDate() != null ? album.getReleaseDate().getFormattedDate() : album.getOriginalReleaseDate().getFormattedDate())); + } + + if (album.getReleaseDate() != null && album.getOriginalReleaseDate() != null) { + if (Objects.equals(album.getReleaseDate().getYear(), album.getOriginalReleaseDate().getYear()) && Objects.equals(album.getReleaseDate().getMonth(), album.getOriginalReleaseDate().getMonth()) && Objects.equals(album.getReleaseDate().getDay(), album.getOriginalReleaseDate().getDay())) { + bind.albumReleaseYearsTextview.setText(getString(R.string.album_page_release_date_label, album.getReleaseDate().getFormattedDate())); + } else { + bind.albumReleaseYearsTextview.setText(getString(R.string.album_page_release_dates_label, album.getReleaseDate().getFormattedDate(), album.getOriginalReleaseDate().getFormattedDate())); + } + } + } } }); @@ -168,7 +181,8 @@ public class AlbumPageFragment extends Fragment implements ClickCallback { 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())); + if (bind != null) + bind.albumNotesTextview.setText(MusicUtil.getReadableString(albumInfo.getNotes())); if (bind != null && albumInfo.getLastFmUrl() != null && !albumInfo.getLastFmUrl().isEmpty()) { bind.albumNotesTextview.setOnClickListener(v -> { @@ -208,10 +222,7 @@ public class AlbumPageFragment extends Fragment implements ClickCallback { private void initBackCover() { albumPageViewModel.getAlbum().observe(getViewLifecycleOwner(), album -> { if (bind != null && album != null) { - CustomGlideRequest.Builder - .from(requireContext(), album.getCoverArtId(), CustomGlideRequest.ResourceType.Album) - .build() - .into(bind.albumCoverImageView); + CustomGlideRequest.Builder.from(requireContext(), album.getCoverArtId(), CustomGlideRequest.ResourceType.Album).build().into(bind.albumCoverImageView); } }); } 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 9bbd5ae1..6c244505 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/viewmodel/AlbumPageViewModel.java +++ b/app/src/main/java/com/cappielloantonio/tempo/viewmodel/AlbumPageViewModel.java @@ -43,7 +43,7 @@ public class AlbumPageViewModel extends AndroidViewModel { this.album.postValue(album); albumRepository.getAlbum(album.getId()).observe(owner, albums -> { - if (albums != null) this.album.setValue(album); + if (albums != null) this.album.setValue(albums); }); } diff --git a/app/src/main/res/layout/fragment_album_page.xml b/app/src/main/res/layout/fragment_album_page.xml index 9be9398d..0e58bf74 100644 --- a/app/src/main/res/layout/fragment_album_page.xml +++ b/app/src/main/res/layout/fragment_album_page.xml @@ -1,6 +1,7 @@ @@ -63,11 +64,11 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" + android:foreground="?android:attr/selectableItemBackgroundBorderless" app:layout_constraintBottom_toBottomOf="@+id/album_name_label" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/album_name_label" - app:layout_constraintTop_toTopOf="@+id/album_name_label" - android:foreground="?android:attr/selectableItemBackgroundBorderless"> + app:layout_constraintTop_toTopOf="@+id/album_name_label"> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/album_release_year_label" + tools:visibility="visible"> + app:layout_constraintTop_toTopOf="parent" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83ed71bc..cd595b16 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,6 +23,8 @@ Albums More like this Play + Released on %1$s + Released on %1$s, originally %2$s Shuffle %1$d songs • %2$d minutes Tempo