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 package org.oxycblt.auxio.home
import javax.inject.Inject
import org.oxycblt.auxio.home.tabs.Tab import org.oxycblt.auxio.home.tabs.Tab
import org.oxycblt.auxio.list.ListSettings import org.oxycblt.auxio.list.ListSettings
import org.oxycblt.auxio.list.adapter.UpdateInstructions import org.oxycblt.auxio.list.adapter.UpdateInstructions
@ -14,15 +33,22 @@ import org.oxycblt.auxio.util.logD
interface HomeGenerator { interface HomeGenerator {
fun songs(): List<Song> fun songs(): List<Song>
fun albums(): List<Album> fun albums(): List<Album>
fun artists(): List<Artist> fun artists(): List<Artist>
fun genres(): List<Genre> fun genres(): List<Genre>
fun playlists(): List<Playlist> fun playlists(): List<Playlist>
fun tabs(): List<MusicType> fun tabs(): List<MusicType>
fun release() fun release()
interface Invalidator { interface Invalidator {
fun invalidateMusic(type: MusicType, instructions: UpdateInstructions) fun invalidateMusic(type: MusicType, instructions: UpdateInstructions)
fun invalidateTabs() 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 class HomeGeneratorImpl(
private val invalidator: HomeGenerator.Invalidator, private val invalidator: HomeGenerator.Invalidator,
private val homeSettings: HomeSettings, private val homeSettings: HomeSettings,
@ -39,13 +76,24 @@ private class HomeGeneratorImpl(
) : HomeGenerator, HomeSettings.Listener, ListSettings.Listener, MusicRepository.UpdateListener { ) : HomeGenerator, HomeSettings.Listener, ListSettings.Listener, MusicRepository.UpdateListener {
override fun songs() = override fun songs() =
musicRepository.deviceLibrary?.let { listSettings.songSort.songs(it.songs) } ?: emptyList() 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() { override fun onTabsChanged() {
invalidator.invalidateTabs() invalidator.invalidateTabs()
@ -113,5 +161,4 @@ private class HomeGeneratorImpl(
invalidator.invalidateMusic(MusicType.PLAYLISTS, UpdateInstructions.Diff) invalidator.invalidateMusic(MusicType.PLAYLISTS, UpdateInstructions.Diff)
} }
} }
}
}

View file

@ -27,4 +27,6 @@ import dagger.hilt.components.SingletonComponent
@InstallIn(SingletonComponent::class) @InstallIn(SingletonComponent::class)
interface HomeModule { interface HomeModule {
@Binds fun settings(homeSettings: HomeSettingsImpl): HomeSettings @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.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import org.oxycblt.auxio.home.tabs.Tab 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.ListSettings
import org.oxycblt.auxio.list.adapter.UpdateInstructions import org.oxycblt.auxio.list.adapter.UpdateInstructions
import org.oxycblt.auxio.list.sort.Sort import org.oxycblt.auxio.list.sort.Sort

View file

@ -38,13 +38,14 @@ class AdaptiveTabStrategy(context: Context, private val tabs: List<MusicType>) :
override fun onConfigureTab(tab: TabLayout.Tab, position: Int) { override fun onConfigureTab(tab: TabLayout.Tab, position: Int) {
val homeTab = tabs[position] val homeTab = tabs[position]
val icon = when (homeTab) { val icon =
MusicType.SONGS -> R.drawable.ic_song_24 when (homeTab) {
MusicType.ALBUMS -> R.drawable.ic_album_24 MusicType.SONGS -> R.drawable.ic_song_24
MusicType.ARTISTS -> R.drawable.ic_artist_24 MusicType.ALBUMS -> R.drawable.ic_album_24
MusicType.GENRES -> R.drawable.ic_genre_24 MusicType.ARTISTS -> R.drawable.ic_artist_24
MusicType.PLAYLISTS -> R.drawable.ic_playlist_24 MusicType.GENRES -> R.drawable.ic_genre_24
} MusicType.PLAYLISTS -> R.drawable.ic_playlist_24
}
// Use expected sw* size thresholds when choosing a configuration. // Use expected sw* size thresholds when choosing a configuration.
when { when {

View file

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

View file

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

View file

@ -83,7 +83,7 @@ constructor(
fun getRoot(maxItems: Int) = fun getRoot(maxItems: Int) =
BrowserRoot( BrowserRoot(
MediaSessionUID.CategoryItem(Category.Root(maxItems)).toString(), MediaSessionUID.Tab(TabNode.Root(maxItems)).toString(),
Bundle().apply { Bundle().apply {
val actions = val actions =
BrowserOption.entries.mapTo(ArrayList()) { 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 package org.oxycblt.auxio.music.service
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.home.tabs.Tab
import org.oxycblt.auxio.music.MusicType import org.oxycblt.auxio.music.MusicType
sealed class TabNode { sealed class TabNode {
@ -38,13 +55,15 @@ sealed class TabNode {
override val id = ID override val id = ID
override val data = type.intCode override val data = type.intCode
override val bitmapRes: Int override val bitmapRes: Int
get() = when (type) { get() =
MusicType.SONGS -> R.drawable.ic_song_bitmap_24 when (type) {
MusicType.ALBUMS -> R.drawable.ic_album_bitmap_24 MusicType.SONGS -> R.drawable.ic_song_bitmap_24
MusicType.ARTISTS -> R.drawable.ic_artist_bitmap_24 MusicType.ALBUMS -> R.drawable.ic_album_bitmap_24
MusicType.GENRES -> R.drawable.ic_genre_bitmap_24 MusicType.ARTISTS -> R.drawable.ic_artist_bitmap_24
MusicType.PLAYLISTS -> R.drawable.ic_playlist_bitmap_24 MusicType.GENRES -> R.drawable.ic_genre_bitmap_24
} MusicType.PLAYLISTS -> R.drawable.ic_playlist_bitmap_24
}
override val nameRes = type.nameRes override val nameRes = type.nameRes
companion object { companion object {
@ -67,4 +86,4 @@ sealed class TabNode {
} }
} }
} }
} }