forked from feelfreelinux/WykopMobilny
-
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.
Merge pull request feelfreelinux#163 from otwarty-wykop-mobilny/theme…
…_updates
- Loading branch information
Showing
19 changed files
with
165 additions
and
132 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
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
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
data/storage/api/src/main/sqldelight/io/github/wykopmobilny/data/storage/api/3.sqm
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,21 @@ | ||
INSERT OR IGNORE INTO preferenceEntity (key, value) | ||
VALUES ( | ||
"settings.appearance.app_theme", | ||
( | ||
SELECT "dark" | ||
FROM preferenceEntity | ||
WHERE key = "settings.appearance.dark_theme" AND value = "true" | ||
) | ||
); | ||
|
||
INSERT OR IGNORE INTO preferenceEntity (key, value) | ||
VALUES ( | ||
"settings.appearance.app_theme", | ||
( | ||
SELECT "light" | ||
FROM preferenceEntity | ||
WHERE key = "settings.appearance.dark_theme" AND value = "false" | ||
) | ||
); | ||
|
||
DELETE FROM preferenceEntity WHERE key = "settings.appearance.dark_theme"; |
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
4 changes: 2 additions & 2 deletions
4
...ub/wykopmobilny/domain/styles/AppTheme.kt → ...bilny/domain/styles/AppThemePreference.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,7 +1,7 @@ | ||
package io.github.wykopmobilny.domain.styles | ||
|
||
enum class AppTheme { | ||
internal enum class AppThemePreference { | ||
Auto, | ||
Light, | ||
Dark, | ||
DarkAmoled, | ||
} |
55 changes: 38 additions & 17 deletions
55
domain/src/main/kotlin/io/github/wykopmobilny/domain/styles/GetAppStyleQuery.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,33 +1,54 @@ | ||
package io.github.wykopmobilny.domain.styles | ||
|
||
import io.github.wykopmobilny.domain.navigation.NightModeState | ||
import io.github.wykopmobilny.domain.navigation.SystemSettingsDetector | ||
import io.github.wykopmobilny.domain.settings.prefs.GetAppearanceSectionPreferences | ||
import io.github.wykopmobilny.styles.AppThemeUi | ||
import io.github.wykopmobilny.styles.ApplicableStyleUi | ||
import io.github.wykopmobilny.styles.GetAppStyle | ||
import io.github.wykopmobilny.styles.StyleUi | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
internal class GetAppStyleQuery @Inject constructor( | ||
private val getAppTheme: GetAppTheme, | ||
private val getAppearanceSectionPreferences: GetAppearanceSectionPreferences, | ||
private val systemSettingsDetector: SystemSettingsDetector, | ||
) : GetAppStyle { | ||
|
||
override fun invoke() = | ||
combine( | ||
getAppTheme(), | ||
getAppearanceSectionPreferences(), | ||
) { theme, appearance -> | ||
StyleUi( | ||
theme = theme.toUi(), | ||
edgeSlidingBehaviorEnabled = !appearance.disableEdgeSlide, | ||
) | ||
} | ||
getAppearanceSectionPreferences() | ||
.map { appearance -> | ||
StyleUi( | ||
style = findAppStyle(appearance.appThemePreference, appearance.isAmoledTheme), | ||
edgeSlidingBehaviorEnabled = !appearance.disableEdgeSlide, | ||
) | ||
} | ||
.distinctUntilChanged() | ||
} | ||
|
||
private fun AppTheme.toUi() = when (this) { | ||
AppTheme.Light -> AppThemeUi.Light | ||
AppTheme.Dark -> AppThemeUi.Dark | ||
AppTheme.DarkAmoled -> AppThemeUi.DarkAmoled | ||
private suspend fun findAppStyle(appThemePreference: AppThemePreference, isAmoledTheme: Boolean) = | ||
when (appThemePreference) { | ||
AppThemePreference.Auto -> | ||
if (isSystemDark()) { | ||
findDarkMode(isAmoledTheme) | ||
} else { | ||
ApplicableStyleUi.Light | ||
} | ||
AppThemePreference.Light -> ApplicableStyleUi.Light | ||
AppThemePreference.Dark -> findDarkMode(isAmoledTheme) | ||
} | ||
|
||
private fun findDarkMode(isAmoledTheme: Boolean) = | ||
if (isAmoledTheme) { | ||
ApplicableStyleUi.DarkAmoled | ||
} else { | ||
ApplicableStyleUi.Dark | ||
} | ||
|
||
private suspend fun isSystemDark() = | ||
when (systemSettingsDetector.getNightModeState()) { | ||
NightModeState.Enabled -> true | ||
NightModeState.Disabled, | ||
NightModeState.Unknown, | ||
-> false | ||
} | ||
} |
Oops, something went wrong.