diff options
| author | Jules Aguillon | 2023-08-15 20:23:33 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2023-08-16 12:21:40 +0200 |
| commit | 5822f98bbbc3b96a90ff09551de8252ca18bca22 (patch) | |
| tree | b9463b52a746149a889a7f83c0fea694bbbf6888 /srcs/juloo.keyboard2/Config.java | |
| parent | 613aa283bdcab3d8d6e26fbe08aedcc49a8fe571 (diff) | |
| download | unexpected-keyboard-5822f98bbbc3b96a90ff09551de8252ca18bca22.tar.gz unexpected-keyboard-5822f98bbbc3b96a90ff09551de8252ca18bca22.zip | |
Migrate layouts preferences
The new `layouts` preference replaces three previous preferences:
layout
second_layout
custom_layout
Add a preference migration function, which first migration is to
migrate layouts into the new preference.
The migration must also be called from the SettingsActivity as it might
use a different preference store due to the boot-aware preference copy.
Diffstat (limited to 'srcs/juloo.keyboard2/Config.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Config.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 4684194..fdc7730 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -348,6 +348,7 @@ final class Config public static void initGlobalConfig(SharedPreferences prefs, Resources res, IKeyEventHandler handler) { + migrate(prefs); _globalConfig = new Config(prefs, res, handler); } @@ -360,4 +361,45 @@ final class Config { public void key_up(KeyValue value, Pointers.Modifiers flags); } + + /** Config migrations. */ + + private static int CONFIG_VERSION = 1; + + public static void migrate(SharedPreferences prefs) + { + int saved_version = prefs.getInt("version", 0); + Logs.debug_config_migration(saved_version, CONFIG_VERSION); + if (saved_version == CONFIG_VERSION) + return; + SharedPreferences.Editor e = prefs.edit(); + e.putInt("version", CONFIG_VERSION); + // Migrations might run on an empty [prefs] for new installs, in this case + // they set the default values of complex options. + switch (saved_version) // Fallback switch + { + case 0: + // Primary, secondary and custom layout options are merged into the new + // Layouts option. This also sets the default value. + List<LayoutsPreference.Layout> l = new ArrayList<LayoutsPreference.Layout>(); + l.add(migrate_layout(prefs.getString("layout", "system"))); + String snd_layout = prefs.getString("second_layout", "none"); + if (snd_layout != null && !snd_layout.equals("none")) + l.add(migrate_layout(snd_layout)); + String custom_layout = prefs.getString("custom_layout", ""); + if (custom_layout != null && !custom_layout.equals("")) + l.add(new LayoutsPreference.CustomLayout(custom_layout)); + LayoutsPreference.save_to_preferences(e, l); + case 1: + default: break; + } + e.commit(); + } + + private static LayoutsPreference.Layout migrate_layout(String name) + { + if (name == null || name.equals("system")) + return new LayoutsPreference.SystemLayout(); + return new LayoutsPreference.NamedLayout(name); + } } |
