Skip to content

Commit

Permalink
refactor: bypass navigation enum not found
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Nov 11, 2024
1 parent f94792e commit ea06f86
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -97,7 +96,7 @@ fun SongList(
modifier = Modifier
.clickable {
context.navController.navigate(
SettingsViewRoute(SettingsViewElements.MediaFolders)
SettingsViewRoute(SettingsViewRoute.ELEMENT_MEDIA_FOLDERS)
)
}
.padding(2.dp),
Expand Down
25 changes: 24 additions & 1 deletion app/src/main/java/io/github/zyrouge/symphony/ui/view/Search.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand All @@ -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<Groove.Kinds> {
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<Groove.Kinds>(decoder.decodeString())
}
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/io/github/zyrouge/symphony/ui/view/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit ea06f86

Please sign in to comment.