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.Artist
|
||||||
import org.oxycblt.musikr.Genre
|
import org.oxycblt.musikr.Genre
|
||||||
import org.oxycblt.musikr.Music
|
import org.oxycblt.musikr.Music
|
||||||
|
import org.oxycblt.musikr.Music.UID
|
||||||
import org.oxycblt.musikr.MusicParent
|
import org.oxycblt.musikr.MusicParent
|
||||||
import org.oxycblt.musikr.Playlist
|
import org.oxycblt.musikr.Playlist
|
||||||
import org.oxycblt.musikr.Song
|
import org.oxycblt.musikr.Song
|
||||||
|
|
||||||
sealed interface MediaSessionUID {
|
sealed interface MediaSessionUID {
|
||||||
data class Tab(val node: TabNode) : 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 {
|
data class SingleItem(val uid: Music.UID) : MediaSessionUID {
|
||||||
override fun toString() = "$ID_ITEM:$uid"
|
override fun toString() = "$MICRO_ID_ITEM$uid"
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val ID_CATEGORY = BuildConfig.APPLICATION_ID + ".category"
|
const val ID_CATEGORY = BuildConfig.APPLICATION_ID + ".category"
|
||||||
|
const val MICRO_ID_CATEGORY = "mc"
|
||||||
const val ID_ITEM = BuildConfig.APPLICATION_ID + ".item"
|
const val ID_ITEM = BuildConfig.APPLICATION_ID + ".item"
|
||||||
|
const val MICRO_ID_ITEM = "mi"
|
||||||
|
|
||||||
fun fromString(str: String): MediaSessionUID? {
|
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)
|
val parts = str.split(":", limit = 2)
|
||||||
if (parts.size != 2) {
|
if (parts.size != 2) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.oxycblt.auxio.music.MusicType
|
|||||||
|
|
||||||
sealed class TabNode {
|
sealed class TabNode {
|
||||||
abstract val id: String
|
abstract val id: String
|
||||||
|
abstract val microId: String
|
||||||
abstract val nameRes: Int
|
abstract val nameRes: Int
|
||||||
abstract val bitmapRes: Int?
|
abstract val bitmapRes: Int?
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ sealed class TabNode {
|
|||||||
|
|
||||||
data object Root : TabNode() {
|
data object Root : TabNode() {
|
||||||
override val id = "root"
|
override val id = "root"
|
||||||
|
override val microId: String = "tt"
|
||||||
override val nameRes = R.string.info_app_name
|
override val nameRes = R.string.info_app_name
|
||||||
override val bitmapRes = null
|
override val bitmapRes = null
|
||||||
|
|
||||||
@@ -38,12 +40,21 @@ sealed class TabNode {
|
|||||||
|
|
||||||
data object More : TabNode() {
|
data object More : TabNode() {
|
||||||
override val id = "more"
|
override val id = "more"
|
||||||
|
override val microId: String = "tm"
|
||||||
override val nameRes = R.string.lbl_more
|
override val nameRes = R.string.lbl_more
|
||||||
override val bitmapRes = R.drawable.ic_more_bitmap_24
|
override val bitmapRes = R.drawable.ic_more_bitmap_24
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Home(val type: MusicType) : TabNode() {
|
data class Home(val type: MusicType) : TabNode() {
|
||||||
override val id = "$ID/${type.intCode}"
|
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
|
override val bitmapRes: Int
|
||||||
get() =
|
get() =
|
||||||
when (type) {
|
when (type) {
|
||||||
@@ -63,6 +74,18 @@ sealed class TabNode {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun fromString(str: String): TabNode? {
|
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 {
|
return when {
|
||||||
str == Root.id -> Root
|
str == Root.id -> Root
|
||||||
str == More.id -> More
|
str == More.id -> More
|
||||||
|
|||||||
Reference in New Issue
Block a user