abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/ListGroupPreference.java
diff options
context:
space:
mode:
authorJules Aguillon2023-08-15 20:23:33 +0200
committerJules Aguillon2023-08-16 12:21:40 +0200
commit5822f98bbbc3b96a90ff09551de8252ca18bca22 (patch)
treeb9463b52a746149a889a7f83c0fea694bbbf6888 /srcs/juloo.keyboard2/ListGroupPreference.java
parent613aa283bdcab3d8d6e26fbe08aedcc49a8fe571 (diff)
downloadunexpected-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/ListGroupPreference.java')
-rw-r--r--srcs/juloo.keyboard2/ListGroupPreference.java12
1 files changed, 11 insertions, 1 deletions
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<E> extends PreferenceGroup
return (s != null) ? load_from_string(s, serializer) : def;
}
+ /** Save items into the preferences. Does not call [prefs.commit()]. */
+ static <E> void save_to_preferences(String key, SharedPreferences.Editor prefs, List<E> items, Serializer<E> 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 <E> List<E> load_from_string(String inp, Serializer<E> serializer)
@@ -92,6 +98,7 @@ public abstract class ListGroupPreference<E> extends PreferenceGroup
}
catch (JSONException e)
{
+ Logs.exn("load_from_string", e);
return null;
}
}
@@ -107,7 +114,10 @@ public abstract class ListGroupPreference<E> 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();
}