music: compress down mediaitem ids
This commit is contained in:
@@ -37,24 +37,43 @@ import org.oxycblt.musikr.Album
|
||||
import org.oxycblt.musikr.Artist
|
||||
import org.oxycblt.musikr.Genre
|
||||
import org.oxycblt.musikr.Music
|
||||
import org.oxycblt.musikr.Music.UID
|
||||
import org.oxycblt.musikr.MusicParent
|
||||
import org.oxycblt.musikr.Playlist
|
||||
import org.oxycblt.musikr.Song
|
||||
|
||||
sealed interface MediaSessionUID {
|
||||
data class Tab(val node: TabNode) : MediaSessionUID {
|
||||
override fun toString() = "$ID_CATEGORY:${node.id}"
|
||||
override fun toString() = "$MICRO_ID_CATEGORY${node.microId}"
|
||||
}
|
||||
|
||||
data class SingleItem(val uid: Music.UID) : MediaSessionUID {
|
||||
override fun toString() = "$ID_ITEM:$uid"
|
||||
override fun toString() = "$MICRO_ID_ITEM$uid"
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ID_CATEGORY = BuildConfig.APPLICATION_ID + ".category"
|
||||
const val MICRO_ID_CATEGORY = "mc"
|
||||
const val ID_ITEM = BuildConfig.APPLICATION_ID + ".item"
|
||||
const val MICRO_ID_ITEM = "mi"
|
||||
|
||||
fun fromString(str: String): MediaSessionUID? {
|
||||
if (str.startsWith("mc")) {
|
||||
if (str.length < 3) {
|
||||
return null
|
||||
}
|
||||
return Tab(
|
||||
TabNode.fromString(str.substring(2 until str.length))
|
||||
?: return null)
|
||||
}
|
||||
if (str.startsWith("mi")) {
|
||||
if (str.length < 3) {
|
||||
return null
|
||||
}
|
||||
return SingleItem(
|
||||
UID.fromString(str.substring(2 until str.length)) ?: return null
|
||||
)
|
||||
}
|
||||
val parts = str.split(":", limit = 2)
|
||||
if (parts.size != 2) {
|
||||
return null
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.oxycblt.auxio.music.MusicType
|
||||
|
||||
sealed class TabNode {
|
||||
abstract val id: String
|
||||
abstract val microId: String
|
||||
abstract val nameRes: Int
|
||||
abstract val bitmapRes: Int?
|
||||
|
||||
@@ -30,6 +31,7 @@ sealed class TabNode {
|
||||
|
||||
data object Root : TabNode() {
|
||||
override val id = "root"
|
||||
override val microId: String = "tt"
|
||||
override val nameRes = R.string.info_app_name
|
||||
override val bitmapRes = null
|
||||
|
||||
@@ -38,12 +40,21 @@ sealed class TabNode {
|
||||
|
||||
data object More : TabNode() {
|
||||
override val id = "more"
|
||||
override val microId: String = "tm"
|
||||
override val nameRes = R.string.lbl_more
|
||||
override val bitmapRes = R.drawable.ic_more_bitmap_24
|
||||
}
|
||||
|
||||
data class Home(val type: MusicType) : TabNode() {
|
||||
override val id = "$ID/${type.intCode}"
|
||||
override val microId: String = "t{${
|
||||
when (type) {
|
||||
MusicType.SONGS -> 's'
|
||||
MusicType.ALBUMS -> 'a'
|
||||
MusicType.ARTISTS -> 'r'
|
||||
MusicType.GENRES -> 'g'
|
||||
MusicType.PLAYLISTS -> 'p'
|
||||
}}}"
|
||||
override val bitmapRes: Int
|
||||
get() =
|
||||
when (type) {
|
||||
@@ -63,6 +74,18 @@ sealed class TabNode {
|
||||
|
||||
companion object {
|
||||
fun fromString(str: String): TabNode? {
|
||||
if (str.startsWith("t")) {
|
||||
return when (val id = str.getOrNull(1)) {
|
||||
't' -> Root
|
||||
'm' -> More
|
||||
's' -> Home(MusicType.SONGS)
|
||||
'a' -> Home(MusicType.ALBUMS)
|
||||
'r' -> Home(MusicType.ARTISTS)
|
||||
'g' -> Home(MusicType.GENRES)
|
||||
'p' -> Home(MusicType.PLAYLISTS)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
return when {
|
||||
str == Root.id -> Root
|
||||
str == More.id -> More
|
||||
|
||||
Reference in New Issue
Block a user