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?
|
||||
): BrowserRoot {
|
||||
val maximumRootChildLimit =
|
||||
rootHints?.getInt(
|
||||
MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_LIMIT, 4) ?: 4
|
||||
rootHints?.getInt(MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_LIMIT, 4) ?: 4
|
||||
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
|
||||
|
||||
import org.oxycblt.auxio.R
|
||||
|
@ -79,6 +97,7 @@ sealed interface Category {
|
|||
val MUSIC = arrayOf(Songs, Albums, Artists, Genres, Playlists)
|
||||
val DEVICE_MUSIC = arrayOf(Songs, Albums, Artists, Genres)
|
||||
val USER_MUSIC = arrayOf(Playlists)
|
||||
|
||||
fun fromString(str: String): Category? =
|
||||
when {
|
||||
str.startsWith(Root.ID_PREFIX) -> Root.fromString(str)
|
||||
|
|
|
@ -60,8 +60,7 @@ sealed interface MediaSessionUID {
|
|||
return null
|
||||
}
|
||||
return when (parts[0]) {
|
||||
ID_CATEGORY ->
|
||||
CategoryItem(Category.fromString(parts[1]) ?: return null)
|
||||
ID_CATEGORY -> CategoryItem(Category.fromString(parts[1]) ?: return null)
|
||||
ID_ITEM -> {
|
||||
val uids = parts[1].split(">", limit = 2)
|
||||
if (uids.size == 1) {
|
||||
|
|
|
@ -186,7 +186,11 @@ constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getCategoryMediaItems(category: Category, deviceLibrary: DeviceLibrary, userLibrary: UserLibrary) =
|
||||
private fun getCategoryMediaItems(
|
||||
category: Category,
|
||||
deviceLibrary: DeviceLibrary,
|
||||
userLibrary: UserLibrary
|
||||
) =
|
||||
when (category) {
|
||||
is Category.Root -> {
|
||||
val base = Category.MUSIC.take(category.amount)
|
||||
|
@ -194,27 +198,23 @@ constructor(
|
|||
base + Category.More(Category.MUSIC.size - base.size)
|
||||
} else {
|
||||
base
|
||||
}.map { it.toMediaItem(context) }
|
||||
}
|
||||
is Category.More -> Category.MUSIC.takeLast(category.remainder).map {
|
||||
it.toMediaItem(context)
|
||||
.map { it.toMediaItem(context) }
|
||||
}
|
||||
is Category.More ->
|
||||
Category.MUSIC.takeLast(category.remainder).map { it.toMediaItem(context) }
|
||||
is Category.Songs ->
|
||||
listSettings.songSort.songs(deviceLibrary.songs).map {
|
||||
it.toMediaItem(context, null)
|
||||
}
|
||||
is Category.Albums ->
|
||||
listSettings.albumSort.albums(deviceLibrary.albums).map {
|
||||
it.toMediaItem(context)
|
||||
}
|
||||
listSettings.albumSort.albums(deviceLibrary.albums).map { it.toMediaItem(context) }
|
||||
is Category.Artists ->
|
||||
listSettings.artistSort.artists(deviceLibrary.artists).map {
|
||||
it.toMediaItem(context)
|
||||
}
|
||||
is Category.Genres ->
|
||||
listSettings.genreSort.genres(deviceLibrary.genres).map {
|
||||
it.toMediaItem(context)
|
||||
}
|
||||
listSettings.genreSort.genres(deviceLibrary.genres).map { it.toMediaItem(context) }
|
||||
is Category.Playlists -> userLibrary.playlists.map { it.toMediaItem(context) }
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
package org.oxycblt.auxio.music.service
|
||||
|
||||
import android.support.v4.media.MediaBrowserCompat.MediaItem
|
||||
import androidx.media.MediaBrowserServiceCompat.Result
|
||||
import androidx.media.MediaBrowserServiceCompat.BrowserRoot
|
||||
import androidx.media.MediaBrowserServiceCompat.Result
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -82,10 +82,8 @@ constructor(
|
|||
fun getItem(mediaId: String, result: Result<MediaItem>) =
|
||||
result.dispatch { musicBrowser.getItem(mediaId) }
|
||||
|
||||
fun getChildren(
|
||||
mediaId: String,
|
||||
result: Result<MutableList<MediaItem>>
|
||||
) = result.dispatch { musicBrowser.getChildren(mediaId)?.toMutableList() }
|
||||
fun getChildren(mediaId: String, result: Result<MutableList<MediaItem>>) =
|
||||
result.dispatch { musicBrowser.getChildren(mediaId)?.toMutableList() }
|
||||
|
||||
fun search(query: String, result: Result<MutableList<MediaItem>>) =
|
||||
result.dispatchAsync { musicBrowser.search(query) }
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.oxycblt.auxio.playback.system
|
|||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.media.session.MediaSession
|
||||
import android.support.v4.media.MediaDescriptionCompat
|
||||
import android.support.v4.media.MediaMetadataCompat
|
||||
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
|
||||
|
||||
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.PlaybackStateCompat
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
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.RepeatMode
|
||||
import org.oxycblt.auxio.playback.state.ShuffleMode
|
||||
import javax.inject.Inject
|
||||
|
||||
class MediaSessionInterface @Inject constructor(
|
||||
class MediaSessionInterface
|
||||
@Inject
|
||||
constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val playbackManager: PlaybackStateManager,
|
||||
private val commandFactory: PlaybackCommand.Factory,
|
||||
|
@ -130,15 +150,13 @@ class MediaSessionInterface @Inject constructor(
|
|||
PlaybackStateCompat.REPEAT_MODE_GROUP -> RepeatMode.ALL
|
||||
PlaybackStateCompat.REPEAT_MODE_ONE -> RepeatMode.TRACK
|
||||
else -> RepeatMode.NONE
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
override fun onSetShuffleMode(shuffleMode: Int) {
|
||||
playbackManager.shuffled(
|
||||
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_ALL ||
|
||||
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_GROUP
|
||||
)
|
||||
shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_GROUP)
|
||||
}
|
||||
|
||||
override fun onSkipToQueueItem(id: Long) {
|
||||
|
@ -164,12 +182,10 @@ class MediaSessionInterface @Inject constructor(
|
|||
is MediaSessionUID.SingleItem -> {
|
||||
music = musicRepository.find(uid.uid) ?: return null
|
||||
}
|
||||
|
||||
is MediaSessionUID.ChildItem -> {
|
||||
music = musicRepository.find(uid.childUid) ?: return null
|
||||
parent = musicRepository.find(uid.parentUid) as? MusicParent ?: return null
|
||||
}
|
||||
|
||||
else -> return null
|
||||
}
|
||||
|
||||
|
@ -187,10 +203,8 @@ class MediaSessionInterface @Inject constructor(
|
|||
is Album -> commandFactory.songFromAlbum(music, ShuffleMode.IMPLICIT)
|
||||
is Artist -> commandFactory.songFromArtist(music, parent, ShuffleMode.IMPLICIT)
|
||||
?: commandFactory.songFromArtist(music, music.artists[0], ShuffleMode.IMPLICIT)
|
||||
|
||||
is Genre -> commandFactory.songFromGenre(music, parent, ShuffleMode.IMPLICIT)
|
||||
?: commandFactory.songFromGenre(music, music.genres[0], ShuffleMode.IMPLICIT)
|
||||
|
||||
is Playlist -> commandFactory.songFromPlaylist(music, parent, ShuffleMode.IMPLICIT)
|
||||
null -> commandFactory.songFromAll(music, ShuffleMode.IMPLICIT)
|
||||
}
|
||||
|
|
|
@ -108,81 +108,4 @@ constructor(
|
|||
override fun onSessionEnded() {
|
||||
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