service: try to fix android auto bugs
This commit is contained in:
@@ -23,7 +23,6 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.support.v4.media.MediaBrowserCompat
|
|
||||||
import android.support.v4.media.MediaBrowserCompat.MediaItem
|
import android.support.v4.media.MediaBrowserCompat.MediaItem
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.core.app.NotificationChannelCompat
|
import androidx.core.app.NotificationChannelCompat
|
||||||
@@ -105,7 +104,7 @@ class AuxioService :
|
|||||||
|
|
||||||
override fun onLoadChildren(parentId: String, result: Result<MutableList<MediaItem>>) {
|
override fun onLoadChildren(parentId: String, result: Result<MutableList<MediaItem>>) {
|
||||||
val maximumRootChildLimit = getRootChildrenLimit()
|
val maximumRootChildLimit = getRootChildrenLimit()
|
||||||
musicFragment.getChildren(parentId, maximumRootChildLimit, result, null)
|
musicFragment.getChildren(parentId, maximumRootChildLimit, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLoadChildren(
|
override fun onLoadChildren(
|
||||||
@@ -114,11 +113,11 @@ class AuxioService :
|
|||||||
options: Bundle,
|
options: Bundle,
|
||||||
) {
|
) {
|
||||||
val maximumRootChildLimit = getRootChildrenLimit()
|
val maximumRootChildLimit = getRootChildrenLimit()
|
||||||
musicFragment.getChildren(parentId, maximumRootChildLimit, result, options.getPage())
|
musicFragment.getChildren(parentId, maximumRootChildLimit, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSearch(query: String, extras: Bundle?, result: Result<MutableList<MediaItem>>) {
|
override fun onSearch(query: String, extras: Bundle?, result: Result<MutableList<MediaItem>>) {
|
||||||
musicFragment.search(query, result, extras?.getPage())
|
musicFragment.search(query, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getRootChildrenLimit(): Int {
|
private fun getRootChildrenLimit(): Int {
|
||||||
@@ -128,13 +127,6 @@ class AuxioService :
|
|||||||
) ?: 4
|
) ?: 4
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Bundle.getPage(): MusicServiceFragment.Page? {
|
|
||||||
val page = getInt(MediaBrowserCompat.EXTRA_PAGE, -1).takeIf { it >= 0 } ?: return null
|
|
||||||
val pageSize =
|
|
||||||
getInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, -1).takeIf { it > 0 } ?: return null
|
|
||||||
return MusicServiceFragment.Page(page, pageSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun updateForeground(change: ForegroundListener.Change) {
|
override fun updateForeground(change: ForegroundListener.Change) {
|
||||||
val mediaNotification = playbackFragment.notification
|
val mediaNotification = playbackFragment.notification
|
||||||
if (mediaNotification != null) {
|
if (mediaNotification != null) {
|
||||||
|
|||||||
@@ -131,9 +131,10 @@ private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getChildren(parentId: String, maxTabs: Int): List<MediaItem>? {
|
fun getChildren(parentId: String, maxTabs: Int): List<MediaItem>? {
|
||||||
if (musicRepository.library == null) {
|
// we do not gate by library here since either
|
||||||
return listOf()
|
// - we are loading tabs, which we want to always load in since some head units dont
|
||||||
}
|
// cope well with sending no tabs then trying to update with tabs
|
||||||
|
// - the downstream code already handles no-library cases
|
||||||
return getMediaItemList(parentId, maxTabs)
|
return getMediaItemList(parentId, maxTabs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,6 +203,7 @@ private constructor(
|
|||||||
homeGenerator.tabs().drop(maxTabs - 1).map { TabNode.Home(it).toMediaItem(context) }
|
homeGenerator.tabs().drop(maxTabs - 1).map { TabNode.Home(it).toMediaItem(context) }
|
||||||
}
|
}
|
||||||
is TabNode.Home ->
|
is TabNode.Home ->
|
||||||
|
// homeGenerator returns emptyLists
|
||||||
when (node.type) {
|
when (node.type) {
|
||||||
MusicType.SONGS -> homeGenerator.songs().map { it.toMediaItem(context) }
|
MusicType.SONGS -> homeGenerator.songs().map { it.toMediaItem(context) }
|
||||||
MusicType.ALBUMS -> homeGenerator.albums().map { it.toMediaItem(context) }
|
MusicType.ALBUMS -> homeGenerator.albums().map { it.toMediaItem(context) }
|
||||||
|
|||||||
@@ -107,15 +107,11 @@ constructor(
|
|||||||
fun getItem(mediaId: String, result: Result<MediaItem>) =
|
fun getItem(mediaId: String, result: Result<MediaItem>) =
|
||||||
result.dispatch { musicBrowser.getItem(mediaId) }
|
result.dispatch { musicBrowser.getItem(mediaId) }
|
||||||
|
|
||||||
fun getChildren(
|
fun getChildren(mediaId: String, maxTabs: Int, result: Result<MutableList<MediaItem>>) =
|
||||||
mediaId: String,
|
result.dispatch { musicBrowser.getChildren(mediaId, maxTabs)?.toMutableList() }
|
||||||
maxTabs: Int,
|
|
||||||
result: Result<MutableList<MediaItem>>,
|
|
||||||
page: Page?,
|
|
||||||
) = result.dispatch { musicBrowser.getChildren(mediaId, maxTabs)?.expose(page) }
|
|
||||||
|
|
||||||
fun search(query: String, result: Result<MutableList<MediaItem>>, page: Page?) =
|
fun search(query: String, result: Result<MutableList<MediaItem>>) =
|
||||||
result.dispatchAsync { musicBrowser.search(query).expose(page) }
|
result.dispatchAsync { musicBrowser.search(query) }
|
||||||
|
|
||||||
private fun <T> Result<T>.dispatch(body: () -> T?) {
|
private fun <T> Result<T>.dispatch(body: () -> T?) {
|
||||||
try {
|
try {
|
||||||
@@ -145,15 +141,4 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T> List<T>.expose(page: Page?): MutableList<T> {
|
|
||||||
if (page == null) return toMutableList()
|
|
||||||
val start = page.num * page.size
|
|
||||||
val end = start + page.size
|
|
||||||
return if (start >= size) {
|
|
||||||
mutableListOf()
|
|
||||||
} else {
|
|
||||||
subList(start, end.coerceAtMost(size)).toMutableList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user