X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionModel.java;h=7ff061a6ea30994bb15437d3297ee4683334f795;hp=fdcab48788b94f6336f41254298f92c02748e4c6;hb=5df10dc0b58df4d4be4e9ab34f1e0f477ca46766;hpb=7c71910950d18868e1f419eed5234f113ee51776 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java index fdcab487..7ff061a6 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java @@ -32,14 +32,15 @@ import androidx.lifecycle.ViewModel; import net.ktnx.mobileledger.BuildConfig; import net.ktnx.mobileledger.db.DB; +import net.ktnx.mobileledger.db.Profile; import net.ktnx.mobileledger.db.TemplateAccount; import net.ktnx.mobileledger.db.TemplateHeader; +import net.ktnx.mobileledger.db.TransactionWithAccounts; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.model.InertMutableLiveData; import net.ktnx.mobileledger.model.LedgerTransaction; import net.ktnx.mobileledger.model.LedgerTransactionAccount; import net.ktnx.mobileledger.model.MatchedTemplate; -import net.ktnx.mobileledger.model.MobileLedgerProfile; import net.ktnx.mobileledger.utils.Globals; import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.Misc; @@ -73,7 +74,7 @@ public class NewTransactionModel extends ViewModel { private final MutableLiveData simulateSave = new InertMutableLiveData<>(false); private final AtomicInteger busyCounter = new AtomicInteger(0); private final MutableLiveData busyFlag = new InertMutableLiveData<>(false); - private final Observer profileObserver = profile -> { + private final Observer profileObserver = profile -> { showCurrency.postValue(profile.getShowCommodityByDefault()); showComments.postValue(profile.getShowCommentsByDefault()); }; @@ -461,23 +462,19 @@ public class NewTransactionModel extends ViewModel { return tr; } - void loadTransactionIntoModel(long profileId, int transactionId) { + void loadTransactionIntoModel(@NonNull TransactionWithAccounts tr) { List newList = new ArrayList<>(); Item.resetIdDispenser(); - LedgerTransaction tr; - MobileLedgerProfile profile = Data.getProfile(profileId); - if (profile == null) - throw new RuntimeException(String.format( - "Unable to find profile %s, which is supposed to contain transaction %d", - profileId, transactionId)); - tr = profile.loadTransaction(transactionId); - TransactionHead head = new TransactionHead(tr.getDescription()); - head.setComment(tr.getComment()); + TransactionHead head = new TransactionHead(tr.transaction.getDescription()); + head.setComment(tr.transaction.getComment()); newList.add(head); - List accounts = tr.getAccounts(); + List accounts = new ArrayList<>(); + for (net.ktnx.mobileledger.db.TransactionAccount acc : tr.accounts) { + accounts.add(new LedgerTransactionAccount(acc)); + } TransactionAccount firstNegative = null; TransactionAccount firstPositive = null; @@ -526,9 +523,10 @@ public class NewTransactionModel extends ViewModel { moveItemLast(newList, singlePositiveIndex); } - setItems(newList); - - noteFocusChanged(1, FocusedElement.Amount); + new Handler(Looper.getMainLooper()).post(() -> { + setItems(newList); + noteFocusChanged(1, FocusedElement.Amount); + }); } /** * A transaction is submittable if: