Add clock widget parts preferences

This commit is contained in:
MM20
2022-03-02 13:21:32 +01:00
parent bdbcba6d67
commit edd59f2d06
8 changed files with 156 additions and 13 deletions
@@ -8,6 +8,7 @@ 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
import de.mm20.launcher2.preferences.migrations.Migration_2_3
typealias LauncherDataStore = DataStore<Settings>
@@ -15,7 +16,11 @@ internal val Context.dataStore: LauncherDataStore by dataStore(
fileName = "settings.pb",
serializer = SettingsSerializer,
produceMigrations = {
listOf(FactorySettingsMigration(it), Migration_1_2())
listOf(
FactorySettingsMigration(it),
Migration_1_2(),
Migration_2_3()
)
},
corruptionHandler = ReplaceFileCorruptionHandler {
CrashReporter.logException(it)
@@ -24,4 +29,4 @@ internal val Context.dataStore: LauncherDataStore by dataStore(
}
)
internal const val SchemaVersion = 2
internal const val SchemaVersion = 3
@@ -35,6 +35,10 @@ fun createFactorySettings(context: Context): Settings {
.newBuilder()
.setLayout(Settings.ClockWidgetSettings.ClockWidgetLayout.Vertical)
.setClockStyle(Settings.ClockWidgetSettings.ClockStyle.DigitalClock1)
.setAlarmPart(true)
.setBatteryPart(true)
.setDatePart(true)
.setMusicPart(true)
.build()
)
.setFavorites(
@@ -0,0 +1,15 @@
package de.mm20.launcher2.preferences.migrations
import de.mm20.launcher2.preferences.Settings
class Migration_2_3: VersionedMigration(2, 3) {
override suspend fun applyMigrations(builder: Settings.Builder): Settings.Builder {
return builder.setClockWidget(
builder.clockWidget.toBuilder()
.setAlarmPart(true)
.setBatteryPart(true)
.setDatePart(true)
.setMusicPart(true)
)
}
}
@@ -52,6 +52,10 @@ message Settings {
EmptyClock = 4;
}
ClockStyle clock_style = 2;
bool date_part = 3;
bool music_part = 4;
bool battery_part = 5;
bool alarm_part = 6;
}
ClockWidgetSettings clock_widget = 7;