diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 1a1eba59..2550c887 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -22,20 +22,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 777b5b2f..7d068716 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -90,6 +90,17 @@ android {
"${versionName}.apk"
}
}
+
+ kotlinOptions {
+ freeCompilerArgs += listOf(
+ // Apply compose_compiler_config.conf
+ "-P",
+ "plugin:androidx.compose.compiler.plugins.kotlin:stabilityConfigurationPath=${project.rootDir.absolutePath}/compose_compiler_config.conf",
+ // Enable strong skipping
+ "-P",
+ "plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true"
+ )
+ }
}
// https://github.com/Triple-T/gradle-play-publisher
diff --git a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/WidgetConfigurationDialog.kt b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/WidgetConfigurationDialog.kt
index 4c9c6ceb..d394ff5d 100644
--- a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/WidgetConfigurationDialog.kt
+++ b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/WidgetConfigurationDialog.kt
@@ -17,14 +17,15 @@ import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog
import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.components.ColorPickerProperties
import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.components.PropertyInfoDialog
import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.model.InfoDialogData
-import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.model.UnconfirmedWidgetConfiguration
+import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.model.ReversibleWidgetConfiguration
import com.w2sv.wifiwidget.ui.utils.isLandscapeModeActivated
import com.w2sv.wifiwidget.ui.utils.thenIf
+import kotlinx.coroutines.flow.update
@Composable
fun WidgetConfigurationDialog(
locationAccessState: LocationAccessState,
- widgetConfiguration: UnconfirmedWidgetConfiguration,
+ widgetConfiguration: ReversibleWidgetConfiguration,
closeDialog: () -> Unit,
modifier: Modifier = Modifier,
) {
@@ -82,8 +83,14 @@ fun WidgetConfigurationDialog(
properties = properties,
applyColor = remember {
{
- widgetConfiguration.customColoringData.value =
- properties.createCustomColoringData(widgetConfiguration.customColoringData.value)
+ widgetConfiguration.coloringConfig.update {
+ it.copy(
+ custom = properties.createCustomColoringData(
+ it.custom
+ )
+ )
+ }
+
}
},
onDismissRequest = {
diff --git a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/WidgetConfigurationDialogContent.kt b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/WidgetConfigurationDialogContent.kt
index 9521c16d..4d802e3d 100644
--- a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/WidgetConfigurationDialogContent.kt
+++ b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/WidgetConfigurationDialogContent.kt
@@ -29,7 +29,7 @@ import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog
import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.components.PropertyCheckRowColumn
import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.model.InfoDialogData
import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.model.PropertyCheckRowData
-import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.model.UnconfirmedWidgetConfiguration
+import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.model.ReversibleWidgetConfiguration
import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.model.getInfoDialogData
import com.w2sv.wifiwidget.ui.utils.ShakeConfig
import com.w2sv.wifiwidget.ui.utils.ShakeController
@@ -51,7 +51,7 @@ private data class Section(
@Composable
fun WidgetConfigurationDialogContent(
- widgetConfiguration: UnconfirmedWidgetConfiguration,
+ widgetConfiguration: ReversibleWidgetConfiguration,
locationAccessState: LocationAccessState,
showPropertyInfoDialog: (InfoDialogData) -> Unit,
showCustomColorConfigurationDialog: (ColorPickerProperties) -> Unit,
@@ -74,19 +74,22 @@ fun WidgetConfigurationDialogContent(
),
) {
AppearanceConfiguration(
- presetColoringData = widgetConfiguration.presetColoringData.collectAsStateWithLifecycle().value,
- setPresetColoringData = {
- widgetConfiguration.presetColoringData.value = it
+ coloringConfig = widgetConfiguration.coloringConfig.collectAsStateWithLifecycle().value,
+ setColoringConfig = remember {
+ {
+ widgetConfiguration.coloringConfig.value = it
+ }
},
- customColoringData = widgetConfiguration.customColoringData.collectAsStateWithLifecycle().value,
- coloring = widgetConfiguration.coloring.collectAsStateWithLifecycle().value,
- setColoring = { widgetConfiguration.coloring.value = it },
opacity = widgetConfiguration.opacity.collectAsStateWithLifecycle().value,
- setOpacity = {
- widgetConfiguration.opacity.value = it
+ setOpacity = remember {
+ {
+ widgetConfiguration.opacity.value = it
+ }
},
fontSize = widgetConfiguration.fontSize.collectAsStateWithLifecycle().value,
- setFontSize = { widgetConfiguration.fontSize.value = it },
+ setFontSize = remember {
+ { widgetConfiguration.fontSize.value = it }
+ },
showCustomColorConfigurationDialog = showCustomColorConfigurationDialog,
modifier = Modifier.padding(horizontal = 16.dp)
)
@@ -177,7 +180,7 @@ fun WidgetConfigurationDialogContent(
@Composable
private fun rememberWidgetWifiPropertyCheckRowData(
- widgetConfiguration: UnconfirmedWidgetConfiguration,
+ widgetConfiguration: ReversibleWidgetConfiguration,
locationAccessState: LocationAccessState,
): ImmutableList> {
val context = LocalContext.current
@@ -283,7 +286,7 @@ private fun rememberWidgetWifiPropertyCheckRowData(
}
}
-private fun UnconfirmedWidgetConfiguration.moreThanOnePropertyChecked(): Boolean =
+private fun ReversibleWidgetConfiguration.moreThanOnePropertyChecked(): Boolean =
wifiProperties.values.count { it } > 1
private val shakeConfig = ShakeConfig(
diff --git a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/components/AppearanceConfiguration.kt b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/components/AppearanceConfiguration.kt
index 3caa68bb..c242b8df 100644
--- a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/components/AppearanceConfiguration.kt
+++ b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/components/AppearanceConfiguration.kt
@@ -46,11 +46,8 @@ private val verticalPadding = 12.dp
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppearanceConfiguration(
- presetColoringData: WidgetColoring.Data.Preset,
- setPresetColoringData: (WidgetColoring.Data.Preset) -> Unit,
- customColoringData: WidgetColoring.Data.Custom,
- coloring: WidgetColoring,
- setColoring: (WidgetColoring) -> Unit,
+ coloringConfig: WidgetColoring.Config,
+ setColoringConfig: (WidgetColoring.Config) -> Unit,
opacity: Float,
setOpacity: (Float) -> Unit,
fontSize: FontSize,
@@ -64,32 +61,37 @@ fun AppearanceConfiguration(
.padding(bottom = verticalPadding)
.align(Alignment.CenterHorizontally)
) {
- WidgetColoring.entries.forEach {
+ coloringConfig.styles.forEachIndexed { i, style ->
SegmentedButton(
- selected = it == coloring,
- onClick = { setColoring(it) },
+ selected = style.javaClass == coloringConfig.appliedStyle.javaClass,
+ onClick = remember(i) {
+ { setColoringConfig(coloringConfig.copy(isCustomSelected = style is WidgetColoring.Style.Custom)) }
+ },
shape = SegmentedButtonDefaults.itemShape(
- index = it.ordinal,
- count = WidgetColoring.entries.size
+ index = i,
+ count = 2
)
) {
- Text(text = stringResource(id = it.labelRes))
+ Text(text = stringResource(id = style.labelRes))
}
}
}
- AnimatedContent(targetState = coloring, label = "") {
- when (it) {
- WidgetColoring.Preset -> {
+ AnimatedContent(
+ targetState = coloringConfig.isCustomSelected,
+ label = ""
+ ) { isCustomStyleSelected ->
+ when (isCustomStyleSelected) {
+ false -> {
PresetColoringConfiguration(
- data = presetColoringData,
- setData = setPresetColoringData
+ data = coloringConfig.preset,
+ setData = remember { { setColoringConfig(coloringConfig.copy(preset = it)) } }
)
}
- WidgetColoring.Custom -> {
+ true -> {
CustomColorConfiguration(
- data = customColoringData,
+ data = coloringConfig.custom,
showCustomColorConfigurationDialog = showCustomColorConfigurationDialog
)
}
@@ -133,8 +135,8 @@ fun AppearanceConfiguration(
@Composable
private fun PresetColoringConfiguration(
- data: WidgetColoring.Data.Preset,
- setData: (WidgetColoring.Data.Preset) -> Unit,
+ data: WidgetColoring.Style.Preset,
+ setData: (WidgetColoring.Style.Preset) -> Unit,
modifier: Modifier = Modifier
) {
Column(modifier = modifier) {
@@ -159,12 +161,12 @@ private fun PresetColoringConfiguration(
}
}
-enum class WidgetColorType(@StringRes val labelRes: Int) {
+enum class CustomWidgetColor(@StringRes val labelRes: Int) {
Background(com.w2sv.core.domain.R.string.background),
Primary(com.w2sv.core.domain.R.string.primary),
Secondary(com.w2sv.core.domain.R.string.secondary);
- fun getColor(data: WidgetColoring.Data.Custom): Color =
+ fun getColor(data: WidgetColoring.Style.Custom): Color =
Color(
when (this) {
Background -> data.background
@@ -176,12 +178,12 @@ enum class WidgetColorType(@StringRes val labelRes: Int) {
@Composable
private fun CustomColorConfiguration(
- data: WidgetColoring.Data.Custom,
+ data: WidgetColoring.Style.Custom,
showCustomColorConfigurationDialog: (ColorPickerProperties) -> Unit,
modifier: Modifier = Modifier,
) {
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {
- WidgetColorType.entries
+ CustomWidgetColor.entries
.forEach { widgetColorType ->
val color = remember(widgetColorType, data) {
widgetColorType.getColor(data)
@@ -192,7 +194,7 @@ private fun CustomColorConfiguration(
onClick = {
showCustomColorConfigurationDialog(
ColorPickerProperties(
- widgetColorType = widgetColorType,
+ customWidgetColor = widgetColorType,
appliedColor = color
)
)
diff --git a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/components/ColorPickerDialog.kt b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/components/ColorPickerDialog.kt
index 1f156aea..0f20425d 100644
--- a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/components/ColorPickerDialog.kt
+++ b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/components/ColorPickerDialog.kt
@@ -25,12 +25,12 @@ import com.w2sv.wifiwidget.ui.utils.nullableListSaver
@Stable
class ColorPickerProperties(
- val widgetColorType: WidgetColorType,
+ val customWidgetColor: CustomWidgetColor,
private val appliedColor: Color,
initialColor: Color
) {
- constructor(widgetColorType: WidgetColorType, appliedColor: Color) : this(
- widgetColorType = widgetColorType,
+ constructor(customWidgetColor: CustomWidgetColor, appliedColor: Color) : this(
+ customWidgetColor = customWidgetColor,
appliedColor = appliedColor,
initialColor = appliedColor
)
@@ -41,21 +41,21 @@ class ColorPickerProperties(
color != appliedColor
}
- fun createCustomColoringData(data: WidgetColoring.Data.Custom): WidgetColoring.Data.Custom =
- when (widgetColorType) {
- WidgetColorType.Background -> data.copy(background = color.toArgb())
- WidgetColorType.Primary -> data.copy(primary = color.toArgb())
- WidgetColorType.Secondary -> data.copy(secondary = color.toArgb())
+ fun createCustomColoringData(data: WidgetColoring.Style.Custom): WidgetColoring.Style.Custom =
+ when (customWidgetColor) {
+ CustomWidgetColor.Background -> data.copy(background = color.toArgb())
+ CustomWidgetColor.Primary -> data.copy(primary = color.toArgb())
+ CustomWidgetColor.Secondary -> data.copy(secondary = color.toArgb())
}
companion object {
val nullableStateSaver = nullableListSaver(
saveNonNull = {
- listOf(it.widgetColorType, it.appliedColor.toArgb(), it.color.toArgb())
+ listOf(it.customWidgetColor, it.appliedColor.toArgb(), it.color.toArgb())
},
restoreNonNull = {
ColorPickerProperties(
- widgetColorType = it[0] as WidgetColorType,
+ customWidgetColor = it[0] as CustomWidgetColor,
appliedColor = Color(it[1] as Int),
initialColor = Color(it[2] as Int)
)
@@ -82,7 +82,7 @@ fun ColorPickerDialog(
modifier = modifier,
columnModifier = Modifier
.verticalScroll(rememberScrollState()),
- title = stringResource(id = properties.widgetColorType.labelRes),
+ title = stringResource(id = properties.customWidgetColor.labelRes),
applyButtonEnabled = properties.colorsDissimilar
) {
HSVColorPickerCircularWithSliders(
diff --git a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/model/UnconfirmedWidgetConfiguration.kt b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/model/ReversibleWidgetConfiguration.kt
similarity index 93%
rename from app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/model/UnconfirmedWidgetConfiguration.kt
rename to app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/model/ReversibleWidgetConfiguration.kt
index caf4ca04..f94bc500 100644
--- a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/model/UnconfirmedWidgetConfiguration.kt
+++ b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/screens/home/components/widget/configurationdialog/model/ReversibleWidgetConfiguration.kt
@@ -21,10 +21,8 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch
@Stable
-class UnconfirmedWidgetConfiguration(
- val coloring: UnconfirmedStateFlow,
- val presetColoringData: UnconfirmedStateFlow,
- val customColoringData: UnconfirmedStateFlow,
+class ReversibleWidgetConfiguration(
+ val coloringConfig: UnconfirmedStateFlow,
val opacity: UnconfirmedStateFlow,
val fontSize: UnconfirmedStateFlow,
val wifiProperties: UnconfirmedStateMap,
@@ -36,9 +34,7 @@ class UnconfirmedWidgetConfiguration(
onStateSynced: suspend () -> Unit
) : UnconfirmedStatesComposition(
unconfirmedStates = listOf(
- coloring,
- presetColoringData,
- customColoringData,
+ coloringConfig,
opacity,
fontSize,
wifiProperties,
diff --git a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/viewmodels/WidgetViewModel.kt b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/viewmodels/WidgetViewModel.kt
index 3c40fdc9..d96c7ef2 100644
--- a/app/src/main/kotlin/com/w2sv/wifiwidget/ui/viewmodels/WidgetViewModel.kt
+++ b/app/src/main/kotlin/com/w2sv/wifiwidget/ui/viewmodels/WidgetViewModel.kt
@@ -22,7 +22,7 @@ import com.w2sv.wifiwidget.di.SnackbarVisualsFlow
import com.w2sv.wifiwidget.di.WidgetPinSuccessFlow
import com.w2sv.wifiwidget.ui.designsystem.AppSnackbarVisuals
import com.w2sv.wifiwidget.ui.designsystem.SnackbarKind
-import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.model.UnconfirmedWidgetConfiguration
+import com.w2sv.wifiwidget.ui.screens.home.components.widget.configurationdialog.model.ReversibleWidgetConfiguration
import com.w2sv.wifiwidget.ui.utils.fromStateFlowMap
import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -83,20 +83,11 @@ class WidgetViewModel @Inject constructor(
val showConfigurationDialogInitially =
savedStateHandle.get(Extra.SHOW_WIDGET_CONFIGURATION_DIALOG) == true
- val configuration = UnconfirmedWidgetConfiguration(
- coloring = UnconfirmedStateFlow(
- coroutineScope = viewModelScope,
- dataStoreStateFlow = repository.coloring
- ),
- presetColoringData = UnconfirmedStateFlow(
- scope = viewModelScope,
- appliedStateFlow = repository.presetColoringData,
- syncState = { repository.savePresetColoringData(it) }
- ),
- customColoringData = UnconfirmedStateFlow(
+ val configuration = ReversibleWidgetConfiguration(
+ coloringConfig = UnconfirmedStateFlow(
scope = viewModelScope,
- appliedStateFlow = repository.customColoringData,
- syncState = { repository.saveCustomColoringData(it) }
+ appliedStateFlow = repository.coloringConfig,
+ syncState = { repository.saveColoringConfig(it) }
),
opacity = UnconfirmedStateFlow(
coroutineScope = viewModelScope,
diff --git a/build.gradle.kts b/build.gradle.kts
index 0692fbd2..bd04a08b 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -7,4 +7,27 @@ plugins {
alias(libs.plugins.play) apply false
alias(libs.plugins.androidTest) apply false
alias(libs.plugins.baselineprofile) apply false
+}
+
+val Task.absoluteBuildDirectoryPath: String
+ get() = project.layout.buildDirectory.get().asFile.absolutePath
+
+subprojects {
+ // Enable compose compiler reports as per https://developer.android.com/develop/ui/compose/performance/stability/diagnose#setup
+ tasks.withType().configureEach {
+ kotlinOptions {
+ if (project.findProperty("composeCompilerReports") == "true") {
+ freeCompilerArgs += listOf(
+ "-P",
+ "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$absoluteBuildDirectoryPath/compose_compiler"
+ )
+ }
+ if (project.findProperty("composeCompilerMetrics") == "true") {
+ freeCompilerArgs += listOf(
+ "-P",
+ "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=$absoluteBuildDirectoryPath/compose_compiler"
+ )
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/compose_compiler_config.conf b/compose_compiler_config.conf
new file mode 100644
index 00000000..2989978c
--- /dev/null
+++ b/compose_compiler_config.conf
@@ -0,0 +1 @@
+com.w2sv.domain.model.**
\ No newline at end of file
diff --git a/core/datastore/src/main/kotlin/com/w2sv/datastore/Mapping.kt b/core/datastore/src/main/kotlin/com/w2sv/datastore/Mapping.kt
deleted file mode 100644
index 319cb5d7..00000000
--- a/core/datastore/src/main/kotlin/com/w2sv/datastore/Mapping.kt
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.w2sv.datastore
-
-import com.w2sv.domain.model.Theme
-import com.w2sv.domain.model.WidgetColoring
-
-internal interface Mapper {
- fun toExternal(proto: Proto): External
- fun toProto(external: External): Proto
-}
-
-internal object WidgetColoringMapper : Mapper {
- override fun toExternal(proto: WidgetColoringProto): WidgetColoring.Config =
- WidgetColoring.Config(
- preset = proto.preset.toExternal(),
- custom = proto.custom.toExternal(),
- isCustomSelected = proto.isCustomSelected
- )
-
- override fun toProto(external: WidgetColoring.Config): WidgetColoringProto =
- widgetColoringProto {
- preset = external.preset.toProto()
- custom = external.custom.toProto()
- isCustomSelected = external.isCustomSelected
- }
-}
-
-internal fun WidgetColoringProto.Preset.toExternal(): WidgetColoring.Preset =
- WidgetColoring.Preset(
- theme = when (theme) {
- WidgetColoringProto.Preset.Theme.Dark -> Theme.Dark
- WidgetColoringProto.Preset.Theme.Light -> Theme.Light
- else -> Theme.SystemDefault
- },
- useDynamicColors = useDynamicColors
- )
-
-internal fun WidgetColoring.Preset.toProto(): WidgetColoringProto.Preset =
- WidgetColoringProto.Preset.newBuilder()
- .apply {
- theme = when (this@toProto.theme) {
- Theme.Dark -> WidgetColoringProto.Preset.Theme.Dark
- Theme.Light -> WidgetColoringProto.Preset.Theme.Light
- Theme.SystemDefault -> WidgetColoringProto.Preset.Theme.SystemDefault
- }
- useDynamicColors = this@toProto.useDynamicColors
- }
- .build()
-
-internal fun WidgetColoringProto.Custom.toExternal(): WidgetColoring.Custom =
- WidgetColoring.Custom(
- background = background,
- primary = primary,
- secondary = secondary
- )
-
-internal fun WidgetColoring.Custom.toProto(): WidgetColoringProto.Custom =
- WidgetColoringProto.Custom.newBuilder()
- .apply {
- background = this@toProto.background
- primary = this@toProto.primary
- secondary = this@toProto.secondary
- }
- .build()
\ No newline at end of file
diff --git a/core/datastore/src/main/kotlin/com/w2sv/datastore/di/PreferencesModule.kt b/core/datastore/src/main/kotlin/com/w2sv/datastore/di/PreferencesModule.kt
index af60583d..6f0abc66 100644
--- a/core/datastore/src/main/kotlin/com/w2sv/datastore/di/PreferencesModule.kt
+++ b/core/datastore/src/main/kotlin/com/w2sv/datastore/di/PreferencesModule.kt
@@ -10,7 +10,8 @@ import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStoreFile
import com.w2sv.datastore.WidgetColoringProto
-import com.w2sv.datastore.WidgetColoringProtoSerializer
+import com.w2sv.datastore.proto.widget_coloring.WidgetColoringProtoSerializer
+import com.w2sv.datastore.proto.widget_coloring.defaultWidgetColoringProto
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -32,12 +33,12 @@ object PreferencesModule {
@Provides
@Singleton
- internal fun providesUserProtoDataStore(
+ internal fun providesWidgetColoringProtoDataStore(
@ApplicationContext context: Context,
): DataStore =
DataStoreFactory.create(
serializer = WidgetColoringProtoSerializer,
- corruptionHandler = ReplaceFileCorruptionHandler { WidgetColoringProto.getDefaultInstance() },
+ corruptionHandler = ReplaceFileCorruptionHandler { defaultWidgetColoringProto },
produceFile = {
context.dataStoreFile("widget_coloring.pb")
}
diff --git a/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/Mapper.kt b/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/Mapper.kt
new file mode 100644
index 00000000..f0ec359c
--- /dev/null
+++ b/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/Mapper.kt
@@ -0,0 +1,6 @@
+package com.w2sv.datastore.proto
+
+internal interface Mapper {
+ fun toExternal(proto: Proto): External
+ fun toProto(external: External): Proto
+}
\ No newline at end of file
diff --git a/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/Default.kt b/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/Default.kt
new file mode 100644
index 00000000..f4eebe90
--- /dev/null
+++ b/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/Default.kt
@@ -0,0 +1,6 @@
+package com.w2sv.datastore.proto.widget_coloring
+
+import com.w2sv.domain.model.WidgetColoring
+
+internal val defaultWidgetColoringProto =
+ WidgetColoringConfigMapper.toProto(WidgetColoring.Config())
\ No newline at end of file
diff --git a/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/WidgetColoringConfigMapper.kt b/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/WidgetColoringConfigMapper.kt
new file mode 100644
index 00000000..99f1084e
--- /dev/null
+++ b/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/WidgetColoringConfigMapper.kt
@@ -0,0 +1,70 @@
+package com.w2sv.datastore.proto.widget_coloring
+
+import com.w2sv.datastore.WidgetColoringProto
+import com.w2sv.datastore.proto.Mapper
+import com.w2sv.datastore.widgetColoringProto
+import com.w2sv.domain.model.Theme
+import com.w2sv.domain.model.WidgetColoring
+
+internal object WidgetColoringConfigMapper : Mapper {
+
+ override fun toExternal(proto: WidgetColoringProto): WidgetColoring.Config =
+ WidgetColoring.Config(
+ preset = PresetColoringMapper.toExternal(proto.preset),
+ custom = CustomColoringMapper.toExternal(proto.custom),
+ isCustomSelected = proto.isCustomSelected
+ )
+
+ override fun toProto(external: WidgetColoring.Config): WidgetColoringProto =
+ widgetColoringProto {
+ preset = PresetColoringMapper.toProto(external.preset)
+ custom = CustomColoringMapper.toProto(external.custom)
+ isCustomSelected = external.isCustomSelected
+ }
+}
+
+private object PresetColoringMapper :
+ Mapper {
+
+ override fun toProto(external: WidgetColoring.Style.Preset): WidgetColoringProto.Preset =
+ WidgetColoringProto.Preset.newBuilder()
+ .apply {
+ theme = when (external.theme) {
+ Theme.Dark -> WidgetColoringProto.Preset.Theme.Dark
+ Theme.Light -> WidgetColoringProto.Preset.Theme.Light
+ Theme.SystemDefault -> WidgetColoringProto.Preset.Theme.SystemDefault
+ }
+ useDynamicColors = external.useDynamicColors
+ }
+ .build()
+
+ override fun toExternal(proto: WidgetColoringProto.Preset): WidgetColoring.Style.Preset =
+ WidgetColoring.Style.Preset(
+ theme = when (proto.theme) {
+ WidgetColoringProto.Preset.Theme.Dark -> Theme.Dark
+ WidgetColoringProto.Preset.Theme.Light -> Theme.Light
+ else -> Theme.SystemDefault
+ },
+ useDynamicColors = proto.useDynamicColors
+ )
+}
+
+private object CustomColoringMapper :
+ Mapper {
+
+ override fun toProto(external: WidgetColoring.Style.Custom): WidgetColoringProto.Custom =
+ WidgetColoringProto.Custom.newBuilder()
+ .apply {
+ background = external.background
+ primary = external.primary
+ secondary = external.secondary
+ }
+ .build()
+
+ override fun toExternal(proto: WidgetColoringProto.Custom): WidgetColoring.Style.Custom =
+ WidgetColoring.Style.Custom(
+ background = proto.background,
+ primary = proto.primary,
+ secondary = proto.secondary
+ )
+}
\ No newline at end of file
diff --git a/core/datastore/src/main/kotlin/com/w2sv/datastore/WidgetColoringDataSource.kt b/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/WidgetColoringDataSource.kt
similarity index 75%
rename from core/datastore/src/main/kotlin/com/w2sv/datastore/WidgetColoringDataSource.kt
rename to core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/WidgetColoringDataSource.kt
index ad440984..3dc57184 100644
--- a/core/datastore/src/main/kotlin/com/w2sv/datastore/WidgetColoringDataSource.kt
+++ b/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/WidgetColoringDataSource.kt
@@ -1,6 +1,7 @@
-package com.w2sv.datastore
+package com.w2sv.datastore.proto.widget_coloring
import androidx.datastore.core.DataStore
+import com.w2sv.datastore.WidgetColoringProto
import com.w2sv.domain.model.WidgetColoring
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flowOn
@@ -13,13 +14,13 @@ class WidgetColoringDataSource @Inject constructor(private val widgetColoringPro
val config = widgetColoringProtoDataStore.data
.map {
- it.toExternal()
+ WidgetColoringConfigMapper.toExternal(it)
}
.flowOn(Dispatchers.IO)
suspend fun saveConfig(config: WidgetColoring.Config) {
widgetColoringProtoDataStore.updateData {
- config.toProto()
+ WidgetColoringConfigMapper.toProto(config)
}
}
}
\ No newline at end of file
diff --git a/core/datastore/src/main/kotlin/com/w2sv/datastore/WidgetColoringProtoSerializer.kt b/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/WidgetColoringProtoSerializer.kt
similarity index 83%
rename from core/datastore/src/main/kotlin/com/w2sv/datastore/WidgetColoringProtoSerializer.kt
rename to core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/WidgetColoringProtoSerializer.kt
index 16ccbd6a..7e780560 100644
--- a/core/datastore/src/main/kotlin/com/w2sv/datastore/WidgetColoringProtoSerializer.kt
+++ b/core/datastore/src/main/kotlin/com/w2sv/datastore/proto/widget_coloring/WidgetColoringProtoSerializer.kt
@@ -1,15 +1,16 @@
-package com.w2sv.datastore
+package com.w2sv.datastore.proto.widget_coloring
import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
import com.google.protobuf.InvalidProtocolBufferException
+import com.w2sv.datastore.WidgetColoringProto
import com.w2sv.domain.model.WidgetColoring
import java.io.InputStream
import java.io.OutputStream
internal object WidgetColoringProtoSerializer : Serializer {
- override val defaultValue: WidgetColoringProto = WidgetColoring.Config().toProto()
+ override val defaultValue: WidgetColoringProto = defaultWidgetColoringProto
override suspend fun readFrom(input: InputStream): WidgetColoringProto =
try {
diff --git a/core/datastore/src/main/kotlin/com/w2sv/datastore/repository/WidgetRepositoryImpl.kt b/core/datastore/src/main/kotlin/com/w2sv/datastore/repository/WidgetRepositoryImpl.kt
index 89bb48b8..1578ec1c 100644
--- a/core/datastore/src/main/kotlin/com/w2sv/datastore/repository/WidgetRepositoryImpl.kt
+++ b/core/datastore/src/main/kotlin/com/w2sv/datastore/repository/WidgetRepositoryImpl.kt
@@ -7,7 +7,7 @@ import androidx.datastore.preferences.core.floatPreferencesKey
import androidx.datastore.preferences.core.intPreferencesKey
import com.w2sv.androidutils.datastorage.datastore.DataStoreEntry
import com.w2sv.androidutils.datastorage.datastore.DataStoreRepository
-import com.w2sv.datastore.WidgetColoringDataSource
+import com.w2sv.datastore.proto.widget_coloring.WidgetColoringDataSource
import com.w2sv.domain.model.FontSize
import com.w2sv.domain.model.WidgetBottomRowElement
import com.w2sv.domain.model.WidgetColoring
@@ -32,14 +32,14 @@ class WidgetRepositoryImpl @Inject constructor(
private val scope = CoroutineScope(Dispatchers.Default + SupervisorJob())
- override val coloring: StateFlow =
+ override val coloringConfig: StateFlow =
widgetColoringDataSource.config.stateIn(
scope = scope,
started = SharingStarted.Eagerly,
initialValue = WidgetColoring.Config()
)
- override suspend fun saveColoring(config: WidgetColoring.Config) {
+ override suspend fun saveColoringConfig(config: WidgetColoring.Config) {
widgetColoringDataSource.saveConfig(config)
}
diff --git a/core/datastore/src/main/proto/widget_coloring.proto b/core/datastore/src/main/proto/widget_coloring.proto
index cf5b1cb0..92d5410a 100644
--- a/core/datastore/src/main/proto/widget_coloring.proto
+++ b/core/datastore/src/main/proto/widget_coloring.proto
@@ -4,6 +4,7 @@ option java_package = "com.w2sv.datastore";
option java_multiple_files = true;
message WidgetColoringProto {
+
message Preset {
enum Theme {
Light = 0;
@@ -19,11 +20,6 @@ message WidgetColoringProto {
sint32 secondary = 3;
}
- enum Kind {
- PresetKind = 0;
- CustomKind = 1;
- }
-
Preset preset = 1;
Custom custom = 2;
bool is_custom_selected = 3;
diff --git a/core/domain/src/main/kotlin/com/w2sv/domain/model/WidgetColoring.kt b/core/domain/src/main/kotlin/com/w2sv/domain/model/WidgetColoring.kt
index cc1a317b..aec00e1a 100644
--- a/core/domain/src/main/kotlin/com/w2sv/domain/model/WidgetColoring.kt
+++ b/core/domain/src/main/kotlin/com/w2sv/domain/model/WidgetColoring.kt
@@ -5,32 +5,38 @@ import androidx.annotation.StringRes
import com.w2sv.common.utils.dynamicColorsSupported
import com.w2sv.core.domain.R
-sealed interface WidgetColoring {
-
- data class Preset(
- val theme: Theme = Theme.SystemDefault,
- val useDynamicColors: Boolean = dynamicColorsSupported
- ) : WidgetColoring
-
- data class Custom(
- @ColorInt val background: Int = -7859146,
- @ColorInt val primary: Int = -5898336,
- @ColorInt val secondary: Int = -1
- ) : WidgetColoring
-
- @get:StringRes
- val label: Int
- get() = when (this) {
- is Preset -> R.string.preset
- is Custom -> R.string.custom
- }
+interface WidgetColoring {
data class Config(
- val preset: Preset = Preset(),
- val custom: Custom = Custom(),
+ val preset: Style.Preset = Style.Preset(),
+ val custom: Style.Custom = Style.Custom(),
val isCustomSelected: Boolean = false
) {
- val selected: WidgetColoring
+ val styles: List