From 5822f98bbbc3b96a90ff09551de8252ca18bca22 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 15 Aug 2023 20:23:33 +0200 Subject: 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. --- srcs/juloo.keyboard2/ListGroupPreference.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'srcs/juloo.keyboard2/ListGroupPreference.java') diff --git a/srcs/juloo.keyboard2/ListGroupPreference.java b/srcs/juloo.keyboard2/ListGroupPreference.java index ad47411..075b38c 100644 --- a/srcs/juloo.keyboard2/ListGroupPreference.java +++ b/srcs/juloo.keyboard2/ListGroupPreference.java @@ -78,6 +78,12 @@ public abstract class ListGroupPreference extends PreferenceGroup return (s != null) ? load_from_string(s, serializer) : def; } + /** Save items into the preferences. Does not call [prefs.commit()]. */ + static void save_to_preferences(String key, SharedPreferences.Editor prefs, List items, Serializer serializer) + { + prefs.putString(key, save_to_string(items, serializer)); + } + /** Decode a list of string previously encoded with [save_to_string]. Returns [null] on error. */ static List load_from_string(String inp, Serializer serializer) @@ -92,6 +98,7 @@ public abstract class ListGroupPreference extends PreferenceGroup } catch (JSONException e) { + Logs.exn("load_from_string", e); return null; } } @@ -107,7 +114,10 @@ public abstract class ListGroupPreference extends PreferenceGroup { serialized_items.add(serializer.save_item(it)); } - catch (JSONException e) {} + catch (JSONException e) + { + Logs.exn("save_to_string", e); + } } return (new JSONArray(serialized_items)).toString(); } -- cgit v1.2.3