Predictive Mode: when there is no dictionary for the current language, a toast message will appear asking the user to load it from Settings
This commit is contained in:
parent
55211b9cd9
commit
ff74e55cf8
8 changed files with 101 additions and 9 deletions
|
|
@ -70,6 +70,17 @@ public class DictionaryDb {
|
|||
}
|
||||
|
||||
|
||||
public static void areThereWords(Handler handler, Language language) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
int langId = language != null ? language.getId() : -1;
|
||||
handler.sendEmptyMessage(getInstance().wordsDao().count(langId) > 0 ? 1 : 0);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
public static void truncateWords(Handler handler) {
|
||||
new Thread() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ import java.util.List;
|
|||
|
||||
@Dao
|
||||
interface WordsDao {
|
||||
@Query("SELECT COUNT(id) FROM words WHERE :langId < 0 OR lang = :langId")
|
||||
int count(int langId);
|
||||
|
||||
@Query(
|
||||
"SELECT * " +
|
||||
"FROM words " +
|
||||
|
|
|
|||
67
src/io/github/sspanak/tt9/ime/EmptyDatabaseWarning.java
Normal file
67
src/io/github/sspanak/tt9/ime/EmptyDatabaseWarning.java
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package io.github.sspanak.tt9.ime;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.db.DictionaryDb;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.LanguageCollection;
|
||||
import io.github.sspanak.tt9.preferences.SettingsStore;
|
||||
import io.github.sspanak.tt9.ui.UI;
|
||||
|
||||
public class EmptyDatabaseWarning {
|
||||
final int WARNING_INTERVAL;
|
||||
private static final HashMap<Integer, Long> warningDisplayedTime = new HashMap<>();
|
||||
|
||||
private Language language;
|
||||
|
||||
public EmptyDatabaseWarning(SettingsStore settings) {
|
||||
WARNING_INTERVAL = settings.getDictionaryMissingWarningInterval();
|
||||
|
||||
for (Language lang : LanguageCollection.getAll()) {
|
||||
if (!warningDisplayedTime.containsKey(lang.getId())) {
|
||||
warningDisplayedTime.put(lang.getId(), 0L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void emitOnce(Language language) {
|
||||
if (language == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.language = language;
|
||||
DictionaryDb.areThereWords(handleWordCount, language);
|
||||
}
|
||||
|
||||
private final Handler handleWordCount = new Handler(Looper.getMainLooper()) {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
boolean areThereWords = msg.what == 1;
|
||||
|
||||
if (areThereWords) {
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = TraditionalT9.getMainContext();
|
||||
if (context == null || !warningDisplayedTime.containsKey(language.getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
Long lastWarningTime = warningDisplayedTime.get(language.getId());
|
||||
boolean isItWarningTimeAgain = lastWarningTime != null && now - lastWarningTime > WARNING_INTERVAL;
|
||||
|
||||
if (isItWarningTimeAgain) {
|
||||
String message = context.getString(R.string.dictionary_missing_go_load_it, language.getName());
|
||||
UI.toastLong(context, message);
|
||||
warningDisplayedTime.put(language.getId(), now);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -10,12 +10,14 @@ import java.util.regex.Pattern;
|
|||
|
||||
import io.github.sspanak.tt9.Logger;
|
||||
import io.github.sspanak.tt9.db.DictionaryDb;
|
||||
import io.github.sspanak.tt9.ime.EmptyDatabaseWarning;
|
||||
import io.github.sspanak.tt9.ime.InputFieldHelper;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.Punctuation;
|
||||
import io.github.sspanak.tt9.preferences.SettingsStore;
|
||||
|
||||
public class ModePredictive extends InputMode {
|
||||
private final EmptyDatabaseWarning emptyDbWarning;
|
||||
private final SettingsStore settings;
|
||||
|
||||
public int getId() { return MODE_PREDICTIVE; }
|
||||
|
|
@ -42,11 +44,13 @@ public class ModePredictive extends InputMode {
|
|||
|
||||
|
||||
ModePredictive(SettingsStore settings) {
|
||||
this.settings = settings;
|
||||
allowedTextCases.add(CASE_LOWER);
|
||||
allowedTextCases.add(CASE_CAPITALIZE);
|
||||
allowedTextCases.add(CASE_UPPER);
|
||||
|
||||
emptyDbWarning = new EmptyDatabaseWarning(settings);
|
||||
this.settings = settings;
|
||||
|
||||
// digitSequence limiter when selecting emoji
|
||||
// "11" = Emoji level 0, "111" = Emoji level 1,... up to the maximum amount of 1s
|
||||
StringBuilder maxEmojiSequenceBuilder = new StringBuilder();
|
||||
|
|
@ -344,6 +348,7 @@ public class ModePredictive extends InputMode {
|
|||
dbSuggestions = dbSuggestions == null ? new ArrayList<>() : dbSuggestions;
|
||||
|
||||
if (dbSuggestions.size() == 0 && digitSequence.length() > 0) {
|
||||
emptyDbWarning.emitOnce(currentLanguage);
|
||||
dbSuggestions = generatePossibleCompletions(currentLanguage, currentInputFieldWord);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,6 +209,8 @@ public class SettingsStore {
|
|||
public int getDictionaryImportProgressUpdateInterval() { return 250; /* ms */ }
|
||||
public int getDictionaryImportWordChunkSize() { return 1000; /* words */ }
|
||||
|
||||
public int getDictionaryMissingWarningInterval() { return 30000; /* ms */ }
|
||||
|
||||
public int getSuggestionsMax() { return 20; }
|
||||
public int getSuggestionsMin() { return 8; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue