prevAccount = lastAccount;
lastAccount = profile.tryLoadAccount(db, acct_name);
if (lastAccount == null)
- lastAccount = new LedgerAccount(acct_name);
+ lastAccount = new LedgerAccount(profile, acct_name);
else
lastAccount.removeAmounts();
profile.storeAccount(db, lastAccount);
if (accountNames.containsKey(parentName))
break;
toAppend.push(parentName);
- parentName = new LedgerAccount(parentName).getParentName();
+ parentName = new LedgerAccount(profile, parentName).getParentName();
}
syntheticAccounts.clear();
while (!toAppend.isEmpty()) {
String aName = toAppend.pop();
LedgerAccount acc = profile.tryLoadAccount(db, aName);
if (acc == null) {
- acc = new LedgerAccount(aName);
+ acc = new LedgerAccount(profile, aName);
acc.setExpanded(!lastAccount.hasSubAccounts() ||
lastAccount.isExpanded());
}
LedgerAccount acc = profile.tryLoadAccount(db, parsedAccount.getAname());
if (acc == null)
- acc = new LedgerAccount(parsedAccount.getAname());
+ acc = new LedgerAccount(profile, parsedAccount.getAname());
else
acc.removeAmounts();
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;
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();
new String[]{uuid, accName}))
{
if (cursor.moveToFirst()) {
- LedgerAccount acc = new LedgerAccount(accName);
+ LedgerAccount acc = new LedgerAccount(this, accName);
acc.setExpanded(cursor.getInt(0) == 1);
acc.setHasSubAccounts(cursor.getInt(1) == 1);