Skip to content

Commit

Permalink
codinguser#876 - ** Add shallDisplayZero in displayBalance(...) to av…
Browse files Browse the repository at this point in the history
…oid displaying 0
  • Loading branch information
JeanGarf committed Jun 14, 2020
1 parent 03225b1 commit 8f1767e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
30 changes: 25 additions & 5 deletions app/src/main/java/org/gnucash/android/model/AccountType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

//
Expand All @@ -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("");
}
}

//
Expand Down Expand Up @@ -188,6 +206,7 @@ public void displayBalance(final TextView balanceTextView,
displayBalance(balanceTextView,
balance,
true,
true,
true);
}

Expand All @@ -206,6 +225,7 @@ public void displayBalanceWithoutCurrency(final TextView transactionBalanceTextV
displayBalance(transactionBalanceTextView,
transactionBalance,
shallDisplayNegativeSignumInSplits,
false,
false);
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public SplitAmountViewHolder(View view,
accountType.displayBalance(balanceView,
splitSignedAmount,
false,
true,
true);
}

Expand Down Expand Up @@ -234,6 +235,7 @@ private void bindViews() {
accountType.displayBalance(balanceTextView,
accountBalance,
true,
true,
true);

//
Expand Down

0 comments on commit 8f1767e

Please sign in to comment.