From: Damyan Ivanov Date: Sun, 5 Jan 2020 15:37:30 +0000 (+0200) Subject: add UI and API support for sending posting (transaction account) comments X-Git-Tag: v0.12.0~109 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=7ae5407090d9ffe2026775ba9e569014f879b54d;p=mobile-ledger.git add UI and API support for sending posting (transaction account) comments --- diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java index 21cc6dbf..f1a6e1ff 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java @@ -42,6 +42,12 @@ public class ParsedPosting { public static ParsedPosting fromLedgerAccount(LedgerTransactionAccount acc) { ParsedPosting result = new ParsedPosting(); result.setPaccount(acc.getAccountName()); + + String comment = acc.getComment(); + if (comment == null) + comment = ""; + result.setPcomment(comment); + ArrayList amounts = new ArrayList<>(); ParsedAmount amt = new ParsedAmount(); amt.setAcommodity((acc.getCurrency() == null) ? "" : acc.getCurrency()); diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java index 7c20a7ba..0789f0d9 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java @@ -113,6 +113,12 @@ public class ParsedPosting { public static ParsedPosting fromLedgerAccount(LedgerTransactionAccount acc) { ParsedPosting result = new ParsedPosting(); result.setPaccount(acc.getAccountName()); + + String comment = acc.getComment(); + if (comment == null) + comment = ""; + result.setPcomment(comment); + ArrayList amounts = new ArrayList<>(); ParsedAmount amt = new ParsedAmount(); amt.setAcommodity((acc.getCurrency() == null) ? "" : acc.getCurrency()); diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java index 89d6a83a..4a83b185 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java @@ -25,7 +25,7 @@ public class LedgerTransactionAccount { private float amount; private boolean amountSet = false; private String currency; - + private String comment; public LedgerTransactionAccount(String accountName, float amount) { this(accountName, amount, null); } @@ -35,18 +35,23 @@ public class LedgerTransactionAccount { this.amountSet = true; this.currency = currency; } - public LedgerTransactionAccount(String accountName) { this.accountName = accountName; } public LedgerTransactionAccount(LedgerTransactionAccount origin) { // copy constructor setAccountName(origin.getAccountName()); + setComment(origin.getComment()); if (origin.isAmountSet()) setAmount(origin.getAmount()); currency = origin.getCurrency(); } - + public String getComment() { + return comment; + } + public void setComment(String comment) { + this.comment = comment; + } public String getAccountName() { return accountName; } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java index e4d1d503..6988fe4f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java @@ -51,6 +51,8 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; +import static net.ktnx.mobileledger.ui.activity.NewTransactionModel.ItemType; + class NewTransactionItemHolder extends RecyclerView.ViewHolder implements DatePickerFragment.DatePickedListener, DescriptionSelectedCallback { private final String decimalSeparator; @@ -59,6 +61,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private TextView tvDate; private AutoCompleteTextView tvDescription; private AutoCompleteTextView tvAccount; + private TextView tvComment; private TextView tvAmount; private LinearLayout lHead; private ViewGroup lAccount; @@ -76,6 +79,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder NewTransactionItemHolder(@NonNull View itemView, NewTransactionItemsAdapter adapter) { super(itemView); tvAccount = itemView.findViewById(R.id.account_row_acc_name); + tvComment = itemView.findViewById(R.id.comment); tvAmount = itemView.findViewById(R.id.account_row_acc_amounts); tvDate = itemView.findViewById(R.id.new_transaction_date); tvDescription = itemView.findViewById(R.id.new_transaction_description); @@ -100,11 +104,16 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder try { final int pos = getAdapterPosition(); adapter.updateFocusedItem(pos); - if (v instanceof AutoCompleteTextViewWithClear) { - adapter.noteFocusIsOnAccount(pos); - } - else { - adapter.noteFocusIsOnAmount(pos); + switch (v.getId()) { + case R.id.account_row_acc_name: + adapter.noteFocusIsOnAccount(pos); + break; + case R.id.account_row_acc_amounts: + adapter.noteFocusIsOnAmount(pos); + break; + case R.id.comment: + adapter.noteFocusIsOnComment(pos); + break; } } finally { @@ -180,6 +189,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder }; tvDescription.addTextChangedListener(tw); tvAccount.addTextChangedListener(tw); + tvComment.addTextChangedListener(tw); tvAmount.addTextChangedListener(amountWatcher); // FIXME: react on locale changes @@ -242,15 +252,20 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder case transactionRow: // do nothing if a row element already has the focus if (!itemView.hasFocus()) { - if (item.focusIsOnAmount()) { - tvAmount.requestFocus(); - } - else { - focused = tvAccount.requestFocus(); - tvAccount.dismissDropDown(); - if (focused) - Misc.showSoftKeyboard( - (NewTransactionActivity) tvAccount.getContext()); + switch (item.getFocusedElement()) { + case Amount: + tvAmount.requestFocus(); + break; + case Comment: + tvComment.requestFocus(); + break; + case Account: + focused = tvAccount.requestFocus(); + tvAccount.dismissDropDown(); + if (focused) + Misc.showSoftKeyboard( + (NewTransactionActivity) tvAccount.getContext()); + break; } } @@ -266,7 +281,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder adapterPosition, layoutPosition, item.getType() .toString() .concat(item.getType() == - NewTransactionModel.ItemType.transactionRow + ItemType.transactionRow ? String.format(Locale.US, "'%s'=%s", item.getAccount() @@ -323,29 +338,28 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder item.setDescription(String.valueOf(tvDescription.getText())); break; case transactionRow: - item.getAccount() - .setAccountName(String.valueOf(tvAccount.getText())); + final LedgerTransactionAccount account = item.getAccount(); + account.setAccountName(String.valueOf(tvAccount.getText())); + + account.setComment(String.valueOf(tvComment.getText())); // TODO: handle multiple amounts String amount = String.valueOf(tvAmount.getText()); amount = amount.trim(); if (amount.isEmpty()) { - item.getAccount() - .resetAmount(); + account.resetAmount(); } else { try { amount = amount.replace(decimalSeparator, decimalDot); - item.getAccount() - .setAmount(Float.parseFloat(amount)); + account.setAmount(Float.parseFloat(amount)); } catch (NumberFormatException e) { Logger.debug("new-trans", String.format( "assuming amount is not set due to number format exception. " + "input was '%s'", amount)); - item.getAccount() - .resetAmount(); + account.resetAmount(); } } @@ -399,6 +413,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder case transactionRow: LedgerTransactionAccount acc = item.getAccount(); tvAccount.setText(acc.getAccountName()); + tvComment.setText(acc.getComment()); if (acc.isAmountSet()) { tvAmount.setText(String.format("%1.2f", acc.getAmount())); } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java index 88f99a20..2cf972f8 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java @@ -287,9 +287,12 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter date = new MutableLiveData<>(); private MutableLiveData description = new MutableLiveData<>(); @@ -314,7 +314,7 @@ public class NewTransactionModel extends ViewModel { private MutableLiveData amountHint = new MutableLiveData<>(null); private NewTransactionModel model; private MutableLiveData editable = new MutableLiveData<>(true); - private boolean focusIsOnAmount = false; + private FocusedElement focusedElement = FocusedElement.Account; public Item(NewTransactionModel model) { this.model = model; type = ItemType.bottomFiller; @@ -333,8 +333,11 @@ public class NewTransactionModel extends ViewModel { this.account = account; this.editable.setValue(true); } - public boolean focusIsOnAmount() { - return focusIsOnAmount; + public FocusedElement getFocusedElement() { + return focusedElement; + } + public void setFocusedElement(FocusedElement focusedElement) { + this.focusedElement = focusedElement; } public NewTransactionModel getModel() { return model; @@ -503,8 +506,5 @@ public class NewTransactionModel extends ViewModel { public void stopObservingEditableFlag(Observer observer) { editable.removeObserver(observer); } - public void setFocusIsOnAmount(boolean flag) { - focusIsOnAmount = flag; - } } } diff --git a/app/src/main/res/drawable-anydpi-v21/ic_comment_black_24dp.xml b/app/src/main/res/drawable-anydpi-v21/ic_comment_black_24dp.xml new file mode 100644 index 00000000..60588c11 --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v21/ic_comment_black_24dp.xml @@ -0,0 +1,29 @@ + + + + + diff --git a/app/src/main/res/layout/new_transaction_row.xml b/app/src/main/res/layout/new_transaction_row.xml index 9210b298..508eea98 100644 --- a/app/src/main/res/layout/new_transaction_row.xml +++ b/app/src/main/res/layout/new_transaction_row.xml @@ -78,8 +78,7 @@ + android:layout_height="wrap_content"> - + + + + + + + Version 1.15 and above Detect automaticaly Backend server version + comment