fixed the 'wait for the dictionary to load' toast being displayed for too long, when attempting to press many keys in a short period of time
This commit is contained in:
parent
d95eb807cc
commit
cc0ce856c5
3 changed files with 22 additions and 11 deletions
|
|
@ -104,7 +104,7 @@ public abstract class HotkeyHandler extends TypingHandler {
|
|||
}
|
||||
|
||||
if (DictionaryLoader.getInstance(this).isRunning()) {
|
||||
UI.toast(this, R.string.dictionary_loading_please_wait);
|
||||
UI.toastShortSingle(this, R.string.dictionary_loading_please_wait);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -223,7 +223,7 @@ public abstract class HotkeyHandler extends TypingHandler {
|
|||
renderMainView();
|
||||
forceShowWindowIfHidden();
|
||||
if (!suggestionOps.isEmpty()) {
|
||||
UI.toastLanguage(this, mLanguage);
|
||||
UI.toastShortSingle(this, mLanguage.getClass().getSimpleName(), mLanguage.getName());
|
||||
}
|
||||
|
||||
if (mInputMode instanceof ModePredictive) {
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ public abstract class TypingHandler extends KeyPadHandler {
|
|||
protected void getSuggestions() {
|
||||
if (mInputMode instanceof ModePredictive && DictionaryLoader.getInstance(this).isRunning()) {
|
||||
mInputMode.reset();
|
||||
UI.toast(this, R.string.dictionary_loading_please_wait);
|
||||
UI.toastShortSingle(this, R.string.dictionary_loading_please_wait);
|
||||
} else {
|
||||
mInputMode.loadSuggestions(this::handleSuggestions, suggestionOps.getCurrent());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,14 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||
|
||||
public class UI {
|
||||
private static Toast toastLang = null;
|
||||
private static final HashMap<String, Toast> singleToasts = new HashMap<>();
|
||||
|
||||
|
||||
public static void showChangeKeyboardDialog(Context context) {
|
||||
|
|
@ -79,14 +82,22 @@ public class UI {
|
|||
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public static void toastLanguage(@NonNull Context context, @NonNull Language language) {
|
||||
if (toastLang != null) {
|
||||
toastLang.cancel();
|
||||
public static void toastShortSingle(@NonNull Context context, @NonNull String uniqueId, @NonNull String message) {
|
||||
Toast toast = singleToasts.get(uniqueId);
|
||||
|
||||
if (toast != null) {
|
||||
toast.cancel();
|
||||
}
|
||||
|
||||
// we recreate the toast, because if set new text, when it is fading out,
|
||||
// the new text is discarded
|
||||
toastLang = Toast.makeText(context, language.getName(), Toast.LENGTH_SHORT);
|
||||
toastLang.show();
|
||||
// we recreate the toast, because if set new text, when it is fading out, it is ignored
|
||||
toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
|
||||
singleToasts.put(uniqueId, toast);
|
||||
}
|
||||
|
||||
|
||||
public static void toastShortSingle(@NonNull Context context, int resourceId) {
|
||||
toastShortSingle(context, String.valueOf(resourceId), context.getString(resourceId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue