]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix profile list not updating tag colour after saving profile changes
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 24 Sep 2020 16:16:07 +0000 (16:16 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 24 Sep 2020 16:16:07 +0000 (16:16 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java

index b712f29da87ca248bbd6923e7407740e5b9db1a8..72c4ed4cdab47fb56448a70ec3f2dc1a1262895f 100644 (file)
@@ -417,22 +417,35 @@ public class ProfileDetailFragment extends Fragment {
             return;
 
         ProfileDetailModel model = getModel();
+        final ArrayList<MobileLedgerProfile> profiles =
+                Objects.requireNonNull(Data.profiles.getValue());
 
         if (mProfile != null) {
+            int pos = Data.profiles.getValue()
+                                   .indexOf(mProfile);
+            mProfile = new MobileLedgerProfile(mProfile);
             model.updateProfile(mProfile);
-//                debug("profiles", String.format("Selected item is %d", mProfile.getThemeHue()));
             mProfile.storeInDB();
             debug("profiles", "profile stored in DB");
-            triggerProfileChange();
+            profiles.set(pos, mProfile);
+//                debug("profiles", String.format("Selected item is %d", mProfile.getThemeHue()));
+
+            final MobileLedgerProfile currentProfile = Data.getProfile();
+            if (mProfile.getUuid()
+                        .equals(currentProfile.getUuid()))
+            {
+                Data.setCurrentProfile(mProfile);
+            }
+
+            ProfilesRecyclerViewAdapter viewAdapter = ProfilesRecyclerViewAdapter.getInstance();
+            if (viewAdapter != null)
+                viewAdapter.notifyItemChanged(pos);
         }
         else {
             mProfile = new MobileLedgerProfile(String.valueOf(UUID.randomUUID()));
             model.updateProfile(mProfile);
             mProfile.storeInDB();
-            final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
-            if (profiles == null)
-                throw new AssertionError();
-            ArrayList<MobileLedgerProfile> newList = new ArrayList<>(profiles);
+            final ArrayList<MobileLedgerProfile> newList = new ArrayList<>(profiles);
             newList.add(mProfile);
             Data.profiles.setValue(newList);
             MobileLedgerProfile.storeProfilesOrder();