detail: improve track number handling

Improve the way track numbers are handled in the album detail view.

Previously, Auxio would show track numbers by simplying stringifying
the integer and then showing it in a TextView. This was problematic for
two reasons:
- Numerics from other languages like Arabic would not be respected
- Invalid track numbers [e.g 0] would be shown regardless of the
situation.

This commit fixes that by placing all track numbers through a format
string first, and showing a generic song icon instead of a number
whenever the track number is 0.
This commit is contained in:
OxygenCobalt 2022-02-06 11:17:22 -07:00
parent 4b919b121a
commit 8e0d27696d
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 29 additions and 3 deletions

View file

@ -20,6 +20,7 @@ package org.oxycblt.auxio.detail.recycler
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isInvisible
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import org.oxycblt.auxio.R
@ -178,13 +179,19 @@ class AlbumDetailAdapter(
) : BaseViewHolder<Song>(binding, doOnClick, doOnLongClick), Highlightable {
override fun onBind(data: Song) {
binding.song = data
binding.songName.requestLayout()
// Hide the track number view if the track is zero, as generally a track number of
// zero implies that the song does not have a track number.
val usePlaceholder = data.track < 1
binding.songTrack.isInvisible = usePlaceholder
binding.songTrackPlaceholder.isInvisible = !usePlaceholder
}
override fun setHighlighted(isHighlighted: Boolean) {
binding.songName.isActivated = isHighlighted
binding.songTrack.isActivated = isHighlighted
binding.songTrackPlaceholder.isActivated = isHighlighted
}
}

View file

@ -13,6 +13,21 @@
<androidx.constraintlayout.widget.ConstraintLayout style="@style/Widget.Auxio.ItemLayout">
<ImageView
android:id="@+id/song_track_placeholder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/def_track"
android:src="@drawable/ic_song"
android:visibility="gone"
app:tint="@color/sel_accented"
app:layout_constraintBottom_toBottomOf="@+id/song_track"
app:layout_constraintEnd_toEndOf="@+id/song_track"
app:layout_constraintStart_toStartOf="@+id/song_track"
app:layout_constraintTop_toTopOf="@+id/song_track"
tools:text="1" />
<TextView
android:id="@+id/song_track"
android:layout_width="wrap_content"
@ -21,12 +36,14 @@
android:gravity="center"
android:maxLines="1"
android:minWidth="@dimen/size_track_number"
android:text="@{String.valueOf(song.track)}"
android:text="@{@string/fmt_track(song.track)}"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.Auxio.TitleMedium"
android:textSize="@dimen/text_size_ext_title_mid_larger"
android:textColor="@color/sel_accented_secondary"
android:textSize="@dimen/text_size_ext_title_mid_larger"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/song_name"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />

View file

@ -7,4 +7,5 @@
<string name="fmt_two" translatable="false">%1$s • %2$s</string>
<string name="fmt_three" translatable="false">%1$s • %2$s • %3$s</string>
<string name="fmt_counts" translatable="false">%1$s, %2$s</string>
<string name="fmt_track" translatable="false">%d</string>
</resources>

View file

@ -145,6 +145,7 @@
<string name="def_artist">Unknown Artist</string>
<string name="def_genre">Unknown Genre</string>
<string name="def_date">No Date</string>
<string name="def_track">No Track Number</string>
<string name="def_playback">No music playing</string>
<string name="def_widget_song">Song Name</string>
<string name="def_widget_artist">Artist Name</string>