1
0
Fork 0

fixed changing the language also causing the currency characters to change

This commit is contained in:
sspanak 2024-03-12 11:03:36 +02:00 committed by Dimo Karaivanov
parent 60aa9acd32
commit 181d596c7c
2 changed files with 41 additions and 32 deletions

View file

@ -129,34 +129,6 @@ abstract public class InputMode {
textCase = allowedTextCases.get(0);
}
/**
* This is used in nextTextCase() for switching to the next set of characters. Obviously,
* special chars do not have a text case, but we use this trick to alternate the char groups.
*/
protected boolean nextSpecialCharacters() { return nextSpecialCharacters(language); }
protected boolean nextSpecialCharacters(Language altLanguage) {
if (altLanguage == null || digitSequence.isEmpty()) {
return false;
}
int previousGroup = specialCharSelectedGroup;
int key = digitSequence.charAt(0) - '0';
ArrayList<String> chars = altLanguage.getKeyCharacters(key, ++specialCharSelectedGroup);
if (chars.isEmpty() && specialCharSelectedGroup == 1) {
specialCharSelectedGroup = 0;
return false;
} else if (chars.isEmpty()) {
specialCharSelectedGroup = 0;
chars = altLanguage.getKeyCharacters(key, specialCharSelectedGroup);
}
suggestions.clear();
suggestions.addAll(chars);
return previousGroup != specialCharSelectedGroup;
}
public boolean nextTextCase() {
if (nextSpecialCharacters()) {
return true;
@ -177,6 +149,43 @@ abstract public class InputMode {
// Based on the internal logic of the mode (punctuation or grammar rules), re-adjust the text case for when getSuggestions() is called.
protected String adjustSuggestionTextCase(String word, int newTextCase) { return word; }
/**
* This is used in nextTextCase() for switching to the next set of characters. Obviously,
* special chars do not have a text case, but we use this trick to alternate the char groups.
*/
protected boolean nextSpecialCharacters() { return nextSpecialCharacters(language); }
protected boolean nextSpecialCharacters(Language altLanguage) {
int previousGroup = specialCharSelectedGroup;
specialCharSelectedGroup++;
return
loadSpecialCharacters(altLanguage) // validates specialCharSelectedGroup
&& previousGroup != specialCharSelectedGroup; // verifies validation has passed
}
protected boolean loadSpecialCharacters(Language altLanguage) {
if (altLanguage == null || digitSequence.isEmpty()) {
return false;
}
int key = digitSequence.charAt(0) - '0';
ArrayList<String> chars = altLanguage.getKeyCharacters(key, specialCharSelectedGroup);
if (chars.isEmpty() && specialCharSelectedGroup == 1) {
specialCharSelectedGroup = 0;
return false;
} else if (chars.isEmpty()) {
specialCharSelectedGroup = 0;
chars = altLanguage.getKeyCharacters(key, specialCharSelectedGroup);
}
suggestions.clear();
suggestions.addAll(chars);
return true;
}
// Stem filtering.
// Where applicable, return "true" if the mode supports it and the operation was possible.
public boolean clearWordStem() { return setWordStem("", true); }

View file

@ -237,7 +237,7 @@ public class ModePredictive extends InputMode {
.setStem(stem)
.setLanguage(searchLanguage)
.setInputWord(currentWord)
.setWordsChangedHandler(this::getPredictions)
.setWordsChangedHandler(this::onPredictions)
.load();
}
@ -249,7 +249,7 @@ public class ModePredictive extends InputMode {
*/
private boolean loadStaticSuggestions(Runnable onLoad) {
if (digitSequence.equals(Language.PUNCTUATION_KEY) || digitSequence.equals(Language.SPECIAL_CHARS_KEY)) {
super.nextSpecialCharacters();
super.loadSpecialCharacters(language);
onLoad.run();
return true;
} else if (!digitSequence.equals(EmojiLanguage.CUSTOM_EMOJI_SEQUENCE) && digitSequence.startsWith(EmojiLanguage.EMOJI_SEQUENCE)) {
@ -269,10 +269,10 @@ public class ModePredictive extends InputMode {
/**
* getPredictions
* onPredictions
* Gets the currently available Predictions and sends them over to the external caller.
*/
private void getPredictions() {
private void onPredictions() {
// in case the user hasn't added any custom emoji, do not allow advancing to the empty character group
if (predictions.getList().isEmpty() && digitSequence.startsWith(EmojiLanguage.EMOJI_SEQUENCE)) {
digitSequence = EmojiLanguage.EMOJI_SEQUENCE;