From bc7510c72087c68d82c93dafac9269753c01875c Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 6 May 2021 20:34:16 +0300 Subject: [PATCH] update the current profile value when profile list has changed without this, Data.getProfile() returns a previous value that may not be current, e.g. the default currency have been changed --- .../ktnx/mobileledger/ui/activity/MainActivity.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 cb7cb46c..d5d0b710 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 @@ -392,20 +392,24 @@ public class MainActivity extends ProfileThemedActivity implements FabManager.Fa createShortcuts(newList); - Profile currentProfile = Data.getProfile(); - boolean currentProfilePresent = false; + final Profile currentProfile = Data.getProfile(); + Profile replacementProfile = null; if (currentProfile != null) { for (Profile p : newList) { if (p.getId() == currentProfile.getId()) { - currentProfilePresent = true; + replacementProfile = p; break; } } } - if (!currentProfilePresent) { + + if (replacementProfile == null) { Logger.debug(TAG, "Switching profile because the current is no longer available"); Data.setCurrentProfile(newList.get(0)); } + else { + Data.setCurrentProfile(replacementProfile); + } } /** * called when the current profile has changed -- 2.39.5