-
Notifications
You must be signed in to change notification settings - Fork 4
Prepare dynamic theme choosing #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
9 changes: 9 additions & 0 deletions
9
panel-core/src/main/kotlin/com/redmadrobot/debug/core/data/storage/model/ThemeData.kt
This file contains hidden or 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,9 @@ | ||
| package com.redmadrobot.debug.core.data.storage.model | ||
|
|
||
| import com.redmadrobot.debug.uikit.theme.model.ThemeMode | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| internal data class ThemeData( | ||
| val themeMode: ThemeMode = ThemeMode.System, | ||
| ) |
23 changes: 23 additions & 0 deletions
23
...core/src/main/kotlin/com/redmadrobot/debug/core/data/storage/theme/ThemeDataSerializer.kt
This file contains hidden or 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,23 @@ | ||
| package com.redmadrobot.debug.core.data.storage.theme | ||
|
|
||
| import androidx.datastore.core.Serializer | ||
| import com.redmadrobot.debug.core.data.storage.model.ThemeData | ||
| import kotlinx.serialization.ExperimentalSerializationApi | ||
| import kotlinx.serialization.json.Json | ||
| import kotlinx.serialization.json.decodeFromStream | ||
| import kotlinx.serialization.json.encodeToStream | ||
| import java.io.InputStream | ||
| import java.io.OutputStream | ||
|
|
||
| @OptIn(ExperimentalSerializationApi::class) | ||
| internal object ThemeDataSerializer : Serializer<ThemeData> { | ||
| override val defaultValue: ThemeData = ThemeData() | ||
|
|
||
| override suspend fun readFrom(input: InputStream): ThemeData { | ||
| return Json.decodeFromStream(input) | ||
| } | ||
|
|
||
| override suspend fun writeTo(themeData: ThemeData, output: OutputStream) { | ||
| Json.encodeToStream(themeData, output) | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
panel-core/src/main/kotlin/com/redmadrobot/debug/core/data/storage/theme/ThemeDataStore.kt
This file contains hidden or 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,24 @@ | ||
| package com.redmadrobot.debug.core.data.storage.theme | ||
|
|
||
| import android.content.Context | ||
| import com.redmadrobot.debug.uikit.theme.model.ThemeMode | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.first | ||
| import kotlinx.coroutines.flow.map | ||
| import kotlinx.coroutines.runBlocking | ||
|
|
||
| internal class ThemeDataStore(private val context: Context) { | ||
| private val dataStore by lazy { context.themeStorage } | ||
|
|
||
| fun getSelectedTheme(): ThemeMode { | ||
| return runBlocking { dataStore.data.first().themeMode } | ||
| } | ||
|
|
||
| fun observeThemeMode(): Flow<ThemeMode> { | ||
| return dataStore.data.map { it.themeMode } | ||
| } | ||
|
|
||
| suspend fun saveThemeMode(mode: ThemeMode) { | ||
| dataStore.updateData { data -> data.copy(themeMode = mode) } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
panel-core/src/main/kotlin/com/redmadrobot/debug/core/data/storage/theme/ThemeStorage.kt
This file contains hidden or 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,9 @@ | ||
| package com.redmadrobot.debug.core.data.storage.theme | ||
|
|
||
| import android.content.Context | ||
| import androidx.datastore.dataStore | ||
|
|
||
| internal val Context.themeStorage by dataStore( | ||
| fileName = "debug_panel_theme.json", | ||
| serializer = ThemeDataSerializer, | ||
| ) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
65 changes: 65 additions & 0 deletions
65
panel-ui-kit/src/main/kotlin/com/redmadrobot/debug/uikit/components/ThemeSwitcher.kt
This file contains hidden or 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,65 @@ | ||
| package com.redmadrobot.debug.uikit.components | ||
|
|
||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.material3.DropdownMenu | ||
| import androidx.compose.material3.DropdownMenuItem | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.IconButton | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.key | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.unit.dp | ||
| import com.redmadrobot.debug.uikit.theme.DebugPanelTheme | ||
| import com.redmadrobot.debug.uikit.theme.model.ThemeMode | ||
|
|
||
| @Composable | ||
| public fun ThemeSwitcher( | ||
| currentMode: ThemeMode, | ||
| onModeSelect: (ThemeMode) -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| var expanded by remember { mutableStateOf(false) } | ||
|
|
||
| IconButton(onClick = { expanded = true }, modifier = modifier) { | ||
| Icon( | ||
| painter = painterResource(id = ThemeMode.getIconRes(mode = currentMode)), | ||
| contentDescription = null, | ||
| tint = DebugPanelTheme.colors.content.secondary, | ||
| modifier = Modifier.size(size = 20.dp), | ||
| ) | ||
| DropdownMenu( | ||
| expanded = expanded, | ||
| onDismissRequest = { expanded = false }, | ||
| ) { | ||
| ThemeMode.entries.forEach { mode -> | ||
| key(mode.name) { | ||
| DropdownMenuItem( | ||
| title = stringResource(id = ThemeMode.getTitleRes(mode = mode)), | ||
| onModeSelect = { | ||
| onModeSelect.invoke(mode) | ||
| expanded = false | ||
| } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun DropdownMenuItem( | ||
| title: String, | ||
| onModeSelect: () -> Unit | ||
| ) { | ||
| DropdownMenuItem( | ||
| text = { Text(text = title, style = DebugPanelTheme.typography.bodyMedium) }, | ||
| onClick = { onModeSelect() }, | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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
22 changes: 22 additions & 0 deletions
22
panel-ui-kit/src/main/kotlin/com/redmadrobot/debug/uikit/theme/DebugPanelDimensions.kt
This file contains hidden or 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,22 @@ | ||
| package com.redmadrobot.debug.uikit.theme | ||
|
|
||
| import androidx.compose.ui.unit.Dp | ||
| import androidx.compose.ui.unit.dp | ||
|
|
||
| public object DebugPanelDimensions { | ||
| // Common | ||
| public val topBarHeight: Dp = 56.dp | ||
| public val tabRowHeight: Dp = 48.dp | ||
| public val bottomBarHeight: Dp = 56.dp | ||
| public val rowMinHeight: Dp = 48.dp | ||
|
|
||
| // Toggles | ||
| public val toggleWidth: Dp = 44.dp | ||
| public val toggleHeight: Dp = 24.dp | ||
| public val dotSize: Dp = 10.dp | ||
|
|
||
| // Icons | ||
| public val iconSizeSmall: Dp = 20.dp | ||
| public val iconSizeMedium: Dp = 24.dp | ||
| public val iconSizeLarge: Dp = 32.dp | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
panel-ui-kit/src/main/kotlin/com/redmadrobot/debug/uikit/theme/DebugPanelShapes.kt
This file contains hidden or 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,11 @@ | ||
| package com.redmadrobot.debug.uikit.theme | ||
|
|
||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.ui.unit.dp | ||
|
|
||
| public object DebugPanelShapes { | ||
| public val small: RoundedCornerShape = RoundedCornerShape(4.dp) | ||
| public val medium: RoundedCornerShape = RoundedCornerShape(8.dp) | ||
| public val large: RoundedCornerShape = RoundedCornerShape(20.dp) | ||
| public val dialog: RoundedCornerShape = RoundedCornerShape(28.dp) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.