fixed the auto-update reminder being too aggressive
This commit is contained in:
parent
f6a788ee63
commit
2ec788ea64
8 changed files with 27 additions and 21 deletions
|
|
@ -7,6 +7,7 @@ import android.os.Handler;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.ConsumerCompat;
|
||||
|
|
@ -38,6 +39,7 @@ public class DictionaryLoader {
|
|||
private ConsumerCompat<Bundle> onStatusChange;
|
||||
private Thread loadThread;
|
||||
|
||||
private final HashMap<Integer, Long> lastAutoLoadAttemptTime = new HashMap<>();
|
||||
private int currentFile = 0;
|
||||
private long importStartTime = 0;
|
||||
private long lastProgressUpdate = 0;
|
||||
|
|
@ -115,8 +117,16 @@ public class DictionaryLoader {
|
|||
return;
|
||||
}
|
||||
|
||||
Long lastUpdateTime = self.lastAutoLoadAttemptTime.get(language.getId());
|
||||
boolean isItTooSoon = lastUpdateTime != null && System.currentTimeMillis() - lastUpdateTime < SettingsStore.DICTIONARY_AUTO_LOAD_COOLDOWN_TIME;
|
||||
if (isItTooSoon) {
|
||||
return;
|
||||
}
|
||||
|
||||
WordStoreAsync.getLastLanguageUpdateTime(
|
||||
(hash) -> {
|
||||
self.lastAutoLoadAttemptTime.put(language.getId(), System.currentTimeMillis());
|
||||
|
||||
// no words at all, load without confirmation
|
||||
if (hash.isEmpty()) {
|
||||
load(context, language);
|
||||
|
|
|
|||
|
|
@ -140,9 +140,11 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
int result = super.onStartCommand(intent, flags, startId);
|
||||
|
||||
String message = intent != null ? intent.getStringExtra(PopupDialogActivity.DIALOG_CLOSED_INTENT) : null;
|
||||
if (message != null && !message.isEmpty()) {
|
||||
if (message != null) {
|
||||
forceShowWindowIfHidden();
|
||||
UI.toastLong(self, message);
|
||||
if (!message.isEmpty()) {
|
||||
UI.toastLong(self, message);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -230,6 +232,9 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
protected void onFinishTyping() {
|
||||
cancelAutoAccept();
|
||||
if (!(mInputMode instanceof ModePredictive)) {
|
||||
DictionaryLoader.autoLoad(this, mLanguage);
|
||||
}
|
||||
mInputMode = InputMode.getInstance(null, null, null, InputMode.MODE_PASSTHROUGH);
|
||||
}
|
||||
|
||||
|
|
@ -239,8 +244,6 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
clearSuggestions();
|
||||
statusBar.setText("--");
|
||||
|
||||
DictionaryLoader.autoLoad(this, mLanguage);
|
||||
|
||||
normalizationHandler.removeCallbacksAndMessages(null);
|
||||
normalizationHandler.postDelayed(
|
||||
() -> { if (!DictionaryLoader.getInstance(this).isRunning()) WordStoreAsync.normalizeNext(); },
|
||||
|
|
@ -789,7 +792,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
* are invisible. This function forces the InputMethodManager to show our window.
|
||||
*/
|
||||
protected void forceShowWindowIfHidden() {
|
||||
if (mInputMode.isPassthrough() || isInputViewShown()) {
|
||||
if (getInputMode().isPassthrough() || isInputViewShown()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -278,9 +278,9 @@ public class SettingsStore {
|
|||
}
|
||||
}
|
||||
|
||||
public final static int DICTIONARY_AUTO_LOAD_COOLDOWN_TIME = 120000; // ms
|
||||
public final static int DICTIONARY_IMPORT_BATCH_SIZE = 5000; // words
|
||||
public final static int DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME = 250; // ms
|
||||
public final static int DICTIONARY_CONFIRM_UPDATE_COOLDOWN_TIME = 120000; // ms
|
||||
public final static byte SLOW_QUERY_TIME = 50; // ms
|
||||
public final static int SOFT_KEY_REPEAT_DELAY = 40; // ms
|
||||
public final static float SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE = 0.55f;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ public class PopupDialogActivity extends AppCompatActivity {
|
|||
PopupDialog dialog = getDialog();
|
||||
if (dialog != null) {
|
||||
dialog.render();
|
||||
} else {
|
||||
onDialogClose("");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -47,9 +49,7 @@ public class PopupDialogActivity extends AppCompatActivity {
|
|||
|
||||
private void onDialogClose(String message) {
|
||||
finish();
|
||||
if (message != null && !message.isEmpty()) {
|
||||
sendMessageToMain(message);
|
||||
}
|
||||
sendMessageToMain(message);
|
||||
}
|
||||
|
||||
private void sendMessageToMain(String message) {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class UI {
|
|||
.setMessage(message)
|
||||
.setPositiveButton(OKLabel, (dialog, whichButton) -> { if (onOk != null) onOk.run(); })
|
||||
.setNegativeButton(android.R.string.cancel, (dialog, whichButton) -> { if (onCancel != null) onCancel.run(); })
|
||||
.setOnCancelListener(dialog -> { if (onCancel != null) onCancel.run(); })
|
||||
.setCancelable(false)
|
||||
.show();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class AddWordDialog extends PopupDialog {
|
|||
|
||||
public void render() {
|
||||
if (message == null || word == null || word.isEmpty()) {
|
||||
if (activityFinisher != null) activityFinisher.accept(null);
|
||||
if (activityFinisher != null) activityFinisher.accept("");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,10 +10,8 @@ import io.github.sspanak.tt9.R;
|
|||
import io.github.sspanak.tt9.db.DictionaryLoader;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.LanguageCollection;
|
||||
import io.github.sspanak.tt9.preferences.SettingsStore;
|
||||
|
||||
public class ConfirmDictionaryUpdateDialog extends PopupDialog {
|
||||
private static long lastDisplayTime = 0;
|
||||
private Language language;
|
||||
public ConfirmDictionaryUpdateDialog(@NonNull Context context, @NonNull Intent intent, ConsumerCompat<String> activityFinisher) {
|
||||
super(context, intent, activityFinisher);
|
||||
|
|
@ -30,16 +28,11 @@ public class ConfirmDictionaryUpdateDialog extends PopupDialog {
|
|||
|
||||
@Override
|
||||
public void render() {
|
||||
if (System.currentTimeMillis() - lastDisplayTime < SettingsStore.DICTIONARY_CONFIRM_UPDATE_COOLDOWN_TIME) {
|
||||
activityFinisher.accept(null);
|
||||
} else {
|
||||
super.render(this::loadDictionary);
|
||||
lastDisplayTime = System.currentTimeMillis();
|
||||
}
|
||||
super.render(this::loadDictionary);
|
||||
}
|
||||
|
||||
private void loadDictionary() {
|
||||
DictionaryLoader.load(context, language);
|
||||
activityFinisher.accept(null);
|
||||
activityFinisher.accept("");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,6 @@ abstract public class PopupDialog {
|
|||
abstract public void render();
|
||||
|
||||
protected void render(Runnable OKAction) {
|
||||
UI.confirm(context, title, message, OKLabel, OKAction, () -> activityFinisher.accept(null));
|
||||
UI.confirm(context, title, message, OKLabel, OKAction, () -> activityFinisher.accept(""));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue