From 8f1767e84a0309469885f85e43e5d20f8c01652c Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Sun, 14 Jun 2020 12:14:29 +0200 Subject: [PATCH] #876 - ** Add shallDisplayZero in displayBalance(...) to avoid displaying 0 --- .../gnucash/android/model/AccountType.java | 30 +++++++++++++++---- .../TransactionDetailActivity.java | 2 ++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/model/AccountType.java b/app/src/main/java/org/gnucash/android/model/AccountType.java index 82c2503fe..0738bc9f6 100644 --- a/app/src/main/java/org/gnucash/android/model/AccountType.java +++ b/app/src/main/java/org/gnucash/android/model/AccountType.java @@ -117,10 +117,16 @@ public TransactionType getDefaultTransactionType() { * * @param balanceTextView {@link android.widget.TextView} where balance is to be displayed * @param balance {@link org.gnucash.android.model.Money} balance (>0 or <0) to display + * @param shallDisplayNegativeSignum if true will display Negative signum (often bind to Preference R.string.key_display_negative_signum_in_splits + * @param shallDisplayZero if true will display 0, else will display nothing (usefull when first creation of a Transaction) + * @param shallDisplayCurrency if true will display Currency as well as amount (usefull when displaying balance in + * TransactionListFragment, BalanceSheetFragment...) + * else will not display Currency (usefull in SplitEditorFragment or TransactionFormFragment) */ public void displayBalance(final TextView balanceTextView, final Money balance, final boolean shallDisplayNegativeSignum, + final boolean shallDisplayZero, final boolean shallDisplayCurrency) { // @@ -141,11 +147,23 @@ public void displayBalance(final TextView balanceTextView, } else { // Shall not display currency - // Display value without currency and without decimals - balanceTextView.setText(!shallDisplayNegativeSignum - ? balanceToDisplay.abs() - .toShortString() - : balanceToDisplay.toShortString()); + // Shall display value in all other cases than zero balance and shall not display zero balance + final boolean shallDisplayValue = !(balanceToDisplay.isAmountZero() && !shallDisplayZero); + + if (shallDisplayValue) { + // Shall display balance + + // Display value without currency and without decimals + balanceTextView.setText(!shallDisplayNegativeSignum + ? balanceToDisplay.abs() + .toShortString() + : balanceToDisplay.toShortString()); + + } else { + // Shall not display balance + + balanceTextView.setText(""); + } } // @@ -188,6 +206,7 @@ public void displayBalance(final TextView balanceTextView, displayBalance(balanceTextView, balance, true, + true, true); } @@ -206,6 +225,7 @@ public void displayBalanceWithoutCurrency(final TextView transactionBalanceTextV displayBalance(transactionBalanceTextView, transactionBalance, shallDisplayNegativeSignumInSplits, + false, false); } /** diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionDetailActivity.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionDetailActivity.java index 34aaaf4e4..62b210d8e 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionDetailActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionDetailActivity.java @@ -78,6 +78,7 @@ public SplitAmountViewHolder(View view, accountType.displayBalance(balanceView, splitSignedAmount, false, + true, true); } @@ -234,6 +235,7 @@ private void bindViews() { accountType.displayBalance(balanceTextView, accountBalance, true, + true, true); //