feat: added release date and original release date to album notes, if available

This commit is contained in:
CappielloAntonio 2024-06-02 20:19:18 +02:00
parent e84f62220c
commit 54a4355793
5 changed files with 62 additions and 20 deletions

View file

@ -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)
}
}

View file

@ -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);
}
});
}

View file

@ -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);
});
}

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@ -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">
<ImageView
android:layout_width="24dp"
@ -107,13 +108,14 @@
android:id="@+id/album_detail_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/album_release_year_label"
android:animateLayoutChanges="true"
android:paddingTop="12dp"
android:paddingBottom="8dp"
android:visibility="gone"
android:animateLayoutChanges="true">
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/album_release_year_label"
tools:visibility="visible">
<TextView
android:id="@+id/album_genres_textview"
@ -124,18 +126,18 @@
android:layout_marginEnd="18dp"
android:text="@string/label_placeholder"
android:textAlignment="center"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/album_song_count_duration_textview"
style="@style/LabelSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingVertical="2dp"
android:layout_marginStart="18dp"
android:layout_marginEnd="18dp"
android:paddingVertical="2dp"
android:text="@string/label_placeholder"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
@ -149,13 +151,28 @@
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginEnd="18dp"
android:text="@string/label_placeholder"
android:justificationMode="inter_word"
android:text="@string/label_placeholder"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/album_song_count_duration_textview" />
<TextView
android:id="@+id/album_release_years_textview"
style="@style/LabelSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginEnd="18dp"
android:paddingVertical="4dp"
android:text="@string/label_placeholder"
android:textAlignment="center"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/album_notes_textview" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -23,6 +23,8 @@
<string name="album_list_page_title">Albums</string>
<string name="album_page_extra_info_button">More like this</string>
<string name="album_page_play_button">Play</string>
<string name="album_page_release_date_label">Released on %1$s</string>
<string name="album_page_release_dates_label">Released on %1$s, originally %2$s</string>
<string name="album_page_shuffle_button">Shuffle</string>
<string name="album_page_tracks_count_and_duration">%1$d songs • %2$d minutes</string>
<string name="app_name">Tempo</string>