Skip to content

Commit

Permalink
all: build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OxygenCobalt committed Sep 9, 2024
1 parent 4f28253 commit 90814a6
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 33 deletions.
63 changes: 55 additions & 8 deletions app/src/main/java/org/oxycblt/auxio/home/HomeGenerator.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
}

Expand All @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -113,5 +161,4 @@ private class HomeGeneratorImpl(
invalidator.invalidateMusic(MusicType.PLAYLISTS, UpdateInstructions.Diff)
}
}

}
}
2 changes: 2 additions & 0 deletions app/src/main/java/org/oxycblt/auxio/home/HomeModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 0 additions & 1 deletion app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ 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) {
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 {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/org/oxycblt/auxio/list/ListSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ interface ListSettings : Settings<ListSettings.Listener> {

interface Listener {
fun onSongSortChanged() {}

fun onAlbumSortChanged() {}

fun onArtistSortChanged() {}

fun onGenreSortChanged() {}

fun onPlaylistSortChanged() {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -194,9 +192,7 @@ constructor(
}
}

private fun getCategoryMediaItems(
node: TabNode
) =
private fun getCategoryMediaItems(node: TabNode) =
when (node) {
is TabNode.Root -> {
val tabs = homeGenerator.tabs()
Expand All @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
37 changes: 28 additions & 9 deletions app/src/main/java/org/oxycblt/auxio/music/service/TabNode.kt
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -67,4 +86,4 @@ sealed class TabNode {
}
}
}
}
}

0 comments on commit 90814a6

Please sign in to comment.