From ea06f863144de246f330072defd722806930d5f8 Mon Sep 17 00:00:00 2001 From: Zyrouge Date: Mon, 11 Nov 2024 22:45:09 +0530 Subject: [PATCH] refactor: bypass navigation enum not found --- .../symphony/services/groove/Groove.kt | 2 -- .../symphony/ui/components/SongList.kt | 3 +-- .../github/zyrouge/symphony/ui/view/Search.kt | 25 ++++++++++++++++++- .../zyrouge/symphony/ui/view/Settings.kt | 10 ++++---- .../ui/view/settings/GrooveSettingsView.kt | 6 ++--- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/github/zyrouge/symphony/services/groove/Groove.kt b/app/src/main/java/io/github/zyrouge/symphony/services/groove/Groove.kt index a1b455d0..1422a111 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/services/groove/Groove.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/services/groove/Groove.kt @@ -14,10 +14,8 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.launch -import kotlinx.serialization.Serializable class Groove(private val symphony: Symphony) : Symphony.Hooks { - @Serializable enum class Kinds { SONG, ALBUM, diff --git a/app/src/main/java/io/github/zyrouge/symphony/ui/components/SongList.kt b/app/src/main/java/io/github/zyrouge/symphony/ui/components/SongList.kt index 0ac2ffb0..271553d6 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/ui/components/SongList.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/ui/components/SongList.kt @@ -27,7 +27,6 @@ import io.github.zyrouge.symphony.services.groove.Song import io.github.zyrouge.symphony.services.groove.repositories.SongRepository import io.github.zyrouge.symphony.services.radio.Radio import io.github.zyrouge.symphony.ui.helpers.ViewContext -import io.github.zyrouge.symphony.ui.view.SettingsViewElements import io.github.zyrouge.symphony.ui.view.SettingsViewRoute enum class SongListType { @@ -97,7 +96,7 @@ fun SongList( modifier = Modifier .clickable { context.navController.navigate( - SettingsViewRoute(SettingsViewElements.MediaFolders) + SettingsViewRoute(SettingsViewRoute.ELEMENT_MEDIA_FOLDERS) ) } .padding(2.dp), diff --git a/app/src/main/java/io/github/zyrouge/symphony/ui/view/Search.kt b/app/src/main/java/io/github/zyrouge/symphony/ui/view/Search.kt index 47cbae99..9a8bc5f8 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/ui/view/Search.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/ui/view/Search.kt @@ -69,7 +69,12 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder private data class SearchResult( val songIds: List, @@ -81,7 +86,25 @@ private data class SearchResult( ) @Serializable -data class SearchViewRoute(val initialChip: Groove.Kinds?) +data class SearchViewRoute( + @Serializable(with = GrooveKindsSerializer::class) val initialChip: Groove.Kinds?, +) { + // NOTE: seems like r8 obfuscates the class, which makes compose navigator to find this class, this is a temporary fix + companion object { + object GrooveKindsSerializer : KSerializer { + override val descriptor = PrimitiveSerialDescriptor( + "Groove.Kinds", + PrimitiveKind.STRING, + ) + + override fun serialize(encoder: Encoder, value: Groove.Kinds) = + encoder.encodeString(value.name) + + override fun deserialize(decoder: Decoder) = + enumValueOf(decoder.decodeString()) + } + } +} @OptIn(ExperimentalMaterial3Api::class) @Composable diff --git a/app/src/main/java/io/github/zyrouge/symphony/ui/view/Settings.kt b/app/src/main/java/io/github/zyrouge/symphony/ui/view/Settings.kt index a891f945..7df8586c 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/ui/view/Settings.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/ui/view/Settings.kt @@ -58,12 +58,12 @@ import io.github.zyrouge.symphony.ui.view.settings.UpdateSettingsViewRoute import io.github.zyrouge.symphony.utils.ActivityUtils import kotlinx.serialization.Serializable -enum class SettingsViewElements { - MediaFolders, -} - @Serializable -data class SettingsViewRoute(val initialElement: SettingsViewElements? = null) +data class SettingsViewRoute(val initialElement: String? = null) { + companion object { + const val ELEMENT_MEDIA_FOLDERS = "media_folders" + } +} @OptIn(ExperimentalMaterial3Api::class) @Composable diff --git a/app/src/main/java/io/github/zyrouge/symphony/ui/view/settings/GrooveSettingsView.kt b/app/src/main/java/io/github/zyrouge/symphony/ui/view/settings/GrooveSettingsView.kt index bb57157f..7d41c693 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/ui/view/settings/GrooveSettingsView.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/ui/view/settings/GrooveSettingsView.kt @@ -66,14 +66,14 @@ import io.github.zyrouge.symphony.ui.components.settings.SettingsSimpleTile import io.github.zyrouge.symphony.ui.components.settings.SettingsTextInputTile import io.github.zyrouge.symphony.ui.helpers.TransitionDurations import io.github.zyrouge.symphony.ui.helpers.ViewContext -import io.github.zyrouge.symphony.ui.view.SettingsViewElements +import io.github.zyrouge.symphony.ui.view.SettingsViewRoute import io.github.zyrouge.symphony.utils.ActivityUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import kotlinx.serialization.Serializable @Serializable -data class GrooveSettingsViewRoute(val initialElement: SettingsViewElements?) +data class GrooveSettingsViewRoute(val initialElement: String? = null) @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -177,7 +177,7 @@ fun GrooveSettingsView(context: ViewContext, route: GrooveSettingsViewRoute) { } } SettingsSideHeading(context.symphony.t.Groove) - SpotlightTile(route.initialElement == SettingsViewElements.MediaFolders) { + SpotlightTile(route.initialElement == SettingsViewRoute.ELEMENT_MEDIA_FOLDERS) { SettingsMultiSystemFolderTile( context, icon = {