-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(android/engine): Initialize index when resuming KeyboardPicker #12832
Conversation
Fixes: #11714 Fixes: KEYMAN-ANDROID-39S Get the current keyboard index from shared preferences if it's uninitialized.
User Test ResultsTest specification and instructions User tests are not required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a couple simple things to make this easier to read
@@ -252,7 +253,11 @@ protected void onResume() { | |||
adapter.notifyDataSetChanged(); | |||
} | |||
|
|||
int curKbPos = KeyboardController.getInstance().getKeyboardIndex(KMKeyboard.currentKeyboard()); | |||
|
|||
SharedPreferences prefs = this.getSharedPreferences(this.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefs are only used if the currentKeyboard is null, so I would not initialize this unless it is null
Instead of the ternary operator, just use a regular if-else, so the logic is easier to follow, and we only load variables that we are going to use.
android/KMEA/app/src/main/java/com/keyman/engine/KeyboardPickerActivity.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Changes in this pull request will be available for download in Keyman version 18.0.160-alpha |
String currentKeyboardKey = KMKeyboard.currentKeyboard(); | ||
if (currentKeyboardKey == null) { | ||
SharedPreferences prefs = this.getSharedPreferences(this.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); | ||
currentKeyboardIndex = prefs.getInt(KMManager.KMKey_UserKeyboardIndex, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the pref has an invalid index? Could this ever happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preference should only save valid indexes.
If the preference key doesn't exist, it'll fallback to 0.
Fixes: #11714
Fixes: KEYMAN-ANDROID-39S
From the crash reports, it's possible for
KeyboardPickerActivity
to resume, and have the keyboard keyKMKeyboard.currentKeyboard()
be uninitialized (null).This updates
KeyboardPickerActivity.onResume
to get the keyboard index from the saved preference ifKMKeyboard.currentKeyboard()
is null.@keymanapp-test-bot skip