diff --git a/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt b/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt index a36e8da5..0299b8f9 100644 --- a/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt +++ b/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt @@ -71,9 +71,9 @@ class LocalDataSource(context: Context, private val database: TwelveDatabase) : Album( uri, - album, + album.takeIf { it != MediaStore.UNKNOWN_STRING }, artistUri, - artist, + artist.takeIf { it != MediaStore.UNKNOWN_STRING }, lastYear.takeIf { it != 0 }, thumbnail, ) @@ -89,7 +89,7 @@ class LocalDataSource(context: Context, private val database: TwelveDatabase) : Artist( uri, - artist, + artist.takeIf { it != MediaStore.UNKNOWN_STRING }, thumbnail, ) } @@ -157,9 +157,9 @@ class LocalDataSource(context: Context, private val database: TwelveDatabase) : audioType, duration, artistUri, - artist, + artist.takeIf { it != MediaStore.UNKNOWN_STRING }, albumUri, - album, + album.takeIf { it != MediaStore.UNKNOWN_STRING }, discNumber, discTrack, genreUri, diff --git a/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt b/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt index d2d57ba9..ea34f72a 100644 --- a/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt +++ b/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt @@ -358,7 +358,7 @@ class SubsonicDataSource(arguments: Bundle) : MediaDataSource { uri = getAlbumUri(id), title = name, artistUri = artistId?.let { getArtistUri(it) } ?: Uri.EMPTY, - artistName = artist ?: "", + artistName = artist, year = year, thumbnail = Thumbnail( uri = Uri.parse(subsonicClient.getCoverArt(id)), @@ -383,9 +383,9 @@ class SubsonicDataSource(arguments: Bundle) : MediaDataSource { type = type.toAudioType(), durationMs = (duration?.toLong()?.let { it * 1000 }) ?: 0, artistUri = artistId?.let { getArtistUri(it) } ?: Uri.EMPTY, - artistName = artist ?: "", + artistName = artist, albumUri = albumId?.let { getAlbumUri(it) } ?: Uri.EMPTY, - albumTitle = album ?: "", + albumTitle = album, discNumber = discNumber, trackNumber = track, genreUri = genre?.let { getGenreUri(it) }, diff --git a/app/src/main/java/org/lineageos/twelve/ext/MediaItem.kt b/app/src/main/java/org/lineageos/twelve/ext/MediaItem.kt index 46117249..729405e4 100644 --- a/app/src/main/java/org/lineageos/twelve/ext/MediaItem.kt +++ b/app/src/main/java/org/lineageos/twelve/ext/MediaItem.kt @@ -12,7 +12,7 @@ import androidx.media3.common.util.UnstableApi @androidx.annotation.OptIn(UnstableApi::class) fun buildMediaItem( - title: String, + title: String?, mediaId: String, isPlayable: Boolean, isBrowsable: Boolean, diff --git a/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt index 7840a3fb..70268013 100644 --- a/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt +++ b/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt @@ -147,7 +147,9 @@ class AlbumFragment : Fragment(R.layout.fragment_album) { } view.headlineText = item.audio.title - view.supportingText = item.audio.artistName + item.audio.artistName?.also { + view.supportingText = it + } ?: view.setSupportingText(R.string.artist_unknown) view.trailingSupportingText = TimestampFormatter.formatTimestampMillis( item.audio.durationMs ) @@ -273,15 +275,22 @@ class AlbumFragment : Fragment(R.layout.fragment_album) { is RequestStatus.Success -> { val (album, audios) = it.data - toolbar.title = album.title - albumTitleTextView.text = album.title + album.title?.also { albumTitle -> + toolbar.title = albumTitle + albumTitleTextView.text = albumTitle + } ?: run { + toolbar.setTitle(R.string.album_unknown) + albumTitleTextView.setText(R.string.album_unknown) + } thumbnailImageView.loadThumbnail( album.thumbnail, placeholder = R.drawable.ic_album ) - artistNameTextView.text = album.artistName + album.artistName?.also { artistName -> + artistNameTextView.text = artistName + } ?: artistNameTextView.setText(R.string.artist_unknown) artistNameTextView.setOnClickListener { findNavController().navigateSafe( R.id.action_albumFragment_to_fragment_artist, diff --git a/app/src/main/java/org/lineageos/twelve/fragments/AlbumsFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/AlbumsFragment.kt index 97ce79b1..14ab9d04 100644 --- a/app/src/main/java/org/lineageos/twelve/fragments/AlbumsFragment.kt +++ b/app/src/main/java/org/lineageos/twelve/fragments/AlbumsFragment.kt @@ -68,8 +68,13 @@ class AlbumsFragment : Fragment(R.layout.fragment_albums) { } override fun ViewHolder.onBindView(item: Album) { - view.headlineText = item.title - view.supportingText = item.artistName + item.title?.also { + view.headlineText = it + } ?: view.setHeadlineText(R.string.unknown) + + item.artistName?.also { + view.supportingText = it + } ?: view.setSupportingText(R.string.artist_unknown) } } } diff --git a/app/src/main/java/org/lineageos/twelve/fragments/ArtistFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/ArtistFragment.kt index a0c659e2..339f78bb 100644 --- a/app/src/main/java/org/lineageos/twelve/fragments/ArtistFragment.kt +++ b/app/src/main/java/org/lineageos/twelve/fragments/ArtistFragment.kt @@ -89,7 +89,9 @@ class ArtistFragment : Fragment(R.layout.fragment_artist) { override fun ViewHolder.onBindView(item: Album) { view.loadThumbnailImage(item.thumbnail, R.drawable.ic_album) - view.headlineText = item.title + item.title?.also { + view.headlineText = it + } ?: view.setHeadlineText(R.string.album_unknown) view.headlineMaxLines = 2 view.supportingText = item.year?.toString() } @@ -212,8 +214,13 @@ class ArtistFragment : Fragment(R.layout.fragment_artist) { is RequestStatus.Success -> { val (artist, artistWorks) = it.data - toolbar.title = artist.name - artistNameTextView.text = artist.name + artist.name?.also { artistName -> + toolbar.title = artistName + artistNameTextView.text = artistName + } ?: run { + toolbar.setTitle(R.string.artist_unknown) + artistNameTextView.setText(R.string.artist_unknown) + } thumbnailImageView.loadThumbnail( artist.thumbnail, diff --git a/app/src/main/java/org/lineageos/twelve/fragments/ArtistsFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/ArtistsFragment.kt index 4f4527e4..b26c53b0 100644 --- a/app/src/main/java/org/lineageos/twelve/fragments/ArtistsFragment.kt +++ b/app/src/main/java/org/lineageos/twelve/fragments/ArtistsFragment.kt @@ -68,7 +68,9 @@ class ArtistsFragment : Fragment(R.layout.fragment_artists) { } override fun ViewHolder.onBindView(item: Artist) { - view.headlineText = item.name + item.name?.also { + view.headlineText = it + } ?: view.setHeadlineText(R.string.unknown) } } } diff --git a/app/src/main/java/org/lineageos/twelve/fragments/GenreFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/GenreFragment.kt index 9944ef8b..02c0cb29 100644 --- a/app/src/main/java/org/lineageos/twelve/fragments/GenreFragment.kt +++ b/app/src/main/java/org/lineageos/twelve/fragments/GenreFragment.kt @@ -92,8 +92,12 @@ class GenreFragment : Fragment(R.layout.fragment_genre) { override fun ViewHolder.onBindView(item: Album) { view.loadThumbnailImage(item.thumbnail, R.drawable.ic_album) - view.headlineText = item.title - view.supportingText = item.artistName + item.title?.also { + view.headlineText = it + } ?: view.setHeadlineText(R.string.album_unknown) + item.artistName?.also { + view.supportingText = it + } ?: view.setSupportingText(R.string.artist_unknown) view.tertiaryText = item.year?.toString() } } @@ -155,8 +159,12 @@ class GenreFragment : Fragment(R.layout.fragment_genre) { override fun ViewHolder.onBindView(item: Audio) { view.headlineText = item.title - view.supportingText = item.artistName - view.tertiaryText = item.albumTitle + item.artistName?.also { + view.supportingText = it + } ?: view.setSupportingText(R.string.artist_unknown) + item.albumTitle?.also { + view.tertiaryText = it + } ?: view.setTertiaryText(R.string.album_unknown) } } } @@ -258,9 +266,12 @@ class GenreFragment : Fragment(R.layout.fragment_genre) { is RequestStatus.Success -> { val (genre, genreContent) = it.data - (genre.name ?: getString(R.string.genre_unknown)).let { genreName -> + genre.name?.also { genreName -> toolbar.title = genreName genreNameTextView.text = genreName + } ?: run { + toolbar.setTitle(R.string.genre_unknown) + genreNameTextView.setText(R.string.genre_unknown) } thumbnailImageView.loadThumbnail( diff --git a/app/src/main/java/org/lineageos/twelve/fragments/GenresFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/GenresFragment.kt index 28522be8..9be29ee5 100644 --- a/app/src/main/java/org/lineageos/twelve/fragments/GenresFragment.kt +++ b/app/src/main/java/org/lineageos/twelve/fragments/GenresFragment.kt @@ -68,11 +68,9 @@ class GenresFragment : Fragment(R.layout.fragment_genres) { } override fun ViewHolder.onBindView(item: Genre) { - item.name?.let { + item.name?.also { view.headlineText = it - } ?: run { - view.headlineText = getString(R.string.genre_unknown) - } + } ?: view.setHeadlineText(R.string.unknown) } } } diff --git a/app/src/main/java/org/lineageos/twelve/fragments/NowPlayingFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/NowPlayingFragment.kt index 83da4b42..ed43c01d 100644 --- a/app/src/main/java/org/lineageos/twelve/fragments/NowPlayingFragment.kt +++ b/app/src/main/java/org/lineageos/twelve/fragments/NowPlayingFragment.kt @@ -320,31 +320,21 @@ class NowPlayingFragment : Fragment(R.layout.fragment_now_playing) { viewModel.mediaMetadata.collectLatest { mediaMetadata -> val audioTitle = mediaMetadata.displayTitle ?: mediaMetadata.title - audioTitle?.let { title -> - if (audioTitleTextView.text != title) { - audioTitleTextView.text = title - } - audioTitleTextView.isVisible = true - } ?: run { - audioTitleTextView.isVisible = false + ?: getString(R.string.unknown) + if (audioTitleTextView.text != audioTitle) { + audioTitleTextView.text = audioTitle } - mediaMetadata.artist?.let { artist -> - if (artistNameTextView.text != artist) { - artistNameTextView.text = artist - } - artistNameTextView.isVisible = true - } ?: run { - artistNameTextView.isVisible = false + val artistName = mediaMetadata.artist + ?: getString(R.string.artist_unknown) + if (artistNameTextView.text != artistName) { + artistNameTextView.text = artistName } - mediaMetadata.albumTitle?.let { albumTitle -> - if (albumTitleTextView.text != albumTitle) { - albumTitleTextView.text = albumTitle - } - albumTitleTextView.isVisible = true - } ?: run { - albumTitleTextView.isVisible = false + val albumTitle = mediaMetadata.albumTitle + ?: getString(R.string.album_unknown) + if (albumTitleTextView.text != albumTitle) { + albumTitleTextView.text = albumTitle } } } diff --git a/app/src/main/java/org/lineageos/twelve/fragments/PlaylistFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/PlaylistFragment.kt index 32dce6e8..939ec528 100644 --- a/app/src/main/java/org/lineageos/twelve/fragments/PlaylistFragment.kt +++ b/app/src/main/java/org/lineageos/twelve/fragments/PlaylistFragment.kt @@ -106,7 +106,9 @@ class PlaylistFragment : Fragment(R.layout.fragment_playlist) { override fun ViewHolder.onBindView(item: Audio) { view.headlineText = item.title - view.supportingText = item.artistName + item.artistName?.also { + view.supportingText = it + } ?: view.setSupportingText(R.string.artist_unknown) view.trailingSupportingText = TimestampFormatter.formatTimestampMillis( item.durationMs ) diff --git a/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt index 59b8732a..8355dd6d 100644 --- a/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt +++ b/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt @@ -69,8 +69,12 @@ class QueueFragment : Fragment(R.layout.fragment_queue) { false -> R.drawable.ic_music_note } ) - view.headlineText = mediaItem.mediaMetadata.title - view.supportingText = mediaItem.mediaMetadata.artist + mediaItem.mediaMetadata.title?.also { + view.headlineText = it + } ?: view.setHeadlineText(R.string.unknown) + mediaItem.mediaMetadata.artist?.also { + view.supportingText = it + } ?: view.setSupportingText(R.string.artist_unknown) view.trailingSupportingText = mediaItem.mediaMetadata.durationMs?.let { TimestampFormatter.formatTimestampMillis(it) } diff --git a/app/src/main/java/org/lineageos/twelve/models/Album.kt b/app/src/main/java/org/lineageos/twelve/models/Album.kt index de9673d4..9a320011 100644 --- a/app/src/main/java/org/lineageos/twelve/models/Album.kt +++ b/app/src/main/java/org/lineageos/twelve/models/Album.kt @@ -22,9 +22,9 @@ import org.lineageos.twelve.ext.toByteArray */ data class Album( override val uri: Uri, - val title: String, + val title: String?, val artistUri: Uri, - val artistName: String, + val artistName: String?, val year: Int?, val thumbnail: Thumbnail?, ) : MediaItem { diff --git a/app/src/main/java/org/lineageos/twelve/models/Artist.kt b/app/src/main/java/org/lineageos/twelve/models/Artist.kt index 9cb52161..4923824e 100644 --- a/app/src/main/java/org/lineageos/twelve/models/Artist.kt +++ b/app/src/main/java/org/lineageos/twelve/models/Artist.kt @@ -19,7 +19,7 @@ import org.lineageos.twelve.ext.toByteArray */ data class Artist( override val uri: Uri, - val name: String, + val name: String?, val thumbnail: Thumbnail?, ) : MediaItem { override val mediaType = MediaType.ARTIST diff --git a/app/src/main/java/org/lineageos/twelve/models/Audio.kt b/app/src/main/java/org/lineageos/twelve/models/Audio.kt index 6c3fae47..4771da9d 100644 --- a/app/src/main/java/org/lineageos/twelve/models/Audio.kt +++ b/app/src/main/java/org/lineageos/twelve/models/Audio.kt @@ -38,9 +38,9 @@ data class Audio( val type: Type, val durationMs: Long, val artistUri: Uri, - val artistName: String, + val artistName: String?, val albumUri: Uri, - val albumTitle: String, + val albumTitle: String?, val discNumber: Int?, val trackNumber: Int?, val genreUri: Uri?, diff --git a/app/src/main/java/org/lineageos/twelve/models/Genre.kt b/app/src/main/java/org/lineageos/twelve/models/Genre.kt index 3fdb132d..34c17cd2 100644 --- a/app/src/main/java/org/lineageos/twelve/models/Genre.kt +++ b/app/src/main/java/org/lineageos/twelve/models/Genre.kt @@ -32,7 +32,7 @@ data class Genre( ) == 0 override fun toMedia3MediaItem() = buildMediaItem( - title = name ?: "Unknown", + title = name, mediaId = "$GENRE_MEDIA_ITEM_ID_PREFIX${uri}", isPlayable = false, isBrowsable = true, diff --git a/app/src/main/java/org/lineageos/twelve/ui/views/NowPlayingBar.kt b/app/src/main/java/org/lineageos/twelve/ui/views/NowPlayingBar.kt index ad7c141d..9d697039 100644 --- a/app/src/main/java/org/lineageos/twelve/ui/views/NowPlayingBar.kt +++ b/app/src/main/java/org/lineageos/twelve/ui/views/NowPlayingBar.kt @@ -13,7 +13,6 @@ import android.widget.ImageView import android.widget.TextView import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat -import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import androidx.media3.common.MediaItem import androidx.media3.common.MediaMetadata @@ -103,25 +102,23 @@ class NowPlayingBar @JvmOverloads constructor( } fun updateMediaMetadata(mediaMetadata: MediaMetadata) { - mediaMetadata.title?.also { - titleTextView.text = it - titleTextView.isVisible = true - } ?: run { - titleTextView.isVisible = false + val audioTitle = mediaMetadata.displayTitle + ?: mediaMetadata.title + ?: context.getString(R.string.unknown) + if (titleTextView.text != audioTitle) { + titleTextView.text = audioTitle } - mediaMetadata.artist?.also { - artistNameTextView.text = it - artistNameTextView.isVisible = true - } ?: run { - artistNameTextView.isVisible = false + val artistName = mediaMetadata.artist + ?: context.getString(R.string.artist_unknown) + if (artistNameTextView.text != artistName) { + artistNameTextView.text = artistName } - mediaMetadata.albumTitle?.also { - albumTitleTextView.text = it - albumTitleTextView.isVisible = true - } ?: run { - albumTitleTextView.isVisible = false + val albumTitle = mediaMetadata.albumTitle + ?: context.getString(R.string.album_unknown) + if (albumTitleTextView.text != albumTitle) { + albumTitleTextView.text = albumTitle } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e2135256..9a046328 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -46,8 +46,11 @@ No results ¯\\_(ツ)_/¯ - - Unknown + + Unknown + Unknown album + Unknown artist + Unknown genre %1$d