all: cleanup
This commit is contained in:
parent
44f9617307
commit
3dea060a28
8 changed files with 65 additions and 114 deletions
|
@ -86,8 +86,7 @@ class AuxioService :
|
||||||
rootHints: Bundle?
|
rootHints: Bundle?
|
||||||
): BrowserRoot {
|
): BrowserRoot {
|
||||||
val maximumRootChildLimit =
|
val maximumRootChildLimit =
|
||||||
rootHints?.getInt(
|
rootHints?.getInt(MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_LIMIT, 4) ?: 4
|
||||||
MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_LIMIT, 4) ?: 4
|
|
||||||
return musicFragment.getRoot(maximumRootChildLimit)
|
return musicFragment.getRoot(maximumRootChildLimit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Auxio Project
|
||||||
|
* Category.kt is part of Auxio.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.oxycblt.auxio.music.service
|
package org.oxycblt.auxio.music.service
|
||||||
|
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
|
@ -79,6 +97,7 @@ sealed interface Category {
|
||||||
val MUSIC = arrayOf(Songs, Albums, Artists, Genres, Playlists)
|
val MUSIC = arrayOf(Songs, Albums, Artists, Genres, Playlists)
|
||||||
val DEVICE_MUSIC = arrayOf(Songs, Albums, Artists, Genres)
|
val DEVICE_MUSIC = arrayOf(Songs, Albums, Artists, Genres)
|
||||||
val USER_MUSIC = arrayOf(Playlists)
|
val USER_MUSIC = arrayOf(Playlists)
|
||||||
|
|
||||||
fun fromString(str: String): Category? =
|
fun fromString(str: String): Category? =
|
||||||
when {
|
when {
|
||||||
str.startsWith(Root.ID_PREFIX) -> Root.fromString(str)
|
str.startsWith(Root.ID_PREFIX) -> Root.fromString(str)
|
||||||
|
@ -91,4 +110,4 @@ sealed interface Category {
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,7 @@ sealed interface MediaSessionUID {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return when (parts[0]) {
|
return when (parts[0]) {
|
||||||
ID_CATEGORY ->
|
ID_CATEGORY -> CategoryItem(Category.fromString(parts[1]) ?: return null)
|
||||||
CategoryItem(Category.fromString(parts[1]) ?: return null)
|
|
||||||
ID_ITEM -> {
|
ID_ITEM -> {
|
||||||
val uids = parts[1].split(">", limit = 2)
|
val uids = parts[1].split(">", limit = 2)
|
||||||
if (uids.size == 1) {
|
if (uids.size == 1) {
|
||||||
|
|
|
@ -186,35 +186,35 @@ constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCategoryMediaItems(category: Category, deviceLibrary: DeviceLibrary, userLibrary: UserLibrary) =
|
private fun getCategoryMediaItems(
|
||||||
|
category: Category,
|
||||||
|
deviceLibrary: DeviceLibrary,
|
||||||
|
userLibrary: UserLibrary
|
||||||
|
) =
|
||||||
when (category) {
|
when (category) {
|
||||||
is Category.Root -> {
|
is Category.Root -> {
|
||||||
val base = Category.MUSIC.take(category.amount)
|
val base = Category.MUSIC.take(category.amount)
|
||||||
if (base.size < Category.MUSIC.size) {
|
if (base.size < Category.MUSIC.size) {
|
||||||
base + Category.More(Category.MUSIC.size - base.size)
|
base + Category.More(Category.MUSIC.size - base.size)
|
||||||
} else {
|
} else {
|
||||||
base
|
base
|
||||||
}.map { it.toMediaItem(context) }
|
}
|
||||||
}
|
.map { it.toMediaItem(context) }
|
||||||
is Category.More -> Category.MUSIC.takeLast(category.remainder).map {
|
|
||||||
it.toMediaItem(context)
|
|
||||||
}
|
}
|
||||||
|
is Category.More ->
|
||||||
|
Category.MUSIC.takeLast(category.remainder).map { it.toMediaItem(context) }
|
||||||
is Category.Songs ->
|
is Category.Songs ->
|
||||||
listSettings.songSort.songs(deviceLibrary.songs).map {
|
listSettings.songSort.songs(deviceLibrary.songs).map {
|
||||||
it.toMediaItem(context, null)
|
it.toMediaItem(context, null)
|
||||||
}
|
}
|
||||||
is Category.Albums ->
|
is Category.Albums ->
|
||||||
listSettings.albumSort.albums(deviceLibrary.albums).map {
|
listSettings.albumSort.albums(deviceLibrary.albums).map { it.toMediaItem(context) }
|
||||||
it.toMediaItem(context)
|
|
||||||
}
|
|
||||||
is Category.Artists ->
|
is Category.Artists ->
|
||||||
listSettings.artistSort.artists(deviceLibrary.artists).map {
|
listSettings.artistSort.artists(deviceLibrary.artists).map {
|
||||||
it.toMediaItem(context)
|
it.toMediaItem(context)
|
||||||
}
|
}
|
||||||
is Category.Genres ->
|
is Category.Genres ->
|
||||||
listSettings.genreSort.genres(deviceLibrary.genres).map {
|
listSettings.genreSort.genres(deviceLibrary.genres).map { it.toMediaItem(context) }
|
||||||
it.toMediaItem(context)
|
|
||||||
}
|
|
||||||
is Category.Playlists -> userLibrary.playlists.map { it.toMediaItem(context) }
|
is Category.Playlists -> userLibrary.playlists.map { it.toMediaItem(context) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
package org.oxycblt.auxio.music.service
|
package org.oxycblt.auxio.music.service
|
||||||
|
|
||||||
import android.support.v4.media.MediaBrowserCompat.MediaItem
|
import android.support.v4.media.MediaBrowserCompat.MediaItem
|
||||||
import androidx.media.MediaBrowserServiceCompat.Result
|
|
||||||
import androidx.media.MediaBrowserServiceCompat.BrowserRoot
|
import androidx.media.MediaBrowserServiceCompat.BrowserRoot
|
||||||
|
import androidx.media.MediaBrowserServiceCompat.Result
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -82,10 +82,8 @@ 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, result: Result<MutableList<MediaItem>>) =
|
||||||
mediaId: String,
|
result.dispatch { musicBrowser.getChildren(mediaId)?.toMutableList() }
|
||||||
result: Result<MutableList<MediaItem>>
|
|
||||||
) = result.dispatch { musicBrowser.getChildren(mediaId)?.toMutableList() }
|
|
||||||
|
|
||||||
fun search(query: String, result: Result<MutableList<MediaItem>>) =
|
fun search(query: String, result: Result<MutableList<MediaItem>>) =
|
||||||
result.dispatchAsync { musicBrowser.search(query) }
|
result.dispatchAsync { musicBrowser.search(query) }
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.oxycblt.auxio.playback.system
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.media.session.MediaSession
|
|
||||||
import android.support.v4.media.MediaDescriptionCompat
|
import android.support.v4.media.MediaDescriptionCompat
|
||||||
import android.support.v4.media.MediaMetadataCompat
|
import android.support.v4.media.MediaMetadataCompat
|
||||||
import android.support.v4.media.session.MediaSessionCompat
|
import android.support.v4.media.session.MediaSessionCompat
|
||||||
|
|
|
@ -1,3 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Auxio Project
|
||||||
|
* MediaSessionInterface.kt is part of Auxio.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.oxycblt.auxio.playback.service
|
package org.oxycblt.auxio.playback.service
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
@ -8,6 +26,7 @@ import android.support.v4.media.MediaDescriptionCompat
|
||||||
import android.support.v4.media.session.MediaSessionCompat
|
import android.support.v4.media.session.MediaSessionCompat
|
||||||
import android.support.v4.media.session.PlaybackStateCompat
|
import android.support.v4.media.session.PlaybackStateCompat
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import javax.inject.Inject
|
||||||
import org.oxycblt.auxio.music.Album
|
import org.oxycblt.auxio.music.Album
|
||||||
import org.oxycblt.auxio.music.Artist
|
import org.oxycblt.auxio.music.Artist
|
||||||
import org.oxycblt.auxio.music.Genre
|
import org.oxycblt.auxio.music.Genre
|
||||||
|
@ -21,9 +40,10 @@ import org.oxycblt.auxio.playback.state.PlaybackCommand
|
||||||
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
||||||
import org.oxycblt.auxio.playback.state.RepeatMode
|
import org.oxycblt.auxio.playback.state.RepeatMode
|
||||||
import org.oxycblt.auxio.playback.state.ShuffleMode
|
import org.oxycblt.auxio.playback.state.ShuffleMode
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class MediaSessionInterface @Inject constructor(
|
class MediaSessionInterface
|
||||||
|
@Inject
|
||||||
|
constructor(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
private val playbackManager: PlaybackStateManager,
|
private val playbackManager: PlaybackStateManager,
|
||||||
private val commandFactory: PlaybackCommand.Factory,
|
private val commandFactory: PlaybackCommand.Factory,
|
||||||
|
@ -130,15 +150,13 @@ class MediaSessionInterface @Inject constructor(
|
||||||
PlaybackStateCompat.REPEAT_MODE_GROUP -> RepeatMode.ALL
|
PlaybackStateCompat.REPEAT_MODE_GROUP -> RepeatMode.ALL
|
||||||
PlaybackStateCompat.REPEAT_MODE_ONE -> RepeatMode.TRACK
|
PlaybackStateCompat.REPEAT_MODE_ONE -> RepeatMode.TRACK
|
||||||
else -> RepeatMode.NONE
|
else -> RepeatMode.NONE
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSetShuffleMode(shuffleMode: Int) {
|
override fun onSetShuffleMode(shuffleMode: Int) {
|
||||||
playbackManager.shuffled(
|
playbackManager.shuffled(
|
||||||
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_ALL ||
|
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_ALL ||
|
||||||
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_GROUP
|
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_GROUP)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSkipToQueueItem(id: Long) {
|
override fun onSkipToQueueItem(id: Long) {
|
||||||
|
@ -164,12 +182,10 @@ class MediaSessionInterface @Inject constructor(
|
||||||
is MediaSessionUID.SingleItem -> {
|
is MediaSessionUID.SingleItem -> {
|
||||||
music = musicRepository.find(uid.uid) ?: return null
|
music = musicRepository.find(uid.uid) ?: return null
|
||||||
}
|
}
|
||||||
|
|
||||||
is MediaSessionUID.ChildItem -> {
|
is MediaSessionUID.ChildItem -> {
|
||||||
music = musicRepository.find(uid.childUid) ?: return null
|
music = musicRepository.find(uid.childUid) ?: return null
|
||||||
parent = musicRepository.find(uid.parentUid) as? MusicParent ?: return null
|
parent = musicRepository.find(uid.parentUid) as? MusicParent ?: return null
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,11 +202,9 @@ class MediaSessionInterface @Inject constructor(
|
||||||
when (parent) {
|
when (parent) {
|
||||||
is Album -> commandFactory.songFromAlbum(music, ShuffleMode.IMPLICIT)
|
is Album -> commandFactory.songFromAlbum(music, ShuffleMode.IMPLICIT)
|
||||||
is Artist -> commandFactory.songFromArtist(music, parent, ShuffleMode.IMPLICIT)
|
is Artist -> commandFactory.songFromArtist(music, parent, ShuffleMode.IMPLICIT)
|
||||||
?: commandFactory.songFromArtist(music, music.artists[0], ShuffleMode.IMPLICIT)
|
?: commandFactory.songFromArtist(music, music.artists[0], ShuffleMode.IMPLICIT)
|
||||||
|
|
||||||
is Genre -> commandFactory.songFromGenre(music, parent, ShuffleMode.IMPLICIT)
|
is Genre -> commandFactory.songFromGenre(music, parent, ShuffleMode.IMPLICIT)
|
||||||
?: commandFactory.songFromGenre(music, music.genres[0], ShuffleMode.IMPLICIT)
|
?: commandFactory.songFromGenre(music, music.genres[0], ShuffleMode.IMPLICIT)
|
||||||
|
|
||||||
is Playlist -> commandFactory.songFromPlaylist(music, parent, ShuffleMode.IMPLICIT)
|
is Playlist -> commandFactory.songFromPlaylist(music, parent, ShuffleMode.IMPLICIT)
|
||||||
null -> commandFactory.songFromAll(music, ShuffleMode.IMPLICIT)
|
null -> commandFactory.songFromAll(music, ShuffleMode.IMPLICIT)
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,81 +108,4 @@ constructor(
|
||||||
override fun onSessionEnded() {
|
override fun onSessionEnded() {
|
||||||
foregroundListener?.updateForeground(ForegroundListener.Change.MEDIA_SESSION)
|
foregroundListener?.updateForeground(ForegroundListener.Change.MEDIA_SESSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
// override fun onGetLibraryRoot(
|
|
||||||
// session: MediaLibrarySession,
|
|
||||||
// browser: MediaSession.ControllerInfo,
|
|
||||||
// params: MediaLibraryService.LibraryParams?
|
|
||||||
// ): ListenableFuture<LibraryResult<MediaItem>> =
|
|
||||||
// Futures.immediateFuture(LibraryResult.ofItem(mediaItemBrowser.root, params))
|
|
||||||
//
|
|
||||||
// override fun onGetItem(
|
|
||||||
// session: MediaLibrarySession,
|
|
||||||
// browser: MediaSession.ControllerInfo,
|
|
||||||
// mediaId: String
|
|
||||||
// ): ListenableFuture<LibraryResult<MediaItem>> {
|
|
||||||
// val result =
|
|
||||||
// mediaItemBrowser.getItem(mediaId)?.let { LibraryResult.ofItem(it, null) }
|
|
||||||
// ?: LibraryResult.ofError(LibraryResult.RESULT_ERROR_BAD_VALUE)
|
|
||||||
// return Futures.immediateFuture(result)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onSetMediaItems(
|
|
||||||
// mediaSession: MediaSession,
|
|
||||||
// controller: MediaSession.ControllerInfo,
|
|
||||||
// mediaItems: MutableList<MediaItem>,
|
|
||||||
// startIndex: Int,
|
|
||||||
// startPositionMs: Long
|
|
||||||
// ): ListenableFuture<MediaSession.MediaItemsWithStartPosition> =
|
|
||||||
// Futures.immediateFuture(
|
|
||||||
// MediaSession.MediaItemsWithStartPosition(mediaItems, startIndex, startPositionMs))
|
|
||||||
//
|
|
||||||
// override fun onGetChildren(
|
|
||||||
// session: MediaLibrarySession,
|
|
||||||
// browser: MediaSession.ControllerInfo,
|
|
||||||
// parentId: String,
|
|
||||||
// page: Int,
|
|
||||||
// pageSize: Int,
|
|
||||||
// params: MediaLibraryService.LibraryParams?
|
|
||||||
// ): ListenableFuture<LibraryResult<ImmutableList<MediaItem>>> {
|
|
||||||
// val children =
|
|
||||||
// mediaItemBrowser.getChildren(parentId, page, pageSize)?.let {
|
|
||||||
// LibraryResult.ofItemList(it, params)
|
|
||||||
// }
|
|
||||||
// ?: LibraryResult.ofError<ImmutableList<MediaItem>>(
|
|
||||||
// LibraryResult.RESULT_ERROR_BAD_VALUE)
|
|
||||||
// return Futures.immediateFuture(children)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onSearch(
|
|
||||||
// session: MediaLibrarySession,
|
|
||||||
// browser: MediaSession.ControllerInfo,
|
|
||||||
// query: String,
|
|
||||||
// params: MediaLibraryService.LibraryParams?
|
|
||||||
// ): ListenableFuture<LibraryResult<Void>> =
|
|
||||||
// waitScope
|
|
||||||
// .async {
|
|
||||||
// mediaItemBrowser.prepareSearch(query, browser)
|
|
||||||
// // Invalidator will send the notify result
|
|
||||||
// LibraryResult.ofVoid()
|
|
||||||
// }
|
|
||||||
// .asListenableFuture()
|
|
||||||
//
|
|
||||||
// override fun onGetSearchResult(
|
|
||||||
// session: MediaLibrarySession,
|
|
||||||
// browser: MediaSession.ControllerInfo,
|
|
||||||
// query: String,
|
|
||||||
// page: Int,
|
|
||||||
// pageSize: Int,
|
|
||||||
// params: MediaLibraryService.LibraryParams?
|
|
||||||
// ) =
|
|
||||||
// waitScope
|
|
||||||
// .async {
|
|
||||||
// mediaItemBrowser.getSearchResult(query, page, pageSize)?.let {
|
|
||||||
// LibraryResult.ofItemList(it, params)
|
|
||||||
// }
|
|
||||||
// ?: LibraryResult.ofError(LibraryResult.RESULT_ERROR_BAD_VALUE)
|
|
||||||
// }
|
|
||||||
// .asListenableFuture()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue