]> 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 a762e3a9dba1d8a3dc295d605b3ee73bb56fbec7..3bc01d1fecd852cc957aeb205640465dec80320f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
 
 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;
 import java.util.regex.Pattern;
 
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
 public class LedgerAccount {
     static Pattern reHigherAccount = Pattern.compile("^[^:]+:");
     private String name;
@@ -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();