]> git.ktnx.net Git - mobile-ledger.git/commitdiff
update the current profile value when profile list has changed
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 6 May 2021 17:34:16 +0000 (20:34 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 6 May 2021 17:34:16 +0000 (20:34 +0300)
without this, Data.getProfile() returns a previous value that may not be
current, e.g. the default currency have been changed

app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java

index cb7cb46c520ea173da9bbd15c71a4bcf9e88d5e0..d5d0b71005b4cc48818fb55e0ddc8a521fc1969d 100644 (file)
@@ -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