Skip to content

Commit

Permalink
refactor: hint to add media folders
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Oct 28, 2024
1 parent c07cfc3 commit a5e2ada
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 71 deletions.
3 changes: 3 additions & 0 deletions .phrasey/schema.toml
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,6 @@ name = "DiscTotal"

[[keys]]
name = "Encoder"

[[keys]]
name = "HintAddMediaFolders"
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import io.github.zyrouge.symphony.ui.view.home.ForYou
import io.github.zyrouge.symphony.utils.StringListUtils

@Suppress("ConstPropertyName")
object SettingsDefaults {
data object SettingsDefaults {
val themeMode = ThemeMode.SYSTEM
const val useMaterialYou = true
val lastUsedSongSortBy = SongRepository.SortBy.TITLE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.zyrouge.symphony.services.settings

@Suppress("ConstPropertyName")
object SettingsKeys {
data object SettingsKeys {
const val identifier = "settings"
const val themeMode = "theme_mode"
const val language = "language"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
import androidx.compose.ui.unit.dp

object ContentDrawScopeScrollBarDefaults {
data object ContentDrawScopeScrollBarDefaults {
val scrollPointerWidth = 4.dp
val scrollPointerHeight = 16.dp
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
package io.github.zyrouge.symphony.ui.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MusicNote
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import io.github.zyrouge.symphony.services.groove.Groove
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.Routes
import io.github.zyrouge.symphony.ui.helpers.ViewContext
import io.github.zyrouge.symphony.ui.helpers.navigateTo
import io.github.zyrouge.symphony.ui.view.SettingsViewElements

enum class SongListType {
Default,
Expand All @@ -39,6 +49,7 @@ fun SongList(
cardThumbnailLabelStyle: SongCardThumbnailLabelStyle = SongCardThumbnailLabelStyle.Default,
type: SongListType = SongListType.Default,
disableHeartIcon: Boolean = false,
enableAddMediaFoldersHint: Boolean = false,
) {
val sortBy by type.getLastUsedSortBy(context).collectAsState()
val sortReverse by type.getLastUsedSortReverse(context).collectAsState()
Expand Down Expand Up @@ -74,13 +85,26 @@ fun SongList(
when {
songIds.isEmpty() -> IconTextBody(
icon = { modifier ->
Icon(
Icons.Filled.MusicNote,
null,
modifier = modifier,
)
Icon(Icons.Filled.MusicNote, null, modifier = modifier)
},
content = { Text(context.symphony.t.DamnThisIsSoEmpty) }
content = {
Text(context.symphony.t.DamnThisIsSoEmpty)
if (enableAddMediaFoldersHint) {
Spacer(modifier = Modifier.height(4.dp))
Text(
context.symphony.t.HintAddMediaFolders,
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Center,
modifier = Modifier
.clickable {
context.navController.navigateTo(
Routes.Settings.build(SettingsViewElements.MediaFolders)
)
}
.padding(2.dp),
)
}
}
)

else -> {
Expand Down
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 app/src/main/java/io/github/zyrouge/symphony/ui/helpers/Routes.kt
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) ?: ""
10 changes: 8 additions & 2 deletions app/src/main/java/io/github/zyrouge/symphony/ui/view/Base.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.github.zyrouge.symphony.ui.helpers.Routes
import io.github.zyrouge.symphony.ui.helpers.ScaleTransition
import io.github.zyrouge.symphony.ui.helpers.SlideTransition
import io.github.zyrouge.symphony.ui.helpers.ViewContext
import io.github.zyrouge.symphony.ui.helpers.getRouteArgument
import io.github.zyrouge.symphony.ui.helpers.getRouteParameter
import io.github.zyrouge.symphony.ui.theme.SymphonyTheme

Expand Down Expand Up @@ -55,10 +56,15 @@ fun BaseView(symphony: Symphony, activity: MainActivity) {
}
composable(
Routes.Settings.template(),
arguments = Routes.Settings.arguments(),
enterTransition = { ScaleTransition.scaleDown.enterTransition() },
exitTransition = { ScaleTransition.scaleUp.exitTransition() },
) {
SettingsView(context)
) { backStackEntry ->
SettingsView(
context,
initialElement = backStackEntry.getRouteArgument(Routes.Settings.ELEMENT_ARGUMENT_NAME)
?.let { SettingsViewElements.valueOf(it) },
)
}
composable(
Routes.Artist.template(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fun HomeView(context: ViewContext) {
},
onClick = {
showOptionsDropdown = false
context.navController.navigateTo(Routes.Settings)
context.navController.navigateTo(Routes.Settings.build())
}
)
}
Expand Down
Loading

0 comments on commit a5e2ada

Please sign in to comment.