-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
193 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -692,3 +692,6 @@ name = "DiscTotal" | |
|
||
[[keys]] | ||
name = "Encoder" | ||
|
||
[[keys]] | ||
name = "HintAddMediaFolders" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/io/github/zyrouge/symphony/services/settings/SettingsKeys.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/src/main/java/io/github/zyrouge/symphony/ui/helpers/Modifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.github.zyrouge.symphony.ui.helpers | ||
|
||
import androidx.compose.ui.Modifier | ||
|
||
fun Modifier.applyIf(value: Boolean, fn: Modifier.() -> Modifier) = when { | ||
value -> fn() | ||
else -> this | ||
} |
82 changes: 55 additions & 27 deletions
82
app/src/main/java/io/github/zyrouge/symphony/ui/helpers/Routes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,79 @@ | ||
package io.github.zyrouge.symphony.ui.helpers | ||
|
||
import android.net.Uri | ||
import androidx.navigation.NamedNavArgument | ||
import androidx.navigation.NavBackStackEntry | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.NavType | ||
import androidx.navigation.navArgument | ||
import io.github.zyrouge.symphony.services.groove.Groove | ||
import io.github.zyrouge.symphony.ui.view.SettingsViewElements | ||
|
||
abstract class Route(val route: String) { | ||
class Simple(route: String) : Route(route) | ||
abstract class Simple(route: String) : Route(route) { | ||
override fun template() = route | ||
} | ||
|
||
abstract class Parameterized<T>(route: String) : Route(route) { | ||
override fun template() = "$route/{$ARGUMENT_NAME}" | ||
abstract fun build(param: T): String | ||
|
||
companion object { | ||
const val ARGUMENT_NAME = "param" | ||
} | ||
override fun template() = "$route/{$PARAM_ARGUMENT_NAME}" | ||
abstract fun buildParam(param: T): String | ||
fun build(param: T) = "$route/${encodeArgument(buildParam(param))}" | ||
} | ||
|
||
class StringParameterized(route: String) : Parameterized<String>(route) { | ||
override fun build(param: String) = withParam(param) | ||
abstract class StringParameterized(route: String) : Parameterized<String>(route) { | ||
override fun template() = "$route/{$PARAM_ARGUMENT_NAME}" | ||
override fun buildParam(param: String) = param | ||
} | ||
|
||
open fun template() = route | ||
abstract fun template(): String | ||
open fun arguments(): List<NamedNavArgument> = emptyList() | ||
|
||
companion object { | ||
const val PARAM_ARGUMENT_NAME = "param" | ||
|
||
protected fun withParam(param: String) = "$route/${encodeParam(param)}" | ||
protected fun encodeParam(param: String): String = Uri.encode(param) | ||
fun encodeArgument(param: String): String = Uri.encode(param) | ||
} | ||
} | ||
|
||
data object Routes { | ||
val Home = Route.Simple("home") | ||
val NowPlaying = Route.Simple("now_playing") | ||
val Queue = Route.Simple("queue") | ||
val Settings = Route.Simple("settings") | ||
val Search = object : Route.Parameterized<Groove.Kinds?>("search") { | ||
override fun build(param: Groove.Kinds?) = withParam(param?.name ?: "null") | ||
object Routes { | ||
object Home : Route.Simple("home") | ||
|
||
object NowPlaying : Route.Simple("now_playing") | ||
object Queue : Route.Simple("queue") | ||
|
||
object Settings : Route("settings") { | ||
const val ELEMENT_ARGUMENT_NAME = "element" | ||
|
||
override fun template() = "$route?$ELEMENT_ARGUMENT_NAME={$ELEMENT_ARGUMENT_NAME}" | ||
override fun arguments() = listOf( | ||
navArgument(ELEMENT_ARGUMENT_NAME) { | ||
type = NavType.StringType | ||
nullable = true | ||
}, | ||
) | ||
|
||
fun build(settingsViewElement: SettingsViewElements? = null) = buildString { | ||
append(route) | ||
if (settingsViewElement != null) { | ||
append("?$ELEMENT_ARGUMENT_NAME=${encodeArgument(settingsViewElement.name)}") | ||
} | ||
} | ||
} | ||
val Artist = Route.StringParameterized("artist") | ||
val Album = Route.StringParameterized("album") | ||
val AlbumArtist = Route.StringParameterized("album_artist") | ||
val Genre = Route.StringParameterized("genre") | ||
val Playlist = Route.StringParameterized("playlist") | ||
val Lyrics = Route.Simple("lyrics") | ||
|
||
object Search : Route.Parameterized<Groove.Kinds?>("search") { | ||
override fun buildParam(param: Groove.Kinds?) = param?.name ?: "null" | ||
} | ||
|
||
object Artist : Route.StringParameterized("artist") | ||
object Album : Route.StringParameterized("album") | ||
object AlbumArtist : Route.StringParameterized("album_artist") | ||
object Genre : Route.StringParameterized("genre") | ||
object Playlist : Route.StringParameterized("playlist") | ||
object Lyrics : Route.Simple("lyrics") | ||
} | ||
|
||
fun NavHostController.navigateTo(route: Route.Simple) = navigate(route.route) | ||
fun NavHostController.navigateTo(route: String) = navigate(route) | ||
|
||
fun NavBackStackEntry.getRouteArgument(key: String) = arguments?.getString(key) | ||
fun NavBackStackEntry.getRouteParameter() = | ||
getRouteArgument(Route.Parameterized.ARGUMENT_NAME) ?: "" | ||
fun NavBackStackEntry.getRouteParameter() = getRouteArgument(Route.PARAM_ARGUMENT_NAME) ?: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.