diff --git a/app/src/main/java/org/oxycblt/auxio/home/HomeGenerator.kt b/app/src/main/java/org/oxycblt/auxio/home/HomeGenerator.kt
index 2da76e2e7..5c551db0e 100644
--- a/app/src/main/java/org/oxycblt/auxio/home/HomeGenerator.kt
+++ b/app/src/main/java/org/oxycblt/auxio/home/HomeGenerator.kt
@@ -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 .
+ */
+
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
+
fun albums(): List
+
fun artists(): List
+
fun genres(): List
+
fun playlists(): List
+
fun tabs(): List
+
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().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().map { it.type }
override fun onTabsChanged() {
invalidator.invalidateTabs()
@@ -113,5 +161,4 @@ private class HomeGeneratorImpl(
invalidator.invalidateMusic(MusicType.PLAYLISTS, UpdateInstructions.Diff)
}
}
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/org/oxycblt/auxio/home/HomeModule.kt b/app/src/main/java/org/oxycblt/auxio/home/HomeModule.kt
index a578b6e07..e7e2f9118 100644
--- a/app/src/main/java/org/oxycblt/auxio/home/HomeModule.kt
+++ b/app/src/main/java/org/oxycblt/auxio/home/HomeModule.kt
@@ -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
}
diff --git a/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt b/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt
index b2d62a6b6..206b4bd0a 100644
--- a/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt
+++ b/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt
@@ -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
diff --git a/app/src/main/java/org/oxycblt/auxio/home/tabs/AdaptiveTabStrategy.kt b/app/src/main/java/org/oxycblt/auxio/home/tabs/AdaptiveTabStrategy.kt
index 237d8edd6..45f63fd7d 100644
--- a/app/src/main/java/org/oxycblt/auxio/home/tabs/AdaptiveTabStrategy.kt
+++ b/app/src/main/java/org/oxycblt/auxio/home/tabs/AdaptiveTabStrategy.kt
@@ -38,13 +38,14 @@ class AdaptiveTabStrategy(context: Context, private val tabs: List) :
override fun onConfigureTab(tab: TabLayout.Tab, position: Int) {
val homeTab = tabs[position]
- 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
- MusicType.GENRES -> R.drawable.ic_genre_24
- MusicType.PLAYLISTS -> R.drawable.ic_playlist_24
- }
+ 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
+ MusicType.GENRES -> R.drawable.ic_genre_24
+ MusicType.PLAYLISTS -> R.drawable.ic_playlist_24
+ }
// Use expected sw* size thresholds when choosing a configuration.
when {
diff --git a/app/src/main/java/org/oxycblt/auxio/list/ListSettings.kt b/app/src/main/java/org/oxycblt/auxio/list/ListSettings.kt
index 9b0bb7f4f..c817dcf0e 100644
--- a/app/src/main/java/org/oxycblt/auxio/list/ListSettings.kt
+++ b/app/src/main/java/org/oxycblt/auxio/list/ListSettings.kt
@@ -46,9 +46,13 @@ interface ListSettings : Settings {
interface Listener {
fun onSongSortChanged() {}
+
fun onAlbumSortChanged() {}
+
fun onArtistSortChanged() {}
+
fun onGenreSortChanged() {}
+
fun onPlaylistSortChanged() {}
}
}
diff --git a/app/src/main/java/org/oxycblt/auxio/music/service/MusicBrowser.kt b/app/src/main/java/org/oxycblt/auxio/music/service/MusicBrowser.kt
index 0ab9db8db..8fe591f98 100644
--- a/app/src/main/java/org/oxycblt/auxio/music/service/MusicBrowser.kt
+++ b/app/src/main/java/org/oxycblt/auxio/music/service/MusicBrowser.kt
@@ -175,9 +175,7 @@ constructor(
return music
}
- private fun getMediaItemList(
- id: String
- ): List? {
+ private fun getMediaItemList(id: String): List? {
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) }
diff --git a/app/src/main/java/org/oxycblt/auxio/music/service/MusicServiceFragment.kt b/app/src/main/java/org/oxycblt/auxio/music/service/MusicServiceFragment.kt
index ba26d4778..b3617ee5d 100644
--- a/app/src/main/java/org/oxycblt/auxio/music/service/MusicServiceFragment.kt
+++ b/app/src/main/java/org/oxycblt/auxio/music/service/MusicServiceFragment.kt
@@ -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()) {
diff --git a/app/src/main/java/org/oxycblt/auxio/music/service/TabNode.kt b/app/src/main/java/org/oxycblt/auxio/music/service/TabNode.kt
index 02a4aa595..1e9705511 100644
--- a/app/src/main/java/org/oxycblt/auxio/music/service/TabNode.kt
+++ b/app/src/main/java/org/oxycblt/auxio/music/service/TabNode.kt
@@ -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 .
+ */
+
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) {
- 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
- }
+ 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 {
@@ -67,4 +86,4 @@ sealed class TabNode {
}
}
}
-}
\ No newline at end of file
+}