]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java
more asynchronous account list (re-)loading
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / LedgerAccount.java
index a762e3a9dba1d8a3dc295d605b3ee73bb56fbec7..11c1a16bfa097febf4361fb5c1e294cc4647269d 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();
@@ -59,13 +66,7 @@ public class LedgerAccount {
                name.equals(((LedgerAccount) obj).getName());
     }
     // an account is visible if:
-    //  - it is starred (not hidden by a star)
-    //  - and it has an expanded parent or is a top account
-    public boolean isVisible() {
-        if (level == 0) return true;
-
-        return isVisible(Data.accounts);
-    }
+    //  - it has an expanded parent or is a top account
     public boolean isVisible(List<LedgerAccount> list) {
         for (LedgerAccount acc : list) {
             if (acc.isParentOf(this)) {