From b033938cc547329fd4bab5b15304a099b10360e0 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Tue, 20 Apr 2021 22:46:46 +0300 Subject: [PATCH] wipe retrieval progress when transaction retrieval is stopped fixes a glitch when a retrieval error suggests changing profile configuration, and from there the profile is deleted and activity restarted because of the change of the active profile. the new activity instance observes the retrieval result and gets the error and reports it erroneously --- app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java | 2 ++ .../net/ktnx/mobileledger/ui/activity/MainActivity.java | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java index c860e41b..06f94ee3 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java @@ -113,6 +113,8 @@ public class MainModel extends ViewModel { public synchronized void stopTransactionsRetrieval() { if (retrieveTransactionsTask != null) retrieveTransactionsTask.cancel(true); + else + Data.backgroundTaskProgress.setValue(null); } public void transactionRetrievalDone() { retrieveTransactionsTask = null; diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 7df18278..c917bb9e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -615,14 +615,16 @@ public class MainActivity extends ProfileThemedActivity implements FabManager.Fa b.transactionProgressLayout.setVisibility(View.GONE); } } - public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) { - if (progress.getState() == RetrieveTransactionsTask.ProgressState.FINISHED) { + public void onRetrieveProgress(@Nullable RetrieveTransactionsTask.Progress progress) { + if (progress == null || + progress.getState() == RetrieveTransactionsTask.ProgressState.FINISHED) + { Logger.debug("progress", "Done"); b.transactionProgressLayout.setVisibility(View.GONE); mainModel.transactionRetrievalDone(); - String error = progress.getError(); + String error = (progress == null) ? null : progress.getError(); if (error != null) { if (error.equals(RetrieveTransactionsTask.Result.ERR_JSON_PARSER_ERROR)) error = getResources().getString(R.string.err_json_parser_error); -- 2.39.2