-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update theme switcher module
- Loading branch information
1 parent
1367a8e
commit 3f6e5ca
Showing
11 changed files
with
93 additions
and
43 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
38 changes: 14 additions & 24 deletions
38
...makeevrserg/empireprojekt/mobile/features/theme/DefaultThemeSwitcherComponentComponent.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
13 changes: 7 additions & 6 deletions
13
...tlin/com/makeevrserg/empireprojekt/mobile/features/theme/PreviewThemeSwitcherComponent.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,25 +1,26 @@ | ||
package com.makeevrserg.empireprojekt.mobile.features.theme | ||
|
||
import com.makeevrserg.empireprojekt.mobile.features.theme.data.model.Theme | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import ru.astrainteractive.klibs.mikro.core.util.next | ||
|
||
class PreviewThemeSwitcherComponent : ThemeSwitcherComponent { | ||
override val theme: MutableStateFlow<ThemeSwitcherComponent.Theme> = | ||
MutableStateFlow(ThemeSwitcherComponent.Theme.LIGHT) | ||
override val theme: MutableStateFlow<Theme> = | ||
MutableStateFlow(Theme.LIGHT) | ||
|
||
override fun selectDarkTheme() { | ||
selectTheme(ThemeSwitcherComponent.Theme.DARK) | ||
selectTheme(Theme.DARK) | ||
} | ||
|
||
override fun selectLightTheme() { | ||
selectTheme(ThemeSwitcherComponent.Theme.LIGHT) | ||
selectTheme(Theme.LIGHT) | ||
} | ||
|
||
override fun selectTheme(theme: ThemeSwitcherComponent.Theme) { | ||
override fun selectTheme(theme: Theme) { | ||
this.theme.value = theme | ||
} | ||
|
||
override fun next() { | ||
theme.value.next(ThemeSwitcherComponent.Theme.values()).run(::selectTheme) | ||
theme.value.next(Theme.values()).run(::selectTheme) | ||
} | ||
} |
5 changes: 1 addition & 4 deletions
5
...Main/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/ThemeSwitcherComponent.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
9 changes: 9 additions & 0 deletions
9
...otlin/com/makeevrserg/empireprojekt/mobile/features/theme/data/ThemeSwitcherRepository.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,9 @@ | ||
package com.makeevrserg.empireprojekt.mobile.features.theme.data | ||
|
||
import com.makeevrserg.empireprojekt.mobile.features.theme.data.model.Theme | ||
import ru.astrainteractive.klibs.kstorage.api.StateFlowMutableStorageValue | ||
|
||
interface ThemeSwitcherRepository { | ||
|
||
val themeFlowStorageValue: StateFlowMutableStorageValue<Theme> | ||
} |
25 changes: 25 additions & 0 deletions
25
...n/com/makeevrserg/empireprojekt/mobile/features/theme/data/ThemeSwitcherRepositoryImpl.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,25 @@ | ||
package com.makeevrserg.empireprojekt.mobile.features.theme.data | ||
|
||
import com.makeevrserg.empireprojekt.mobile.features.theme.data.model.Theme | ||
import com.russhwolf.settings.Settings | ||
import ru.astrainteractive.klibs.kstorage.StateFlowMutableStorageValue | ||
|
||
class ThemeSwitcherRepositoryImpl( | ||
private val settings: Settings | ||
) : ThemeSwitcherRepository { | ||
|
||
private val key = "THEME" | ||
|
||
private val default = Theme.DARK | ||
|
||
override val themeFlowStorageValue = StateFlowMutableStorageValue( | ||
default = default, | ||
loadSettingsValue = { | ||
val ordinal = settings.getInt(key, Theme.LIGHT.ordinal) | ||
Theme.entries.getOrNull(ordinal) ?: default | ||
}, | ||
saveSettingsValue = { | ||
settings.putInt(key, it.ordinal) | ||
} | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
...commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/data/model/Theme.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,5 @@ | ||
package com.makeevrserg.empireprojekt.mobile.features.theme.data.model | ||
|
||
enum class Theme { | ||
DARK, LIGHT | ||
} |
18 changes: 18 additions & 0 deletions
18
...Main/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/di/ThemeSwitcherModule.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,18 @@ | ||
package com.makeevrserg.empireprojekt.mobile.features.theme.di | ||
|
||
import com.makeevrserg.empireprojekt.mobile.features.theme.data.ThemeSwitcherRepository | ||
import com.makeevrserg.empireprojekt.mobile.features.theme.data.ThemeSwitcherRepositoryImpl | ||
import com.russhwolf.settings.Settings | ||
import ru.astrainteractive.klibs.kdi.Single | ||
import ru.astrainteractive.klibs.kdi.getValue | ||
|
||
interface ThemeSwitcherModule { | ||
|
||
val themeSwitcherRepository: ThemeSwitcherRepository | ||
|
||
class Default(settings: Settings) : ThemeSwitcherModule { | ||
override val themeSwitcherRepository: ThemeSwitcherRepository by Single { | ||
ThemeSwitcherRepositoryImpl(settings) | ||
} | ||
} | ||
} |
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