fixed the dictionary loading progress notification not disappearing or showing -0.0 seconds, when loading is cancelled
This commit is contained in:
parent
c8c484a570
commit
547b18a56f
3 changed files with 17 additions and 7 deletions
|
|
@ -98,6 +98,7 @@ public class DictionaryLoader {
|
|||
// SQLite does not support parallel queries, so let's import them one by one
|
||||
for (Language lang : languages) {
|
||||
if (loadThread.isInterrupted()) {
|
||||
sendProgressMessage(lang, 0, 0);
|
||||
break;
|
||||
}
|
||||
importAll(context, lang);
|
||||
|
|
|
|||
|
|
@ -30,9 +30,11 @@ class ItemLoadDictionary extends ItemClickable {
|
|||
ItemLoadDictionary(Preference item, PreferencesActivity context, Runnable onStart, Runnable onFinish) {
|
||||
super(item);
|
||||
|
||||
loader = DictionaryLoader.getInstance(context);
|
||||
progressBar = DictionaryLoadingBar.getInstance(context);
|
||||
loader.setOnStatusChange(progressBar::show);
|
||||
|
||||
this.activity = context;
|
||||
this.loader = DictionaryLoader.getInstance(context);
|
||||
this.progressBar = DictionaryLoadingBar.getInstance(context);
|
||||
this.onStart = onStart;
|
||||
this.onFinish = onFinish;
|
||||
}
|
||||
|
|
@ -47,8 +49,7 @@ class ItemLoadDictionary extends ItemClickable {
|
|||
}
|
||||
|
||||
|
||||
private void onLoadingStatusChange(Bundle status) {
|
||||
progressBar.show(status);
|
||||
private void onLoadingStatusChange() {
|
||||
item.setSummary(progressBar.getTitle() + " " + progressBar.getMessage());
|
||||
|
||||
if (progressBar.isCancelled()) {
|
||||
|
|
@ -82,14 +83,14 @@ class ItemLoadDictionary extends ItemClickable {
|
|||
|
||||
|
||||
private void setBusy() {
|
||||
loader.setOnStatusChange(this::onLoadingStatusChange);
|
||||
progressBar.setOnStatusChange(this::onLoadingStatusChange);
|
||||
onStart.run();
|
||||
item.setTitle(activity.getString(R.string.dictionary_cancel_load));
|
||||
}
|
||||
|
||||
|
||||
private void setReady() {
|
||||
loader.setOnStatusChange(null);
|
||||
progressBar.setOnStatusChange(null);
|
||||
item.setTitle(activity.getString(R.string.dictionary_load_title));
|
||||
item.setSummary(progressBar.isFailed() || progressBar.isCancelled() ? progressBar.getMessage() : "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ import io.github.sspanak.tt9.languages.exceptions.InvalidLanguageException;
|
|||
public class DictionaryLoadingBar extends DictionaryProgressNotification {
|
||||
private static DictionaryLoadingBar self;
|
||||
|
||||
|
||||
private boolean isStopped = false;
|
||||
private boolean hasFailed = false;
|
||||
private Runnable onStatusChange = null;
|
||||
|
||||
|
||||
public static DictionaryLoadingBar getInstance(Context context) {
|
||||
|
|
@ -54,6 +54,11 @@ public class DictionaryLoadingBar extends DictionaryProgressNotification {
|
|||
}
|
||||
|
||||
|
||||
public void setOnStatusChange(Runnable onStatusChange) {
|
||||
this.onStatusChange = onStatusChange;
|
||||
}
|
||||
|
||||
|
||||
public boolean isCancelled() {
|
||||
return isStopped;
|
||||
}
|
||||
|
|
@ -76,6 +81,7 @@ public class DictionaryLoadingBar extends DictionaryProgressNotification {
|
|||
data.getInt("languageId", -1),
|
||||
data.getLong("fileLine", -1)
|
||||
);
|
||||
if (onStatusChange != null) onStatusChange.run();
|
||||
} else if (progress >= 0) {
|
||||
hasFailed = false;
|
||||
if (fileCount >= 0) {
|
||||
|
|
@ -88,6 +94,8 @@ public class DictionaryLoadingBar extends DictionaryProgressNotification {
|
|||
data.getInt("progress", 0),
|
||||
data.getInt("languageId", -1)
|
||||
);
|
||||
|
||||
if (onStatusChange != null) onStatusChange.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue