/*
- * 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;
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();
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)) {