From: Damyan Ivanov Date: Sat, 24 Apr 2021 16:17:10 +0000 (+0000) Subject: avoid switching current profile when profiles are rearranged X-Git-Tag: v0.18.0~30 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=cf5745a939dd043b6b144c416fd4e8257b2cac66;p=mobile-ledger.git avoid switching current profile when profiles are rearranged on rearrange the object instances change so the equality check needs to be done on IDs, not object instances --- 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 406d0d73..d9ac65b7 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 @@ -391,7 +391,16 @@ public class MainActivity extends ProfileThemedActivity implements FabManager.Fa createShortcuts(newList); Profile currentProfile = Data.getProfile(); - if (currentProfile == null || !newList.contains(currentProfile)) { + boolean currentProfilePresent = false; + if (currentProfile != null) { + for (Profile p : newList) { + if (p.getId() == currentProfile.getId()) { + currentProfilePresent = true; + break; + } + } + } + if (!currentProfilePresent) { Logger.debug(TAG, "Switching profile because the current is no longer available"); Data.setCurrentProfile(newList.get(0)); }