From 8acf5b5464c1996a822aa8e5f1e8fb5afd7dc0c6 Mon Sep 17 00:00:00 2001 From: Michael W Date: Sat, 22 Jan 2022 18:04:06 +0100 Subject: [PATCH] LatinIME: Properly refresh summary * onResume() of AppearanceSettingsFragment gets called before onPause() of CustomInputStyleSettingsFragment * Instead, save after each modification so the lifecycle doesn't matter Change-Id: If5c5df8b589c08df61eea2643c217e9665a01002 --- .../CustomInputStyleSettingsFragment.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java index ca4d14c0b..bc7ffb10a 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java @@ -188,7 +188,8 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment return; } if (findDuplicatedSubtype(subtype) == null) { - mRichImm.setAdditionalInputMethodSubtypes(getSubtypes()); + final InputMethodSubtype[] subTypes = saveAndGetSubTypes(); + mRichImm.setAdditionalInputMethodSubtypes(subTypes); return; } @@ -205,7 +206,8 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment mIsAddingNewSubtype = false; final InputMethodSubtype subtype = stylePref.getSubtype(); if (findDuplicatedSubtype(subtype) == null) { - mRichImm.setAdditionalInputMethodSubtypes(getSubtypes()); + final InputMethodSubtype[] subTypes = saveAndGetSubTypes(); + mRichImm.setAdditionalInputMethodSubtypes(subTypes); mSubtypePreferenceKeyForSubtypeEnabler = stylePref.getKey(); mSubtypeEnablerNotificationDialog = createDialog(); mSubtypeEnablerNotificationDialog.show(); @@ -299,16 +301,7 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment @Override public void onPause() { super.onPause(); - final String oldSubtypes = Settings.readPrefAdditionalSubtypes(mPrefs, getResources()); - final InputMethodSubtype[] subtypes = getSubtypes(); - final String prefSubtypes = AdditionalSubtypeUtils.createPrefSubtypes(subtypes); - if (DEBUG_CUSTOM_INPUT_STYLES) { - Log.i(TAG, "Save custom input styles: " + prefSubtypes); - } - if (prefSubtypes.equals(oldSubtypes)) { - return; - } - Settings.writePrefAdditionalSubtypes(mPrefs, prefSubtypes); + final InputMethodSubtype[] subtypes = saveAndGetSubTypes(); mRichImm.setAdditionalInputMethodSubtypes(subtypes); } @@ -335,4 +328,18 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment } return super.onOptionsItemSelected(item); } + + private InputMethodSubtype[] saveAndGetSubTypes() { + final String oldSubtypes = Settings.readPrefAdditionalSubtypes(mPrefs, getResources()); + final InputMethodSubtype[] subtypes = getSubtypes(); + final String prefSubtypes = AdditionalSubtypeUtils.createPrefSubtypes(subtypes); + if (DEBUG_CUSTOM_INPUT_STYLES) { + Log.i(TAG, "Save custom input styles: " + prefSubtypes); + } + if (prefSubtypes.equals(oldSubtypes)) { + return null; + } + Settings.writePrefAdditionalSubtypes(mPrefs, prefSubtypes); + return subtypes; + } }