Migrate system bar settings

This commit is contained in:
MM20 2022-01-29 17:47:45 +01:00
parent 97e714acf4
commit f5b21e4fe6
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
6 changed files with 81 additions and 1 deletions

View File

@ -114,5 +114,10 @@ fun createFactorySettings(context: Context): Settings {
.setIconPack("")
)
.setEasterEgg(false)
.setSystemBars(
Settings.SystemBarsSettings.newBuilder()
.setLightNavBar(false)
.setLightStatusBar(false)
)
.build()
}

View File

@ -159,4 +159,10 @@ message Settings {
bool easter_egg = 22;
message SystemBarsSettings {
bool lightStatusBar = 1;
bool lightNavBar = 2;
}
SystemBarsSettings system_bars = 23;
}

View File

@ -57,6 +57,14 @@ class LauncherActivity : BaseActivity() {
}
}
val windowController = WindowInsetsControllerCompat(window, binding.rootView)
viewModel.lightStatusBar.observe(this) {
windowController.isAppearanceLightStatusBars = it
}
viewModel.lightNavBar.observe(this) {
windowController.isAppearanceLightNavigationBars = it
}
var editFavoritesDialog: MaterialDialog? = null
viewModel.isEditFavoritesShown.observe(this) {
if (it) {

View File

@ -18,11 +18,26 @@ class LauncherActivityVM : ViewModel(), KoinComponent {
private var isDarkInMode = MutableStateFlow(false)
val dimBackground = combine(
private val dimBackgroundState = combine(
dataStore.data.map { it.appearance.dimWallpaper },
isDarkInMode
) { dim, darkMode ->
dim && darkMode
}
val dimBackground = dimBackgroundState.asLiveData()
val lightStatusBar = combine(
dimBackgroundState,
dataStore.data.map { it.systemBars.lightStatusBar }
) { dim, light ->
!dim && light
}.asLiveData()
val lightNavBar = combine(
dimBackgroundState,
dataStore.data.map { it.systemBars.lightNavBar }
) { dim, light ->
!dim && light
}.asLiveData()
fun setDarkMode(darkMode: Boolean) {

View File

@ -173,6 +173,24 @@ fun AppearanceSettingsScreen() {
}
)
}
PreferenceCategory(stringResource(R.string.preference_category_system_bars)) {
val lightStatusBar by viewModel.lightStatusBar.observeAsState()
SwitchPreference(
title = stringResource(R.string.preference_light_status_bar),
value = lightStatusBar == true,
onValueChanged = {
viewModel.setLightStatusBar(it)
}
)
val lightNavBar by viewModel.lightNavBar.observeAsState()
SwitchPreference(
title = stringResource(R.string.preference_light_nav_bar),
value = lightNavBar == true,
onValueChanged = {
viewModel.setLightNavBar(it)
}
)
}
}
}
}

View File

@ -148,4 +148,32 @@ class AppearanceSettingsScreenVM : ViewModel(), KoinComponent {
}
}
}
val lightStatusBar = dataStore.data.map { it.systemBars.lightStatusBar }.asLiveData()
fun setLightStatusBar(lightStatusBar: Boolean) {
viewModelScope.launch {
dataStore.updateData {
it.toBuilder()
.setSystemBars(
it.systemBars.toBuilder()
.setLightStatusBar(lightStatusBar)
)
.build()
}
}
}
val lightNavBar = dataStore.data.map { it.systemBars.lightNavBar }.asLiveData()
fun setLightNavBar(lightNavBar: Boolean) {
viewModelScope.launch {
dataStore.updateData {
it.toBuilder()
.setSystemBars(
it.systemBars.toBuilder()
.setLightNavBar(lightNavBar)
)
.build()
}
}
}
}