Add options to hide system bars
This commit is contained in:
@@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
+25
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user