1
0
Fork 0

fixed the auto-update reminder being too aggressive

This commit is contained in:
sspanak 2024-02-20 15:36:11 +02:00 committed by Dimo Karaivanov
parent f6a788ee63
commit 2ec788ea64
8 changed files with 27 additions and 21 deletions

View file

@ -7,6 +7,7 @@ import android.os.Handler;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import io.github.sspanak.tt9.ConsumerCompat; import io.github.sspanak.tt9.ConsumerCompat;
@ -38,6 +39,7 @@ public class DictionaryLoader {
private ConsumerCompat<Bundle> onStatusChange; private ConsumerCompat<Bundle> onStatusChange;
private Thread loadThread; private Thread loadThread;
private final HashMap<Integer, Long> lastAutoLoadAttemptTime = new HashMap<>();
private int currentFile = 0; private int currentFile = 0;
private long importStartTime = 0; private long importStartTime = 0;
private long lastProgressUpdate = 0; private long lastProgressUpdate = 0;
@ -115,8 +117,16 @@ public class DictionaryLoader {
return; 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( WordStoreAsync.getLastLanguageUpdateTime(
(hash) -> { (hash) -> {
self.lastAutoLoadAttemptTime.put(language.getId(), System.currentTimeMillis());
// no words at all, load without confirmation // no words at all, load without confirmation
if (hash.isEmpty()) { if (hash.isEmpty()) {
load(context, language); load(context, language);

View file

@ -140,10 +140,12 @@ public class TraditionalT9 extends KeyPadHandler {
int result = super.onStartCommand(intent, flags, startId); int result = super.onStartCommand(intent, flags, startId);
String message = intent != null ? intent.getStringExtra(PopupDialogActivity.DIALOG_CLOSED_INTENT) : null; String message = intent != null ? intent.getStringExtra(PopupDialogActivity.DIALOG_CLOSED_INTENT) : null;
if (message != null && !message.isEmpty()) { if (message != null) {
forceShowWindowIfHidden(); forceShowWindowIfHidden();
if (!message.isEmpty()) {
UI.toastLong(self, message); UI.toastLong(self, message);
} }
}
return result; return result;
} }
@ -230,6 +232,9 @@ public class TraditionalT9 extends KeyPadHandler {
protected void onFinishTyping() { protected void onFinishTyping() {
cancelAutoAccept(); cancelAutoAccept();
if (!(mInputMode instanceof ModePredictive)) {
DictionaryLoader.autoLoad(this, mLanguage);
}
mInputMode = InputMode.getInstance(null, null, null, InputMode.MODE_PASSTHROUGH); mInputMode = InputMode.getInstance(null, null, null, InputMode.MODE_PASSTHROUGH);
} }
@ -239,8 +244,6 @@ public class TraditionalT9 extends KeyPadHandler {
clearSuggestions(); clearSuggestions();
statusBar.setText("--"); statusBar.setText("--");
DictionaryLoader.autoLoad(this, mLanguage);
normalizationHandler.removeCallbacksAndMessages(null); normalizationHandler.removeCallbacksAndMessages(null);
normalizationHandler.postDelayed( normalizationHandler.postDelayed(
() -> { if (!DictionaryLoader.getInstance(this).isRunning()) WordStoreAsync.normalizeNext(); }, () -> { 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. * are invisible. This function forces the InputMethodManager to show our window.
*/ */
protected void forceShowWindowIfHidden() { protected void forceShowWindowIfHidden() {
if (mInputMode.isPassthrough() || isInputViewShown()) { if (getInputMode().isPassthrough() || isInputViewShown()) {
return; return;
} }

View file

@ -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_BATCH_SIZE = 5000; // words
public final static int DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME = 250; // ms 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 byte SLOW_QUERY_TIME = 50; // ms
public final static int SOFT_KEY_REPEAT_DELAY = 40; // ms public final static int SOFT_KEY_REPEAT_DELAY = 40; // ms
public final static float SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE = 0.55f; public final static float SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE = 0.55f;

View file

@ -24,6 +24,8 @@ public class PopupDialogActivity extends AppCompatActivity {
PopupDialog dialog = getDialog(); PopupDialog dialog = getDialog();
if (dialog != null) { if (dialog != null) {
dialog.render(); dialog.render();
} else {
onDialogClose("");
} }
} }
@ -47,10 +49,8 @@ public class PopupDialogActivity extends AppCompatActivity {
private void onDialogClose(String message) { private void onDialogClose(String message) {
finish(); finish();
if (message != null && !message.isEmpty()) {
sendMessageToMain(message); sendMessageToMain(message);
} }
}
private void sendMessageToMain(String message) { private void sendMessageToMain(String message) {
Intent intent = new Intent(this, TraditionalT9.class); Intent intent = new Intent(this, TraditionalT9.class);

View file

@ -60,7 +60,7 @@ public class UI {
.setMessage(message) .setMessage(message)
.setPositiveButton(OKLabel, (dialog, whichButton) -> { if (onOk != null) onOk.run(); }) .setPositiveButton(OKLabel, (dialog, whichButton) -> { if (onOk != null) onOk.run(); })
.setNegativeButton(android.R.string.cancel, (dialog, whichButton) -> { if (onCancel != null) onCancel.run(); }) .setNegativeButton(android.R.string.cancel, (dialog, whichButton) -> { if (onCancel != null) onCancel.run(); })
.setOnCancelListener(dialog -> { if (onCancel != null) onCancel.run(); }) .setCancelable(false)
.show(); .show();
} }

View file

@ -42,7 +42,7 @@ public class AddWordDialog extends PopupDialog {
public void render() { public void render() {
if (message == null || word == null || word.isEmpty()) { if (message == null || word == null || word.isEmpty()) {
if (activityFinisher != null) activityFinisher.accept(null); if (activityFinisher != null) activityFinisher.accept("");
return; return;
} }

View file

@ -10,10 +10,8 @@ import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.db.DictionaryLoader; import io.github.sspanak.tt9.db.DictionaryLoader;
import io.github.sspanak.tt9.languages.Language; import io.github.sspanak.tt9.languages.Language;
import io.github.sspanak.tt9.languages.LanguageCollection; import io.github.sspanak.tt9.languages.LanguageCollection;
import io.github.sspanak.tt9.preferences.SettingsStore;
public class ConfirmDictionaryUpdateDialog extends PopupDialog { public class ConfirmDictionaryUpdateDialog extends PopupDialog {
private static long lastDisplayTime = 0;
private Language language; private Language language;
public ConfirmDictionaryUpdateDialog(@NonNull Context context, @NonNull Intent intent, ConsumerCompat<String> activityFinisher) { public ConfirmDictionaryUpdateDialog(@NonNull Context context, @NonNull Intent intent, ConsumerCompat<String> activityFinisher) {
super(context, intent, activityFinisher); super(context, intent, activityFinisher);
@ -30,16 +28,11 @@ public class ConfirmDictionaryUpdateDialog extends PopupDialog {
@Override @Override
public void render() { public void render() {
if (System.currentTimeMillis() - lastDisplayTime < SettingsStore.DICTIONARY_CONFIRM_UPDATE_COOLDOWN_TIME) {
activityFinisher.accept(null);
} else {
super.render(this::loadDictionary); super.render(this::loadDictionary);
lastDisplayTime = System.currentTimeMillis();
}
} }
private void loadDictionary() { private void loadDictionary() {
DictionaryLoader.load(context, language); DictionaryLoader.load(context, language);
activityFinisher.accept(null); activityFinisher.accept("");
} }
} }

View file

@ -25,6 +25,6 @@ abstract public class PopupDialog {
abstract public void render(); abstract public void render();
protected void render(Runnable OKAction) { protected void render(Runnable OKAction) {
UI.confirm(context, title, message, OKLabel, OKAction, () -> activityFinisher.accept(null)); UI.confirm(context, title, message, OKLabel, OKAction, () -> activityFinisher.accept(""));
} }
} }