playback: add tab icons

This commit is contained in:
Alexander Capehart 2024-06-09 20:25:33 -06:00
parent 4f71dba90e
commit ba0d2cd879
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
26 changed files with 52 additions and 10 deletions

View file

@ -19,10 +19,15 @@
package org.oxycblt.auxio.music.service package org.oxycblt.auxio.music.service
import android.content.Context import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle import android.os.Bundle
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.media.utils.MediaConstants
import androidx.media3.common.MediaItem import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata import androidx.media3.common.MediaMetadata
import java.io.ByteArrayOutputStream
import org.oxycblt.auxio.BuildConfig import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.Album import org.oxycblt.auxio.music.Album
@ -37,14 +42,27 @@ import org.oxycblt.auxio.music.resolveNames
import org.oxycblt.auxio.util.getPlural import org.oxycblt.auxio.util.getPlural
fun MediaSessionUID.Category.toMediaItem(context: Context): MediaItem { fun MediaSessionUID.Category.toMediaItem(context: Context): MediaItem {
// TODO: Make custom overflow menu for compat
val style =
Bundle().apply {
putInt(
MediaConstants.DESCRIPTION_EXTRAS_KEY_CONTENT_STYLE_SINGLE_ITEM,
MediaConstants.DESCRIPTION_EXTRAS_VALUE_CONTENT_STYLE_CATEGORY_LIST_ITEM)
}
val metadata = val metadata =
MediaMetadata.Builder() MediaMetadata.Builder()
.setTitle(context.getString(nameRes)) .setTitle(context.getString(nameRes))
.setIsPlayable(false) .setIsPlayable(false)
.setIsBrowsable(true) .setIsBrowsable(true)
.setMediaType(mediaType) .setMediaType(mediaType)
.build() .setExtras(style)
return MediaItem.Builder().setMediaId(toString()).setMediaMetadata(metadata).build() if (bitmapRes != null) {
val data = ByteArrayOutputStream()
BitmapFactory.decodeResource(context.resources, bitmapRes)
.compress(Bitmap.CompressFormat.PNG, 100, data)
metadata.setArtworkData(data.toByteArray(), MediaMetadata.PICTURE_TYPE_FILE_ICON)
}
return MediaItem.Builder().setMediaId(toString()).setMediaMetadata(metadata.build()).build()
} }
fun Song.toMediaItem(context: Context, parent: MusicParent?): MediaItem { fun Song.toMediaItem(context: Context, parent: MusicParent?): MediaItem {
@ -205,14 +223,38 @@ fun MediaItem.toSong(deviceLibrary: DeviceLibrary): Song? {
} }
sealed interface MediaSessionUID { sealed interface MediaSessionUID {
enum class Category(val id: String, @StringRes val nameRes: Int, val mediaType: Int?) : enum class Category(
MediaSessionUID { val id: String,
ROOT("root", R.string.info_app_name, null), @StringRes val nameRes: Int,
SONGS("songs", R.string.lbl_songs, MediaMetadata.MEDIA_TYPE_MUSIC), @DrawableRes val bitmapRes: Int?,
ALBUMS("albums", R.string.lbl_albums, MediaMetadata.MEDIA_TYPE_FOLDER_ALBUMS), val mediaType: Int?
ARTISTS("artists", R.string.lbl_artists, MediaMetadata.MEDIA_TYPE_FOLDER_ARTISTS), ) : MediaSessionUID {
GENRES("genres", R.string.lbl_genres, MediaMetadata.MEDIA_TYPE_FOLDER_GENRES), ROOT("root", R.string.info_app_name, null, null),
PLAYLISTS("playlists", R.string.lbl_playlists, MediaMetadata.MEDIA_TYPE_FOLDER_PLAYLISTS); SONGS(
"songs",
R.string.lbl_songs,
R.drawable.ic_song_bitmap_24,
MediaMetadata.MEDIA_TYPE_MUSIC),
ALBUMS(
"albums",
R.string.lbl_albums,
R.drawable.ic_album_bitmap_24,
MediaMetadata.MEDIA_TYPE_FOLDER_ALBUMS),
ARTISTS(
"artists",
R.string.lbl_artists,
R.drawable.ic_artist_bitmap_24,
MediaMetadata.MEDIA_TYPE_FOLDER_ARTISTS),
GENRES(
"genres",
R.string.lbl_genres,
R.drawable.ic_genre_bitmap_24,
MediaMetadata.MEDIA_TYPE_FOLDER_GENRES),
PLAYLISTS(
"playlists",
R.string.lbl_playlists,
R.drawable.ic_playlist_bitmap_24,
MediaMetadata.MEDIA_TYPE_FOLDER_PLAYLISTS);
override fun toString() = "$ID_CATEGORY:$id" override fun toString() = "$ID_CATEGORY:$id"

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 812 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B