mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-20 17:00:30 +00:00
fix issues with adding words to personal dictionary
This commit is contained in:
parent
2439791322
commit
f498d14e3b
2 changed files with 35 additions and 28 deletions
|
@ -57,6 +57,7 @@ Plan / to do:
|
||||||
* ~license issues, require using an external library~
|
* ~license issues, require using an external library~
|
||||||
* re-consider preferring lowercase word for typed history in some cases (DictionaryFacilitatorImpl.addWordToUserHistory)
|
* re-consider preferring lowercase word for typed history in some cases (DictionaryFacilitatorImpl.addWordToUserHistory)
|
||||||
* ~move/copy _use contacts_ setting from well hidden spell checker settings to _text correction_ settings~
|
* ~move/copy _use contacts_ setting from well hidden spell checker settings to _text correction_ settings~
|
||||||
|
* add emojis to user history, to be used for next word suggestions
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
@ -681,34 +681,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
&& Settings.getInstance().getCurrent().mAddToPersonalDictionary
|
&& Settings.getInstance().getCurrent().mAddToPersonalDictionary
|
||||||
&& (mSecondaryDictionaryGroup == null || mDictionaryGroup.mConfidence != mSecondaryDictionaryGroup.mConfidence)
|
&& (mSecondaryDictionaryGroup == null || mDictionaryGroup.mConfidence != mSecondaryDictionaryGroup.mConfidence)
|
||||||
&& !wasAutoCapitalized && words.length == 1) {
|
&& !wasAutoCapitalized && words.length == 1) {
|
||||||
// user history always reports words as invalid, so we need to check isInDictionary instead
|
addToPersonalDictionaryIfInvalidButInHistory(suggestion, validMainWord, validSecondaryWord);
|
||||||
// also maybe a problem: words added to dictionaries (user and history) are apparently found
|
|
||||||
// only after some delay. but this is not too bad, it just delays adding
|
|
||||||
|
|
||||||
final DictionaryGroup dictionaryGroup = getCurrentlyPreferredDictionaryGroup();
|
|
||||||
final ExpandableBinaryDictionary userDict = dictionaryGroup.getSubDict(Dictionary.TYPE_USER);
|
|
||||||
final Dictionary userHistoryDict = dictionaryGroup.getSubDict(Dictionary.TYPE_USER_HISTORY);
|
|
||||||
if (userDict != null && userHistoryDict.isInDictionary(suggestion)) {
|
|
||||||
if (validMainWord == null)
|
|
||||||
validMainWord = isValidWord(suggestion, ALL_DICTIONARY_TYPES, mDictionaryGroup);
|
|
||||||
if (validMainWord)
|
|
||||||
return;
|
|
||||||
if (mSecondaryDictionaryGroup != null) {
|
|
||||||
if (validSecondaryWord == null)
|
|
||||||
validSecondaryWord = isValidWord(suggestion, ALL_DICTIONARY_TYPES, mSecondaryDictionaryGroup);
|
|
||||||
if (validSecondaryWord)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (userDict.isInDictionary(suggestion))
|
|
||||||
return;
|
|
||||||
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
UserDictionary.Words.addWord(userDict.mContext, suggestion,
|
|
||||||
250 /*FREQUENCY_FOR_USER_DICTIONARY_ADDS*/, null, dictionaryGroup.mLocale);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NgramContext ngramContextForCurrentWord = ngramContext;
|
NgramContext ngramContextForCurrentWord = ngramContext;
|
||||||
|
@ -730,6 +703,39 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// main and secondary isValid provided to avoid duplicate lookups
|
||||||
|
private void addToPersonalDictionaryIfInvalidButInHistory(String suggestion, Boolean validMainWord, Boolean validSecondaryWord) {
|
||||||
|
// user history always reports words as invalid, so here we need to check isInDictionary instead
|
||||||
|
// also maybe a problem: words added to dictionaries (user and history) are apparently found
|
||||||
|
// only after some delay. but this is not too bad, it just delays adding
|
||||||
|
|
||||||
|
final DictionaryGroup dictionaryGroup = getCurrentlyPreferredDictionaryGroup();
|
||||||
|
final ExpandableBinaryDictionary userDict = dictionaryGroup.getSubDict(Dictionary.TYPE_USER);
|
||||||
|
final Dictionary userHistoryDict = dictionaryGroup.getSubDict(Dictionary.TYPE_USER_HISTORY);
|
||||||
|
if (userDict != null && userHistoryDict.isInDictionary(suggestion)) {
|
||||||
|
if (validMainWord == null)
|
||||||
|
validMainWord = isValidWord(suggestion, ALL_DICTIONARY_TYPES, mDictionaryGroup);
|
||||||
|
if (validMainWord)
|
||||||
|
return;
|
||||||
|
if (mSecondaryDictionaryGroup != null) {
|
||||||
|
if (validSecondaryWord == null)
|
||||||
|
validSecondaryWord = isValidWord(suggestion, ALL_DICTIONARY_TYPES, mSecondaryDictionaryGroup);
|
||||||
|
if (validSecondaryWord)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (userDict.isInDictionary(suggestion))
|
||||||
|
return;
|
||||||
|
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
UserDictionary.Words.addWord(userDict.mContext, suggestion,
|
||||||
|
250 /*FREQUENCY_FOR_USER_DICTIONARY_ADDS*/, null, dictionaryGroup.mLocale);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void putWordIntoValidSpellingWordCache(
|
private void putWordIntoValidSpellingWordCache(
|
||||||
@Nonnull final String caller,
|
@Nonnull final String caller,
|
||||||
@Nonnull final String originalWord) {
|
@Nonnull final String originalWord) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue