diff --git a/app/src/main/java/org/jellyfin/mobile/sessionbrowser/LibraryPageElement.kt b/app/src/main/java/org/jellyfin/mobile/sessionbrowser/LibraryPageElement.kt index c98b99af..d7803c4a 100644 --- a/app/src/main/java/org/jellyfin/mobile/sessionbrowser/LibraryPageElement.kt +++ b/app/src/main/java/org/jellyfin/mobile/sessionbrowser/LibraryPageElement.kt @@ -1,7 +1,9 @@ package org.jellyfin.mobile.sessionbrowser import android.net.Uri +import androidx.annotation.DrawableRes import androidx.core.net.toUri +import org.jellyfin.mobile.R import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.imageApi import org.jellyfin.sdk.model.api.BaseItemDto @@ -24,6 +26,7 @@ sealed interface LibraryPageElement { val artist: String? = null, val album: String? = null, val image: Uri? = null, + @DrawableRes val iconRes: Int? = null, val action: LibraryItemAction, ) : LibraryPageElement @@ -35,12 +38,14 @@ sealed interface LibraryPageElement { artist: String? = item.artists?.joinToString(), album: String? = item.album, image: Uri? = item.getImage(api), + @DrawableRes iconRes: Int? = R.drawable.ic_notification, action: LibraryItemAction = LibraryItemAction.Play(item), ): Item = Item( title = title, artist = artist, album = album, image = image, + iconRes = iconRes, action = action, ) diff --git a/app/src/main/java/org/jellyfin/mobile/sessionbrowser/SessionBrowserCallback.kt b/app/src/main/java/org/jellyfin/mobile/sessionbrowser/SessionBrowserCallback.kt index 26430dfd..afd51c0e 100644 --- a/app/src/main/java/org/jellyfin/mobile/sessionbrowser/SessionBrowserCallback.kt +++ b/app/src/main/java/org/jellyfin/mobile/sessionbrowser/SessionBrowserCallback.kt @@ -1,6 +1,8 @@ package org.jellyfin.mobile.sessionbrowser +import android.content.ContentResolver import android.content.Context +import android.net.Uri import android.os.Bundle import androidx.core.os.bundleOf import androidx.media3.common.MediaItem @@ -105,13 +107,25 @@ class SessionBrowserCallback( setAlbumTitle(album) setIsBrowsable(action is LibraryItemAction.Navigate) setIsPlayable(action is LibraryItemAction.Play) - if (image != null) setArtworkUri(image) + + if (image != null) { + setArtworkUri(image) + } else if (iconRes != null) { + setArtworkUri(iconRes.asResourceUri()) + } setExtras(extras) }.build(), ) }.build() + private fun Int.asResourceUri() = Uri.Builder() + .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) + .authority(context.resources.getResourcePackageName(this)) + .appendPath(context.resources.getResourceTypeName(this)) + .appendPath(context.resources.getResourceEntryName(this)) + .build() + private fun List.toMediaItems(): List = flatMap { element -> when (element) { is LibraryPageElement.Group -> element.items.map { item -> item.toMediaItem(groupTitle = element.title) } diff --git a/app/src/main/java/org/jellyfin/mobile/sessionbrowser/page/RootLibraryPage.kt b/app/src/main/java/org/jellyfin/mobile/sessionbrowser/page/RootLibraryPage.kt index 4923b50e..567dd17e 100644 --- a/app/src/main/java/org/jellyfin/mobile/sessionbrowser/page/RootLibraryPage.kt +++ b/app/src/main/java/org/jellyfin/mobile/sessionbrowser/page/RootLibraryPage.kt @@ -27,6 +27,7 @@ val RootLibraryPage = { api: ApiClient -> api = api, item = it, image = null, + iconRes = null, action = LibraryItemAction.Navigate(LibraryRoute.Library(it.id, it.collectionType)), ) } diff --git a/app/src/main/java/org/jellyfin/mobile/sessionbrowser/page/UserViewLibraryPage.kt b/app/src/main/java/org/jellyfin/mobile/sessionbrowser/page/UserViewLibraryPage.kt index 39c77396..3eefc39c 100644 --- a/app/src/main/java/org/jellyfin/mobile/sessionbrowser/page/UserViewLibraryPage.kt +++ b/app/src/main/java/org/jellyfin/mobile/sessionbrowser/page/UserViewLibraryPage.kt @@ -18,6 +18,7 @@ val UserViewLibraryPage = { context: Context -> add( LibraryPageElement.Item( title = context.getString(R.string.media_service_car_section_albums), + iconRes = R.drawable.ic_album, action = LibraryItemAction.Navigate(LibraryRoute.AlbumsAlpha(route.libraryId)), ), ) @@ -25,6 +26,7 @@ val UserViewLibraryPage = { context: Context -> add( LibraryPageElement.Item( title = context.getString(R.string.media_service_car_section_artists), + iconRes = R.drawable.ic_artist, action = LibraryItemAction.Navigate(LibraryRoute.ArtistsAlpha(route.libraryId)), ), ) @@ -34,6 +36,7 @@ val UserViewLibraryPage = { context: Context -> add( LibraryPageElement.Item( title = context.getString(R.string.media_service_car_section_audiobooks), + iconRes = R.drawable.ic_audiobooks, action = LibraryItemAction.Navigate(LibraryRoute.AudioBooksAlpha(route.libraryId)), ), ) @@ -42,6 +45,7 @@ val UserViewLibraryPage = { context: Context -> add( LibraryPageElement.Item( title = context.getString(R.string.media_service_car_section_favorites), + iconRes = R.drawable.ic_favorite, action = LibraryItemAction.Navigate(LibraryRoute.Favorites(route.libraryId)), ), ) @@ -49,6 +53,7 @@ val UserViewLibraryPage = { context: Context -> add( LibraryPageElement.Item( title = context.getString(R.string.media_service_car_section_genres), + iconRes = R.drawable.ic_genres, action = LibraryItemAction.Navigate(LibraryRoute.Genres(route.libraryId)), ), ) @@ -56,6 +61,7 @@ val UserViewLibraryPage = { context: Context -> add( LibraryPageElement.Item( title = context.getString(R.string.media_service_car_section_playlists), + iconRes = R.drawable.ic_playlist, action = LibraryItemAction.Navigate(LibraryRoute.Playlists(route.libraryId)), ), ) @@ -63,6 +69,7 @@ val UserViewLibraryPage = { context: Context -> add( LibraryPageElement.Item( title = context.getString(R.string.media_service_car_section_recents), + iconRes = R.drawable.ic_recently_played, action = LibraryItemAction.Navigate(LibraryRoute.Recent(route.libraryId)), ), ) diff --git a/app/src/main/res/drawable/ic_album.xml b/app/src/main/res/drawable/ic_album.xml new file mode 100644 index 00000000..f8d84d5c --- /dev/null +++ b/app/src/main/res/drawable/ic_album.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_artist.xml b/app/src/main/res/drawable/ic_artist.xml new file mode 100644 index 00000000..a9f8cfc6 --- /dev/null +++ b/app/src/main/res/drawable/ic_artist.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_audiobooks.xml b/app/src/main/res/drawable/ic_audiobooks.xml new file mode 100644 index 00000000..e2321060 --- /dev/null +++ b/app/src/main/res/drawable/ic_audiobooks.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_favorite.xml b/app/src/main/res/drawable/ic_favorite.xml new file mode 100644 index 00000000..6235d47c --- /dev/null +++ b/app/src/main/res/drawable/ic_favorite.xml @@ -0,0 +1,11 @@ + + + + diff --git a/app/src/main/res/drawable/ic_genres.xml b/app/src/main/res/drawable/ic_genres.xml new file mode 100644 index 00000000..4b546c33 --- /dev/null +++ b/app/src/main/res/drawable/ic_genres.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_playlist.xml b/app/src/main/res/drawable/ic_playlist.xml new file mode 100644 index 00000000..55bce247 --- /dev/null +++ b/app/src/main/res/drawable/ic_playlist.xml @@ -0,0 +1,11 @@ + + + + diff --git a/app/src/main/res/drawable/ic_recently_played.xml b/app/src/main/res/drawable/ic_recently_played.xml new file mode 100644 index 00000000..9092bc0d --- /dev/null +++ b/app/src/main/res/drawable/ic_recently_played.xml @@ -0,0 +1,11 @@ + + + +