]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java
store a weak reference to the profile in the account object
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / LedgerAccount.java
index 7510576a81a65fdd31792158514f40c474f8c8ef..3bc01d1fecd852cc957aeb205640465dec80320f 100644 (file)
@@ -20,6 +20,7 @@ package net.ktnx.mobileledger.model;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
+import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.regex.Matcher;
@@ -36,17 +37,23 @@ public class LedgerAccount {
     private List<LedgerAmount> amounts;
     private boolean hasSubAccounts;
     private boolean amountsExpanded;
+    private WeakReference<MobileLedgerProfile> profileWeakReference;
 
-    public LedgerAccount(String name) {
+    public LedgerAccount(MobileLedgerProfile profile, String name) {
+        this.profileWeakReference = new WeakReference<>(profile);
         this.setName(name);
     }
 
-    public LedgerAccount(String name, float amount) {
+    public LedgerAccount(MobileLedgerProfile profile, String name, float amount) {
+        this.profileWeakReference = new WeakReference<>(profile);
         this.setName(name);
         this.expanded = true;
         this.amounts = new ArrayList<LedgerAmount>();
         this.addAmount(amount);
     }
+    public @Nullable MobileLedgerProfile getProfile() {
+        return profileWeakReference.get();
+    }
     @Override
     public int hashCode() {
         return name.hashCode();