New Settings Screen more bugfixes
* proper error messages are displayed when dictionary loading fails or is cancelled * debounced the clicking on ItemClickable to avoid weird side effects, caused by faulty devices, sending multiple click events * a couple of French translations on the Settings screen * fixed Settings screen blinking in some cases * fixed default hotkey value cannot be 'no key' * fixed SuggestionsView having the incorrect theme forced at startup
This commit is contained in:
parent
a6fa129984
commit
bd73918f6a
17 changed files with 93 additions and 35 deletions
|
|
@ -106,14 +106,14 @@ public class DictionaryLoader {
|
|||
}
|
||||
|
||||
DictionaryDb.runInTransaction(() -> {
|
||||
long start = System.currentTimeMillis();
|
||||
importLetters(language);
|
||||
Logger.i(
|
||||
logTag,
|
||||
"Loaded letters for '" + language.getName() + "' language in: " + (System.currentTimeMillis() - start) + " ms"
|
||||
);
|
||||
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
importLetters(language);
|
||||
Logger.i(
|
||||
logTag,
|
||||
"Loaded letters for '" + language.getName() + "' language in: " + (System.currentTimeMillis() - start) + " ms"
|
||||
);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
importWords(language);
|
||||
Logger.i(
|
||||
|
|
@ -140,7 +140,7 @@ public class DictionaryLoader {
|
|||
+ " of language '" + language.getName() + "'. "
|
||||
+ e.getMessage()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
} catch (Exception | Error e) {
|
||||
stop();
|
||||
sendError(e.getClass().getSimpleName(), language.getId());
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,45 @@ package io.github.sspanak.tt9.preferences;
|
|||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import io.github.sspanak.tt9.Logger;
|
||||
|
||||
public abstract class ItemClickable {
|
||||
protected final int CLICK_DEBOUNCE_TIME = 250;
|
||||
private long lastClickTime = 0;
|
||||
|
||||
protected final Preference item;
|
||||
|
||||
|
||||
ItemClickable(Preference item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
public void enableClickHandler() {
|
||||
item.setOnPreferenceClickListener(this::onClick);
|
||||
item.setOnPreferenceClickListener(this::debounceClick);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* debounceClick
|
||||
* Protection against faulty devices, that sometimes send two (or more) click events
|
||||
* per a single key press.
|
||||
*
|
||||
* My smashed Qin F21 Pro+ occasionally does this, if I press the keys hard.
|
||||
* There were reports the same happens on Kyocera KYF31, causing absolutely undesirable side effects.
|
||||
* @see: https://github.com/sspanak/tt9/issues/117
|
||||
*/
|
||||
protected boolean debounceClick(Preference p) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastClickTime < CLICK_DEBOUNCE_TIME) {
|
||||
Logger.d("debounceClick", "Preference click debounced.");
|
||||
return true;
|
||||
}
|
||||
lastClickTime = now;
|
||||
|
||||
return onClick(p);
|
||||
}
|
||||
|
||||
|
||||
abstract protected boolean onClick(Preference p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,12 +51,14 @@ public class ItemLoadDictionary extends ItemClickable {
|
|||
progressBar.show(msg.getData());
|
||||
item.setSummary(progressBar.getTitle() + " " + progressBar.getMessage());
|
||||
|
||||
if (progressBar.isCompleted()) {
|
||||
if (progressBar.isCancelled()) {
|
||||
changeToLoadButton();
|
||||
UI.toast(context, R.string.dictionary_loaded);
|
||||
} else if (progressBar.isFailed()) {
|
||||
changeToLoadButton();
|
||||
UI.toast(context, R.string.dictionary_load_failed);
|
||||
UI.toast(context, progressBar.getMessage());
|
||||
} else if (progressBar.isCompleted()) {
|
||||
changeToLoadButton();
|
||||
UI.toast(context, R.string.dictionary_loaded);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -75,7 +77,7 @@ public class ItemLoadDictionary extends ItemClickable {
|
|||
changeToLoadButton();
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -86,6 +88,6 @@ public class ItemLoadDictionary extends ItemClickable {
|
|||
|
||||
public void changeToLoadButton() {
|
||||
item.setTitle(context.getString(R.string.dictionary_load_title));
|
||||
item.setSummary(progressBar.isFailed() ? progressBar.getMessage() : "");
|
||||
item.setSummary(progressBar.isFailed() || progressBar.isCancelled() ? progressBar.getMessage() : "");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,6 @@ public class ItemResetKeys extends ItemClickable {
|
|||
settings.setDefaultKeys();
|
||||
dropdowns.reloadSettings();
|
||||
UI.toast(context, R.string.function_reset_keys_done);
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,6 @@ public class ItemTruncateDictionary extends ItemClickable {
|
|||
|
||||
DictionaryDb.truncateWords(onDictionaryTruncated);
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ public class PreferencesActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
settings = new SettingsStore(this);
|
||||
DictionaryDb.init(this);
|
||||
|
||||
validateFunctionKeys();
|
||||
settings = new SettingsStore(this);
|
||||
applyTheme();
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
validateFunctionKeys();
|
||||
buildScreen();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,10 +100,8 @@ public class SectionKeymap {
|
|||
public void reloadSettings() {
|
||||
for (DropDownPreference dropDown : items) {
|
||||
int keypadKey = settings.getFunctionKey(dropDown.getKey());
|
||||
if (keypadKey != 0) {
|
||||
dropDown.setValue(String.valueOf(keypadKey));
|
||||
previewCurrentKey(dropDown);
|
||||
}
|
||||
dropDown.setValue(String.valueOf(keypadKey));
|
||||
previewCurrentKey(dropDown);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,9 @@ public class DictionaryLoadingBar {
|
|||
private final NotificationCompat.Builder notificationBuilder;
|
||||
private final Resources resources;
|
||||
|
||||
private boolean isStopped = false;
|
||||
private boolean hasFailed = false;
|
||||
|
||||
private int maxProgress = 0;
|
||||
private int progress = 0;
|
||||
private String title = "";
|
||||
|
|
@ -76,6 +78,11 @@ public class DictionaryLoadingBar {
|
|||
}
|
||||
|
||||
|
||||
public boolean isCancelled() {
|
||||
return isStopped;
|
||||
}
|
||||
|
||||
|
||||
public boolean isCompleted() {
|
||||
return progress >= maxProgress;
|
||||
}
|
||||
|
|
@ -126,16 +133,20 @@ public class DictionaryLoadingBar {
|
|||
return resources.getString(R.string.dictionary_loading, lang.getName());
|
||||
}
|
||||
|
||||
return resources.getString(R.string.dictionary_load_title);
|
||||
return resources.getString(R.string.dictionary_loading_indeterminate);
|
||||
}
|
||||
|
||||
|
||||
private void showProgress(long time, int currentFile, int currentFileProgress, int languageId) {
|
||||
if (currentFileProgress < 0) {
|
||||
hide();
|
||||
isStopped = true;
|
||||
title = "";
|
||||
message = resources.getString(R.string.dictionary_load_cancelled);
|
||||
return;
|
||||
}
|
||||
|
||||
isStopped = false;
|
||||
progress = 100 * currentFile + currentFileProgress;
|
||||
|
||||
if (progress >= maxProgress) {
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class SuggestionsView {
|
|||
);
|
||||
mView.setAdapter(mSuggestionsAdapter);
|
||||
|
||||
setDarkTheme(true); // just use some default colors
|
||||
setDarkTheme(settings.getDarkTheme());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue