Add options to hide system bars
This commit is contained in:
parent
577ac7e28c
commit
902d77fff0
@ -116,6 +116,8 @@
|
||||
<string name="preference_category_system_bars">Systemleisten</string>
|
||||
<string name="preference_light_status_bar">Dunkle Statusleisten-Symbole</string>
|
||||
<string name="preference_light_nav_bar">Dunkle Navigationsleisten-Symbole</string>
|
||||
<string name="preference_hide_status_bar">Statusleiste ausblenden</string>
|
||||
<string name="preference_hide_nav_bar">Navigationsleiste ausblenden</string>
|
||||
<string name="widget_name_music">Musik</string>
|
||||
<string name="contacts_menu_open_externally">In Kontakte-App anzeigen</string>
|
||||
<string name="favorites_menu_pin">An Favoriten anheften</string>
|
||||
|
||||
@ -155,6 +155,8 @@
|
||||
<string name="preference_category_system_bars">System bars</string>
|
||||
<string name="preference_light_status_bar">Dark status bar icons</string>
|
||||
<string name="preference_light_nav_bar">Dark navigation bar icons</string>
|
||||
<string name="preference_hide_status_bar">Hide status bar</string>
|
||||
<string name="preference_hide_nav_bar">Hide navigation bar</string>
|
||||
<string name="widget_name_music">Music</string>
|
||||
<string name="contacts_menu_open_externally">Open in contacts app</string>
|
||||
<string name="favorites_menu_pin">Pin to favorites</string>
|
||||
|
||||
@ -7,6 +7,7 @@ import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
|
||||
import androidx.datastore.dataStore
|
||||
import de.mm20.launcher2.crashreporter.CrashReporter
|
||||
import de.mm20.launcher2.preferences.migrations.FactorySettingsMigration
|
||||
import de.mm20.launcher2.preferences.migrations.Migration_1_2
|
||||
|
||||
typealias LauncherDataStore = DataStore<Settings>
|
||||
|
||||
@ -14,7 +15,7 @@ internal val Context.dataStore: LauncherDataStore by dataStore(
|
||||
fileName = "settings.pb",
|
||||
serializer = SettingsSerializer,
|
||||
produceMigrations = {
|
||||
listOf(FactorySettingsMigration(it))
|
||||
listOf(FactorySettingsMigration(it), Migration_1_2())
|
||||
},
|
||||
corruptionHandler = ReplaceFileCorruptionHandler {
|
||||
CrashReporter.logException(it)
|
||||
@ -23,4 +24,4 @@ internal val Context.dataStore: LauncherDataStore by dataStore(
|
||||
}
|
||||
)
|
||||
|
||||
internal const val SchemaVersion = 1
|
||||
internal const val SchemaVersion = 2
|
||||
@ -118,6 +118,8 @@ fun createFactorySettings(context: Context): Settings {
|
||||
Settings.SystemBarsSettings.newBuilder()
|
||||
.setLightNavBar(false)
|
||||
.setLightStatusBar(false)
|
||||
.setHideStatusBar(false)
|
||||
.setHideNavBar(false)
|
||||
)
|
||||
.setCards(
|
||||
Settings.CardSettings.newBuilder()
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package de.mm20.launcher2.preferences.migrations
|
||||
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
|
||||
class Migration_1_2: VersionedMigration(1, 2) {
|
||||
|
||||
override suspend fun applyMigrations(builder: Settings.Builder): Settings.Builder {
|
||||
return builder.setSystemBars(
|
||||
builder.systemBars.toBuilder()
|
||||
.setHideNavBar(false)
|
||||
.setHideStatusBar(false)
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package de.mm20.launcher2.preferences.migrations
|
||||
|
||||
import androidx.datastore.core.DataMigration
|
||||
import de.mm20.launcher2.preferences.SchemaVersion
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
|
||||
abstract class VersionedMigration(
|
||||
private val fromVersion: Int,
|
||||
private val toVersion: Int
|
||||
) : DataMigration<Settings> {
|
||||
abstract suspend fun applyMigrations(builder: Settings.Builder): Settings.Builder
|
||||
|
||||
final override suspend fun migrate(currentData: Settings): Settings {
|
||||
val builder = currentData.toBuilder()
|
||||
applyMigrations(builder)
|
||||
builder.version = toVersion
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
override suspend fun cleanUp() {}
|
||||
|
||||
override suspend fun shouldMigrate(currentData: Settings): Boolean {
|
||||
return currentData.version <= fromVersion && SchemaVersion >= toVersion
|
||||
}
|
||||
}
|
||||
@ -162,6 +162,8 @@ message Settings {
|
||||
message SystemBarsSettings {
|
||||
bool lightStatusBar = 1;
|
||||
bool lightNavBar = 2;
|
||||
bool hideStatusBar = 3;
|
||||
bool hideNavBar = 4;
|
||||
}
|
||||
SystemBarsSettings system_bars = 23;
|
||||
|
||||
|
||||
@ -4,9 +4,13 @@ import android.app.WallpaperManager
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.*
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.afollestad.materialdialogs.LayoutMode
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||
@ -14,12 +18,14 @@ import com.afollestad.materialdialogs.callbacks.onDismiss
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
import de.mm20.launcher2.icons.DynamicIconController
|
||||
import de.mm20.launcher2.icons.IconRepository
|
||||
import de.mm20.launcher2.ui.legacy.helper.ActivityStarter
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.base.BaseActivity
|
||||
import de.mm20.launcher2.ui.databinding.ActivityLauncherBinding
|
||||
import de.mm20.launcher2.ui.launcher.modals.EditFavoritesView
|
||||
import de.mm20.launcher2.ui.launcher.modals.HiddenItemsView
|
||||
import de.mm20.launcher2.ui.legacy.helper.ActivityStarter
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
|
||||
@ -53,13 +59,31 @@ class LauncherActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
val windowController = WindowInsetsControllerCompat(window, binding.rootView)
|
||||
windowController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
|
||||
viewModel.lightStatusBar.observe(this) {
|
||||
windowController.isAppearanceLightStatusBars = it
|
||||
}
|
||||
|
||||
viewModel.lightNavBar.observe(this) {
|
||||
windowController.isAppearanceLightNavigationBars = it
|
||||
}
|
||||
|
||||
viewModel.hideStatusBar.observe(this) {
|
||||
if (it) {
|
||||
windowController.hide(WindowInsetsCompat.Type.statusBars())
|
||||
} else {
|
||||
windowController.show(WindowInsetsCompat.Type.statusBars())
|
||||
}
|
||||
}
|
||||
viewModel.hideNavBar.observe(this) {
|
||||
if (it) {
|
||||
windowController.hide(WindowInsetsCompat.Type.navigationBars())
|
||||
} else {
|
||||
windowController.show(WindowInsetsCompat.Type.navigationBars())
|
||||
}
|
||||
}
|
||||
|
||||
var editFavoritesDialog: MaterialDialog? = null
|
||||
viewModel.isEditFavoritesShown.observe(this) {
|
||||
if (it) {
|
||||
|
||||
@ -40,6 +40,9 @@ class LauncherActivityVM : ViewModel(), KoinComponent {
|
||||
!dim && light
|
||||
}.asLiveData()
|
||||
|
||||
val hideNavBar = dataStore.data.map { it.systemBars.hideNavBar }.asLiveData()
|
||||
val hideStatusBar = dataStore.data.map { it.systemBars.hideStatusBar }.asLiveData()
|
||||
|
||||
fun setDarkMode(darkMode: Boolean) {
|
||||
isDarkInMode.value = darkMode
|
||||
}
|
||||
|
||||
@ -194,6 +194,22 @@ fun AppearanceSettingsScreen() {
|
||||
viewModel.setLightNavBar(it)
|
||||
}
|
||||
)
|
||||
val hideStatusBar by viewModel.hideStatusBar.observeAsState()
|
||||
SwitchPreference(
|
||||
title = stringResource(R.string.preference_hide_status_bar),
|
||||
value = hideStatusBar == true,
|
||||
onValueChanged = {
|
||||
viewModel.setHideStatusBar(it)
|
||||
}
|
||||
)
|
||||
val hideNavBar by viewModel.hideNavBar.observeAsState()
|
||||
SwitchPreference(
|
||||
title = stringResource(R.string.preference_hide_nav_bar),
|
||||
value = hideNavBar == true,
|
||||
onValueChanged = {
|
||||
viewModel.setHideNavBar(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,4 +178,32 @@ class AppearanceSettingsScreenVM : ViewModel(), KoinComponent {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val hideStatusBar = dataStore.data.map { it.systemBars.hideStatusBar }.asLiveData()
|
||||
fun setHideStatusBar(hideStatusBar: Boolean) {
|
||||
viewModelScope.launch {
|
||||
dataStore.updateData {
|
||||
it.toBuilder()
|
||||
.setSystemBars(
|
||||
it.systemBars.toBuilder()
|
||||
.setHideStatusBar(hideStatusBar)
|
||||
)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val hideNavBar = dataStore.data.map { it.systemBars.hideNavBar }.asLiveData()
|
||||
fun setHideNavBar(hideNavBar: Boolean) {
|
||||
viewModelScope.launch {
|
||||
dataStore.updateData {
|
||||
it.toBuilder()
|
||||
.setSystemBars(
|
||||
it.systemBars.toBuilder()
|
||||
.setHideNavBar(hideNavBar)
|
||||
)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user