all: build fixes

This commit is contained in:
Alexander Capehart 2024-09-13 13:35:39 -06:00
parent 3832c4e525
commit fcd4ef3dc8
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
8 changed files with 102 additions and 33 deletions

View file

@ -1,5 +1,24 @@
/*
* Copyright (c) 2024 Auxio Project
* HomeGenerator.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.home
import javax.inject.Inject
import org.oxycblt.auxio.home.tabs.Tab
import org.oxycblt.auxio.list.ListSettings
import org.oxycblt.auxio.list.adapter.UpdateInstructions
@ -14,15 +33,22 @@ import org.oxycblt.auxio.util.logD
interface HomeGenerator {
fun songs(): List<Song>
fun albums(): List<Album>
fun artists(): List<Artist>
fun genres(): List<Genre>
fun playlists(): List<Playlist>
fun tabs(): List<MusicType>
fun release()
interface Invalidator {
fun invalidateMusic(type: MusicType, instructions: UpdateInstructions)
fun invalidateTabs()
}
@ -31,6 +57,17 @@ interface HomeGenerator {
}
}
class HomeGeneratorFactoryImpl
@Inject
constructor(
private val homeSettings: HomeSettings,
private val listSettings: ListSettings,
private val musicRepository: MusicRepository,
) : HomeGenerator.Factory {
override fun create(invalidator: HomeGenerator.Invalidator): HomeGenerator =
HomeGeneratorImpl(invalidator, homeSettings, listSettings, musicRepository)
}
private class HomeGeneratorImpl(
private val invalidator: HomeGenerator.Invalidator,
private val homeSettings: HomeSettings,
@ -39,13 +76,24 @@ private class HomeGeneratorImpl(
) : HomeGenerator, HomeSettings.Listener, ListSettings.Listener, MusicRepository.UpdateListener {
override fun songs() =
musicRepository.deviceLibrary?.let { listSettings.songSort.songs(it.songs) } ?: emptyList()
override fun albums() = musicRepository.deviceLibrary?.let { listSettings.albumSort.albums(it.albums) } ?: emptyList()
override fun artists() = musicRepository.deviceLibrary?.let { listSettings.artistSort.artists(it.artists) } ?: emptyList()
override fun genres() = musicRepository.deviceLibrary?.let { listSettings.genreSort.genres(it.genres) } ?: emptyList()
override fun playlists() = musicRepository.userLibrary?.let { listSettings.playlistSort.playlists(it.playlists) } ?: emptyList()
override fun tabs() =
homeSettings.homeTabs.filterIsInstance<Tab.Visible>().map { it.type }
override fun albums() =
musicRepository.deviceLibrary?.let { listSettings.albumSort.albums(it.albums) }
?: emptyList()
override fun artists() =
musicRepository.deviceLibrary?.let { listSettings.artistSort.artists(it.artists) }
?: emptyList()
override fun genres() =
musicRepository.deviceLibrary?.let { listSettings.genreSort.genres(it.genres) }
?: emptyList()
override fun playlists() =
musicRepository.userLibrary?.let { listSettings.playlistSort.playlists(it.playlists) }
?: emptyList()
override fun tabs() = homeSettings.homeTabs.filterIsInstance<Tab.Visible>().map { it.type }
override fun onTabsChanged() {
invalidator.invalidateTabs()
@ -113,5 +161,4 @@ private class HomeGeneratorImpl(
invalidator.invalidateMusic(MusicType.PLAYLISTS, UpdateInstructions.Diff)
}
}
}

View file

@ -27,4 +27,6 @@ import dagger.hilt.components.SingletonComponent
@InstallIn(SingletonComponent::class)
interface HomeModule {
@Binds fun settings(homeSettings: HomeSettingsImpl): HomeSettings
@Binds fun homeGeneratorFactory(factory: HomeGeneratorFactoryImpl): HomeGenerator.Factory
}

View file

@ -24,7 +24,6 @@ import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import org.oxycblt.auxio.home.tabs.Tab
import org.oxycblt.auxio.home.tabs.TabListGenerator
import org.oxycblt.auxio.list.ListSettings
import org.oxycblt.auxio.list.adapter.UpdateInstructions
import org.oxycblt.auxio.list.sort.Sort

View file

@ -38,7 +38,8 @@ class AdaptiveTabStrategy(context: Context, private val tabs: List<MusicType>) :
override fun onConfigureTab(tab: TabLayout.Tab, position: Int) {
val homeTab = tabs[position]
val icon = when (homeTab) {
val icon =
when (homeTab) {
MusicType.SONGS -> R.drawable.ic_song_24
MusicType.ALBUMS -> R.drawable.ic_album_24
MusicType.ARTISTS -> R.drawable.ic_artist_24

View file

@ -46,9 +46,13 @@ interface ListSettings : Settings<ListSettings.Listener> {
interface Listener {
fun onSongSortChanged() {}
fun onAlbumSortChanged() {}
fun onArtistSortChanged() {}
fun onGenreSortChanged() {}
fun onPlaylistSortChanged() {}
}
}

View file

@ -175,9 +175,7 @@ constructor(
return music
}
private fun getMediaItemList(
id: String
): List<MediaItem>? {
private fun getMediaItemList(id: String): List<MediaItem>? {
return when (val mediaSessionUID = MediaSessionUID.fromString(id)) {
is MediaSessionUID.Tab -> {
getCategoryMediaItems(mediaSessionUID.node)
@ -194,9 +192,7 @@ constructor(
}
}
private fun getCategoryMediaItems(
node: TabNode
) =
private fun getCategoryMediaItems(node: TabNode) =
when (node) {
is TabNode.Root -> {
val tabs = homeGenerator.tabs()
@ -210,7 +206,8 @@ constructor(
}
is TabNode.More ->
homeGenerator.tabs().takeLast(node.remainder).map {
TabNode.Home(it).toMediaItem(context) }
TabNode.Home(it).toMediaItem(context)
}
is TabNode.Home ->
when (node.type) {
MusicType.SONGS -> homeGenerator.songs().map { it.toMediaItem(context, null) }

View file

@ -83,7 +83,7 @@ constructor(
fun getRoot(maxItems: Int) =
BrowserRoot(
MediaSessionUID.CategoryItem(Category.Root(maxItems)).toString(),
MediaSessionUID.Tab(TabNode.Root(maxItems)).toString(),
Bundle().apply {
val actions =
BrowserOption.entries.mapTo(ArrayList()) {

View file

@ -1,7 +1,24 @@
/*
* Copyright (c) 2024 Auxio Project
* TabNode.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
import org.oxycblt.auxio.home.tabs.Tab
import org.oxycblt.auxio.music.MusicType
sealed class TabNode {
@ -38,13 +55,15 @@ sealed class TabNode {
override val id = ID
override val data = type.intCode
override val bitmapRes: Int
get() = when (type) {
get() =
when (type) {
MusicType.SONGS -> R.drawable.ic_song_bitmap_24
MusicType.ALBUMS -> R.drawable.ic_album_bitmap_24
MusicType.ARTISTS -> R.drawable.ic_artist_bitmap_24
MusicType.GENRES -> R.drawable.ic_genre_bitmap_24
MusicType.PLAYLISTS -> R.drawable.ic_playlist_bitmap_24
}
override val nameRes = type.nameRes
companion object {