From 8aadea6086cb15025639b868414fffd8adbfecad Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Mon, 14 Mar 2022 08:43:10 +0700 Subject: [PATCH] fix(oem/fv/android): Refresh menu on install --- .../keyboards/FVKeyboardSettingsActivity.java | 11 +++++++---- .../java/com/firstvoices/keyboards/MainActivity.java | 12 +++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/FVKeyboardSettingsActivity.java b/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/FVKeyboardSettingsActivity.java index bf2ca8bc4b..02e00f7c40 100644 --- a/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/FVKeyboardSettingsActivity.java +++ b/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/FVKeyboardSettingsActivity.java @@ -57,6 +57,7 @@ public final class FVKeyboardSettingsActivity extends AppCompatActivity { private String associatedLexicalModel = ""; private String lgCode; private static RelativeLayout checkModelLayout = null; + private static Intent intent = null; private static Bundle bundle = null; private static ListView listView = null; private String lgName; @@ -121,7 +122,8 @@ public final class FVKeyboardSettingsActivity extends AppCompatActivity { setContentView(R.layout.fv_keyboard_settings_list_layout); if (getIntent() != null && getIntent().getExtras() != null) { - bundle = getIntent().getExtras(); + intent = getIntent(); + bundle = intent.getExtras(); } if (bundle == null) { // Should never actually happen. @@ -182,8 +184,7 @@ public final class FVKeyboardSettingsActivity extends AppCompatActivity { }); // The following two layouts/toggles will need to link with these objects. - Context appContext = this.getApplicationContext(); - prefs = appContext.getSharedPreferences(appContext.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); boolean mayPredict = prefs.getBoolean(KMManager.getLanguagePredictionPreferenceKey(lgCode), false); boolean mayCorrect = prefs.getBoolean(KMManager.getLanguageCorrectionPreferenceKey(lgCode), false); @@ -382,7 +383,9 @@ public final class FVKeyboardSettingsActivity extends AppCompatActivity { public static void restartActivity() { if (context != null) { - ((Activity)context).recreate(); + // Not using Activity.recreate() because we need to recalculate the items + ((Activity)context).finish(); + ((Activity)context).startActivity(intent); } } diff --git a/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/MainActivity.java b/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/MainActivity.java index b0e71e885e..5d3e5c5939 100644 --- a/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/MainActivity.java +++ b/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/MainActivity.java @@ -19,6 +19,7 @@ import io.sentry.android.core.SentryAndroid; import com.tavultesoft.kmea.*; import com.tavultesoft.kmea.data.Keyboard; +import com.tavultesoft.kmea.util.BCP47; import com.tavultesoft.kmea.util.DownloadFileUtils; import com.tavultesoft.kmea.KeyboardEventHandler.OnKeyboardDownloadEventListener; @@ -250,7 +251,7 @@ public class MainActivity extends AppCompatActivity implements OnKeyboardDownloa @Override public void onLexicalModelInstalled(List> lexicalModelsInstalled) { - String langId = (KMManager.getCurrentKeyboardInfo(this) != null) ? + String keyboardLangId = (KMManager.getCurrentKeyboardInfo(this) != null) ? KMManager.getCurrentKeyboardInfo(this).getLanguageID() : KMManager.KMDefault_LanguageID; boolean matchingModel = false; @@ -260,21 +261,22 @@ public class MainActivity extends AppCompatActivity implements OnKeyboardDownloa for(int i=0; ilexicalModelInfo = new HashMap<>(lexicalModelsInstalled.get(i)); - if(lexicalModelInfo.get(KMManager.KMKey_LanguageID).equals(langId)) { + String lexicalModelLangId = lexicalModelInfo.get(KMManager.KMKey_LanguageID); + if(BCP47.languageEquals(keyboardLangId, lexicalModelLangId)) { matchingModel = true; } KMManager.addLexicalModel(this, lexicalModelInfo); // Enable predictions and corrections toggles - editor.putBoolean(KMManager.getLanguagePredictionPreferenceKey(lexicalModelInfo.get(KMManager.KMKey_LanguageID)), true); - editor.putBoolean(KMManager.getLanguageCorrectionPreferenceKey(lexicalModelInfo.get(KMManager.KMKey_LanguageID)), true); + editor.putBoolean(KMManager.getLanguagePredictionPreferenceKey(lexicalModelLangId), true); + editor.putBoolean(KMManager.getLanguageCorrectionPreferenceKey(lexicalModelLangId), true); } editor.commit(); // We're on the main thread, so if the active keyboard's language code matches, // let's register the associated lexical model. if(matchingModel) { - KMManager.registerAssociatedLexicalModel(langId); + KMManager.registerAssociatedLexicalModel(keyboardLangId); } // Launch/refresh FV Keyboard Settings menu