reduced the button status updates on the Languages screen for more responsive navigation
This commit is contained in:
parent
f7e11c7445
commit
7864c24850
7 changed files with 28 additions and 31 deletions
|
|
@ -20,9 +20,8 @@ abstract public class ItemProcessCustomWordsAbstract extends ItemClickable {
|
|||
|
||||
AbstractFileProcessor processor = getProcessor();
|
||||
processor.setFailureHandler(() -> onFinishProcessing(null));
|
||||
processor.setStartHandler(() -> activity.runOnUiThread(this::setLoadingStatus));
|
||||
processor.setStartHandler(() -> activity.runOnUiThread(this::setBusy));
|
||||
processor.setSuccessHandler(this::onFinishProcessing);
|
||||
refreshStatus();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -32,9 +31,9 @@ abstract public class ItemProcessCustomWordsAbstract extends ItemClickable {
|
|||
public ItemProcessCustomWordsAbstract refreshStatus() {
|
||||
if (item != null) {
|
||||
if (getProcessor().isRunning()) {
|
||||
setLoadingStatus();
|
||||
setBusy();
|
||||
} else {
|
||||
setReadyStatus();
|
||||
enable();
|
||||
}
|
||||
}
|
||||
return this;
|
||||
|
|
@ -43,9 +42,9 @@ abstract public class ItemProcessCustomWordsAbstract extends ItemClickable {
|
|||
|
||||
@Override
|
||||
protected boolean onClick(Preference p) {
|
||||
setLoadingStatus();
|
||||
setBusy();
|
||||
if (!onStartProcessing()) {
|
||||
setReadyStatus();
|
||||
setAndNotifyReady();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -56,7 +55,7 @@ abstract public class ItemProcessCustomWordsAbstract extends ItemClickable {
|
|||
|
||||
protected void onFinishProcessing(String fileName) {
|
||||
activity.runOnUiThread(() -> {
|
||||
setReadyStatus();
|
||||
setAndNotifyReady();
|
||||
|
||||
if (fileName == null) {
|
||||
DictionaryProgressNotification.getInstance(activity).showError(
|
||||
|
|
@ -80,7 +79,7 @@ abstract public class ItemProcessCustomWordsAbstract extends ItemClickable {
|
|||
abstract protected String getSuccessTitle();
|
||||
|
||||
|
||||
protected void setLoadingStatus() {
|
||||
protected void setBusy() {
|
||||
if (onStart != null) onStart.run();
|
||||
disable();
|
||||
|
||||
|
|
@ -89,8 +88,7 @@ abstract public class ItemProcessCustomWordsAbstract extends ItemClickable {
|
|||
DictionaryProgressNotification.getInstance(activity).showLoadingMessage(loadingMessage, "");
|
||||
}
|
||||
|
||||
|
||||
public void setReadyStatus() {
|
||||
protected void setAndNotifyReady() {
|
||||
enable();
|
||||
if (onFinish != null) onFinish.run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class ItemExportLogcat extends ItemExportAbstract {
|
|||
protected void onFinishProcessing(String outputFile) {
|
||||
activity.runOnUiThread(() -> {
|
||||
DictionaryProgressNotification.getInstance(activity).hide();
|
||||
setReadyStatus();
|
||||
setAndNotifyReady();
|
||||
|
||||
if (outputFile == null) {
|
||||
item.setSummary("Export failed");
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ class ItemExportCustomWords extends ItemExportAbstract {
|
|||
return CustomWordsExporter.getInstance().run(activity);
|
||||
}
|
||||
|
||||
public void setReadyStatus() {
|
||||
super.setReadyStatus();
|
||||
public void enable() {
|
||||
super.enable();
|
||||
item.setSummary(activity.getString(
|
||||
R.string.dictionary_export_custom_words_summary,
|
||||
CustomWordsExporter.getInstance().getOutputDir()
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ class ItemExportDictionary extends ItemExportAbstract {
|
|||
.run(activity);
|
||||
}
|
||||
|
||||
public void setReadyStatus() {
|
||||
super.setReadyStatus();
|
||||
public void enable() {
|
||||
super.enable();
|
||||
item.setSummary("");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,9 +82,9 @@ public class ItemImportCustomWords extends ItemProcessCustomWordsAbstract {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setReadyStatus() {
|
||||
public void enable() {
|
||||
item.setSummary(R.string.dictionary_import_custom_words_summary);
|
||||
super.setReadyStatus();
|
||||
super.enable();
|
||||
}
|
||||
|
||||
void setBrowseFilesLauncher(ActivityResultLauncher<Intent> launcher) {
|
||||
|
|
|
|||
|
|
@ -35,16 +35,14 @@ class ItemLoadDictionary extends ItemClickable {
|
|||
this.progressBar = DictionaryLoadingBar.getInstance(context);
|
||||
this.onStart = onStart;
|
||||
this.onFinish = onFinish;
|
||||
|
||||
refreshStatus();
|
||||
}
|
||||
|
||||
|
||||
public void refreshStatus() {
|
||||
if (loader.isRunning()) {
|
||||
setLoadingStatus();
|
||||
setBusy();
|
||||
} else {
|
||||
setReadyStatus();
|
||||
setReady();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,12 +52,15 @@ class ItemLoadDictionary extends ItemClickable {
|
|||
item.setSummary(progressBar.getTitle() + " " + progressBar.getMessage());
|
||||
|
||||
if (progressBar.isCancelled()) {
|
||||
setReadyStatus();
|
||||
setReady();
|
||||
onFinish.run();
|
||||
} else if (progressBar.isFailed()) {
|
||||
setReadyStatus();
|
||||
setReady();
|
||||
onFinish.run();
|
||||
UI.toastFromAsync(activity, progressBar.getMessage());
|
||||
} else if (!progressBar.inProgress()) {
|
||||
setReadyStatus();
|
||||
setReady();
|
||||
onFinish.run();
|
||||
UI.toastFromAsync(activity, R.string.dictionary_loaded);
|
||||
}
|
||||
}
|
||||
|
|
@ -69,25 +70,25 @@ class ItemLoadDictionary extends ItemClickable {
|
|||
protected boolean onClick(Preference p) {
|
||||
ArrayList<Language> languages = LanguageCollection.getAll(activity.getSettings().getEnabledLanguageIds());
|
||||
|
||||
setLoadingStatus();
|
||||
setBusy();
|
||||
if (!loader.load(activity, languages)) {
|
||||
loader.stop();
|
||||
setReadyStatus();
|
||||
setReady();
|
||||
onFinish.run();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void setLoadingStatus() {
|
||||
private void setBusy() {
|
||||
loader.setOnStatusChange(this::onLoadingStatusChange);
|
||||
onStart.run();
|
||||
item.setTitle(activity.getString(R.string.dictionary_cancel_load));
|
||||
}
|
||||
|
||||
|
||||
private void setReadyStatus() {
|
||||
onFinish.run();
|
||||
private void setReady() {
|
||||
item.setTitle(activity.getString(R.string.dictionary_load_title));
|
||||
item.setSummary(progressBar.isFailed() || progressBar.isCancelled() ? progressBar.getMessage() : "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ class ItemTruncateAll extends ItemClickable {
|
|||
this.deleter = DictionaryDeleter.getInstance(activity);
|
||||
this.onStart = onStart;
|
||||
this.onFinish = onFinish;
|
||||
|
||||
refreshStatus();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue