Skip to content

Commit

Permalink
remove workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
babichev.a committed Jul 26, 2024
1 parent 3c0ea07 commit 44f3132
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 90 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalResourceApi::class)

package com.softartdev.shared

import androidx.compose.foundation.ScrollState
Expand All @@ -12,11 +10,10 @@ import com.softartdev.theme.pref.LocalThemePrefs
import com.softartdev.theme.pref.PreferableMaterialTheme.themePrefs
import com.softartdev.theme.pref.ThemeEnum
import com.softartdev.theme.pref.ThemePrefs
import com.softartdev.theme.pref.stringResource
import io.github.softartdev.theme_prefs.generated.resources.Res
import io.github.softartdev.theme_prefs.generated.resources.switch_to_material_design_2
import io.github.softartdev.theme_prefs.generated.resources.switch_to_material_design_3
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource

object AppState {
val showMaterial3: MutableState<Boolean> = mutableStateOf(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalResourceApi::class)

package com.softartdev.shared.material

import androidx.compose.foundation.layout.Box
Expand All @@ -18,9 +16,8 @@ import com.softartdev.theme.material.ThemePreferenceItem
import com.softartdev.theme.material.ThemePreferencesCategory
import com.softartdev.theme.pref.PreferableMaterialTheme.themePrefs
import io.github.softartdev.theme_prefs.generated.resources.Res
import org.jetbrains.compose.resources.ExperimentalResourceApi
import com.softartdev.theme.pref.stringResource
import io.github.softartdev.theme_prefs.generated.resources.material_version
import org.jetbrains.compose.resources.stringResource
import kotlin.experimental.ExperimentalObjCRefinement
import kotlin.native.HiddenFromObjC

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalResourceApi::class)

package com.softartdev.shared.material3

import androidx.compose.foundation.layout.Box
Expand All @@ -18,9 +16,8 @@ import com.softartdev.theme.material3.ThemePreferenceItem
import com.softartdev.theme.material3.ThemePreferencesCategory
import com.softartdev.theme.pref.PreferableMaterialTheme.themePrefs
import io.github.softartdev.theme_prefs.generated.resources.Res
import com.softartdev.theme.pref.stringResource
import io.github.softartdev.theme_prefs.generated.resources.material_version
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource
import kotlin.experimental.ExperimentalObjCRefinement
import kotlin.native.HiddenFromObjC

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@file:OptIn(ExperimentalMaterialApi::class, ExperimentalResourceApi::class)
@file:Suppress("EXPERIMENTAL_IS_NOT_ENABLED")
@file:OptIn(ExperimentalMaterialApi::class)

package com.softartdev.theme.material

Expand All @@ -17,11 +16,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import com.softartdev.theme.pref.LocalThemePrefs
import com.softartdev.theme.pref.ThemePrefs
import com.softartdev.theme.pref.stringResource
import io.github.softartdev.theme_prefs.generated.resources.Res
import io.github.softartdev.theme_prefs.generated.resources.choose_theme
import io.github.softartdev.theme_prefs.generated.resources.theme
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource

@Composable
fun ThemePreferencesCategory() = PreferenceCategory(
Expand All @@ -33,7 +31,7 @@ fun ThemePreferencesCategory() = PreferenceCategory(
fun ThemePreferenceItem(themePrefs: ThemePrefs = LocalThemePrefs.current) = PreferenceItem(
title = stringResource(Res.string.choose_theme),
vector = Icons.Filled.SettingsBrightness,
secondaryText = { Text(text = themePrefs.darkThemeState.value.toLocalizedString()) },
secondaryText = { Text(text = stringResource(themePrefs.darkThemeState.value.stringRes)) },
onClick = themePrefs::showDialog
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.softartdev.theme.material

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material.MaterialTheme
Expand All @@ -13,10 +17,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import com.softartdev.theme.pref.ThemeEnum
import org.jetbrains.compose.resources.stringResource

@Composable
fun RadioDialogContent(darkThemeState: MutableState<ThemeEnum>) = Column(Modifier.selectableGroup()) {
ThemeEnum.values().forEach { themeEnum: ThemeEnum ->
ThemeEnum.entries.forEach { themeEnum: ThemeEnum ->
Row(
Modifier
.fillMaxWidth()
Expand All @@ -34,7 +39,7 @@ fun RadioDialogContent(darkThemeState: MutableState<ThemeEnum>) = Column(Modifie
onClick = null // null recommended for accessibility with screenreaders
)
Text(
text = themeEnum.toLocalizedString(),
text = stringResource(themeEnum.stringRes),
style = MaterialTheme.typography.body1.merge(),
modifier = Modifier.padding(start = 16.dp)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
@file:Suppress("EXPERIMENTAL_IS_NOT_ENABLED")
@file:OptIn(ExperimentalResourceApi::class)

package com.softartdev.theme.material

import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -14,10 +11,9 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.ImageVector
import com.softartdev.theme.pref.stringResource
import io.github.softartdev.theme_prefs.generated.resources.Res
import io.github.softartdev.theme_prefs.generated.resources.settings
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource

@Composable
fun SettingsScaffold(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalResourceApi::class)

package com.softartdev.theme.material

import androidx.compose.material.AlertDialog
Expand All @@ -10,13 +8,12 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import com.softartdev.theme.pref.DialogHolder
import io.github.softartdev.theme_prefs.generated.resources.Res
import com.softartdev.theme.pref.ThemeEnum
import org.jetbrains.compose.resources.ExperimentalResourceApi
import com.softartdev.theme.pref.stringResource
import io.github.softartdev.theme_prefs.generated.resources.Res
import io.github.softartdev.theme_prefs.generated.resources.cancel
import io.github.softartdev.theme_prefs.generated.resources.choose_theme
import io.github.softartdev.theme_prefs.generated.resources.ok
import org.jetbrains.compose.resources.stringResource

@Composable
fun ThemeDialog(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("EXPERIMENTAL_IS_NOT_ENABLED")

package com.softartdev.theme.material3

import androidx.compose.foundation.clickable
Expand All @@ -16,24 +14,21 @@ import androidx.compose.ui.graphics.vector.ImageVector
import com.softartdev.theme.pref.LocalThemePrefs
import io.github.softartdev.theme_prefs.generated.resources.Res
import com.softartdev.theme.pref.ThemePrefs
import org.jetbrains.compose.resources.ExperimentalResourceApi
import com.softartdev.theme.pref.stringResource
import io.github.softartdev.theme_prefs.generated.resources.choose_theme
import io.github.softartdev.theme_prefs.generated.resources.theme
import org.jetbrains.compose.resources.stringResource

@OptIn(ExperimentalResourceApi::class)
@Composable
fun ThemePreferencesCategory() = PreferenceCategory(
title = stringResource(Res.string.theme),
vector = Icons.Filled.Brightness4
)

@OptIn(ExperimentalResourceApi::class)
@Composable
fun ThemePreferenceItem(themePrefs: ThemePrefs = LocalThemePrefs.current) = PreferenceItem(
title = stringResource(Res.string.choose_theme),
vector = Icons.Filled.SettingsBrightness,
secondaryText = { Text(text = themePrefs.darkThemeState.value.toLocalizedString()) },
secondaryText = { Text(text = stringResource(themePrefs.darkThemeState.value.stringRes)) },
onClick = themePrefs::showDialog
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.softartdev.theme.material3

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material3.MaterialTheme
Expand All @@ -13,10 +17,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import com.softartdev.theme.pref.ThemeEnum
import org.jetbrains.compose.resources.stringResource

@Composable
fun RadioDialogContent(darkThemeState: MutableState<ThemeEnum>) = Column(Modifier.selectableGroup()) {
ThemeEnum.values().forEach { themeEnum: ThemeEnum ->
ThemeEnum.entries.forEach { themeEnum: ThemeEnum ->
Row(
Modifier
.fillMaxWidth()
Expand All @@ -34,7 +39,7 @@ fun RadioDialogContent(darkThemeState: MutableState<ThemeEnum>) = Column(Modifie
onClick = null // null recommended for accessibility with screenreaders
)
Text(
text = themeEnum.toLocalizedString(),
text = stringResource(themeEnum.stringRes),
style = MaterialTheme.typography.bodyLarge.merge(),
modifier = Modifier.padding(start = 16.dp)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@file:Suppress("EXPERIMENTAL_IS_NOT_ENABLED")
@file:OptIn(ExperimentalMaterial3Api::class, ExperimentalResourceApi::class)
@file:OptIn(ExperimentalMaterial3Api::class)

package com.softartdev.theme.material3

Expand All @@ -15,10 +14,9 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.ImageVector
import com.softartdev.theme.pref.stringResource
import io.github.softartdev.theme_prefs.generated.resources.Res
import io.github.softartdev.theme_prefs.generated.resources.settings
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource

@Composable
fun SettingsScaffold(
Expand All @@ -44,4 +42,4 @@ fun SettingsTopAppBar(
}
},
actions = actions
)
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalResourceApi::class)

package com.softartdev.theme.material3

import androidx.compose.material3.AlertDialog
Expand All @@ -10,15 +8,13 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import com.softartdev.theme.pref.DialogHolder
import io.github.softartdev.theme_prefs.generated.resources.Res
import com.softartdev.theme.pref.ThemeEnum
import org.jetbrains.compose.resources.ExperimentalResourceApi
import com.softartdev.theme.pref.stringResource
import io.github.softartdev.theme_prefs.generated.resources.Res
import io.github.softartdev.theme_prefs.generated.resources.cancel
import io.github.softartdev.theme_prefs.generated.resources.choose_theme
import io.github.softartdev.theme_prefs.generated.resources.ok
import org.jetbrains.compose.resources.stringResource

@OptIn(ExperimentalResourceApi::class)
@Composable
fun ThemeDialog(
darkThemeState: MutableState<ThemeEnum> = mutableStateOf(ThemeEnum.SystemDefault),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
package com.softartdev.theme.pref

import androidx.compose.runtime.Composable
import io.github.softartdev.theme_prefs.generated.resources.Res
import io.github.softartdev.theme_prefs.generated.resources.dark
import io.github.softartdev.theme_prefs.generated.resources.light
import io.github.softartdev.theme_prefs.generated.resources.system_default
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.StringResource

enum class ThemeEnum {
Light,
Dark,
SystemDefault;

@OptIn(ExperimentalResourceApi::class)
@Composable
fun toLocalizedString(): String = stringResource(
resource = when (this) {
Light -> Res.string.light
Dark -> Res.string.dark
SystemDefault -> Res.string.system_default
}
)
}
enum class ThemeEnum(val stringRes: StringResource) {
Light(Res.string.light),
Dark(Res.string.dark),
SystemDefault(Res.string.system_default)
}

0 comments on commit 44f3132

Please sign in to comment.