playback: define menu options

This commit is contained in:
Alexander Capehart 2024-08-29 09:55:02 -06:00
parent bf50867b37
commit b43dbb3e89
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 37 additions and 1 deletions

View file

@ -78,6 +78,22 @@ sealed interface MediaSessionUID {
} }
} }
enum class MediaMenuItem(val id: String, val labelRes: Int, val iconRes: Int) {
PLAY(BuildConfig.APPLICATION_ID + ".menu.PLAY", R.string.lbl_play, R.drawable.ic_play_24),
SHUFFLE(
BuildConfig.APPLICATION_ID + ".menu.SHUFFLE",
R.string.lbl_shuffle,
R.drawable.ic_shuffle_off_24),
PLAY_NEXT(
BuildConfig.APPLICATION_ID + ".menu.PLAY_NEXT",
R.string.lbl_play_next,
R.drawable.ic_play_next_24),
ADD_TO_QUEUE(
BuildConfig.APPLICATION_ID + ".menu.ADD_TO_QUEUE",
R.string.lbl_queue_add,
R.drawable.ic_queue_add_24)
}
typealias Sugar = Bundle.(Context) -> Unit typealias Sugar = Bundle.(Context) -> Unit
fun header(@StringRes nameRes: Int): Sugar = { fun header(@StringRes nameRes: Int): Sugar = {

View file

@ -18,9 +18,13 @@
package org.oxycblt.auxio.music.service package org.oxycblt.auxio.music.service
import android.content.Context
import android.os.Bundle
import android.support.v4.media.MediaBrowserCompat.MediaItem import android.support.v4.media.MediaBrowserCompat.MediaItem
import androidx.media.MediaBrowserServiceCompat.BrowserRoot import androidx.media.MediaBrowserServiceCompat.BrowserRoot
import androidx.media.MediaBrowserServiceCompat.Result import androidx.media.MediaBrowserServiceCompat.Result
import androidx.media.utils.MediaConstants
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -35,6 +39,7 @@ import org.oxycblt.auxio.util.logW
class MusicServiceFragment class MusicServiceFragment
@Inject @Inject
constructor( constructor(
@ApplicationContext private val context: Context,
private val indexer: Indexer, private val indexer: Indexer,
private val musicBrowser: MusicBrowser, private val musicBrowser: MusicBrowser,
private val musicRepository: MusicRepository private val musicRepository: MusicRepository
@ -77,7 +82,22 @@ constructor(
} }
fun getRoot(maxItems: Int) = fun getRoot(maxItems: Int) =
BrowserRoot(MediaSessionUID.CategoryItem(Category.Root(maxItems)).toString(), null) BrowserRoot(
MediaSessionUID.CategoryItem(Category.Root(maxItems)).toString(),
Bundle().apply {
val actions =
MediaMenuItem.entries.mapTo(ArrayList()) {
Bundle().apply {
putString(MediaConstants.EXTRAS_KEY_CUSTOM_BROWSER_ACTION_ID, it.id)
putString(
MediaConstants.EXTRAS_KEY_CUSTOM_BROWSER_ACTION_LABEL,
context.getString(it.labelRes))
}
}
putParcelableArrayList(
MediaConstants.BROWSER_SERVICE_EXTRAS_KEY_CUSTOM_BROWSER_ACTION_ROOT_LIST,
actions)
})
fun getItem(mediaId: String, result: Result<MediaItem>) = fun getItem(mediaId: String, result: Result<MediaItem>) =
result.dispatch { musicBrowser.getItem(mediaId) } result.dispatch { musicBrowser.getItem(mediaId) }