From 5367a269960e37ba66532359b6c8f7a5fe6a8228 Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Mon, 2 Mar 2020 01:59:44 +0100 Subject: [PATCH] #876 - Correct errors in debit/credit labels vs GnuCash Windows. isChecked() : true == CREDIT. CREDIT => red, DEBIT => green --- .../ui/util/widget/TransactionTypeSwitch.java | 129 ++++++++++++------ 1 file changed, 85 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java b/app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java index 9a06fe3ad..ca3a64b74 100644 --- a/app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java +++ b/app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java @@ -33,7 +33,7 @@ import java.util.List; /** - * A special type of {@link android.widget.ToggleButton} which displays the appropriate CREDIT/DEBIT labels for the + * A special type of {@link android.widget.ToggleButton} which displays the appropriate DEBIT/CREDIT labels for the * different account types. * @author Ngewi Fet */ @@ -59,49 +59,55 @@ public void setAccountType(AccountType accountType){ Context context = getContext().getApplicationContext(); switch (mAccountType) { case CASH: - setTextOn(context.getString(R.string.label_spend)); - setTextOff(context.getString(R.string.label_receive)); + setTextOff(context.getString(R.string.label_receive)); // DEBIT + setTextOn(context.getString(R.string.label_spend)); // CREDIT break; case BANK: - setTextOn(context.getString(R.string.label_withdrawal)); - setTextOff(context.getString(R.string.label_deposit)); + setTextOff(context.getString(R.string.label_deposit)); // DEBIT + setTextOn(context.getString(R.string.label_withdrawal)); // CREDIT break; case CREDIT: - setTextOn(context.getString(R.string.label_payment)); - setTextOff(context.getString(R.string.label_charge)); + // #876 Change according to GnuCash on Windows + setTextOff(context.getString(R.string.label_payment)); // DEBIT + setTextOn(context.getString(R.string.label_charge)); // CREDIT break; case ASSET: case EQUITY: case LIABILITY: - setTextOn(context.getString(R.string.label_decrease)); - setTextOff(context.getString(R.string.label_increase)); + // #876 Change according to GnuCash on Windows + setTextOff(context.getString(R.string.label_decrease)); // DEBIT + setTextOn(context.getString(R.string.label_increase)); // CREDIT break; case INCOME: - setTextOn(context.getString(R.string.label_charge)); - setTextOff(context.getString(R.string.label_income)); + // #876 Change according to GnuCash on Windows + setTextOff(context.getString(R.string.label_charge)); // DEBIT + setTextOn(context.getString(R.string.label_income)); // CREDIT break; case EXPENSE: - setTextOn(context.getString(R.string.label_rebate)); - setTextOff(context.getString(R.string.label_expense)); + setTextOff(context.getString(R.string.label_expense)); // DEBIT + setTextOn(context.getString(R.string.label_rebate)); // CREDIT break; case PAYABLE: - setTextOn(context.getString(R.string.label_payment)); - setTextOff(context.getString(R.string.label_bill)); + // #876 Change according to GnuCash on Windows + setTextOff(context.getString(R.string.label_payment)); // DEBIT + setTextOn(context.getString(R.string.label_bill)); // CREDIT break; case RECEIVABLE: - setTextOn(context.getString(R.string.label_payment)); - setTextOff(context.getString(R.string.label_invoice)); + setTextOff(context.getString(R.string.label_invoice)); // DEBIT + setTextOn(context.getString(R.string.label_payment)); // CREDIT break; case STOCK: case MUTUAL: - setTextOn(context.getString(R.string.label_buy)); - setTextOff(context.getString(R.string.label_sell)); + // #876 Change according to GnuCash on Windows + setTextOff(context.getString(R.string.label_buy)); // DEBIT + setTextOn(context.getString(R.string.label_sell)); // CREDIT break; case CURRENCY: case ROOT: default: - setTextOn(context.getString(R.string.label_debit)); - setTextOff(context.getString(R.string.label_credit)); + // #876 Change according to GnuCash on Windows + setTextOff(context.getString(R.string.label_debit)); // DEBIT + setTextOn(context.getString(R.string.label_credit)); // CREDIT break; } setText(isChecked() ? getTextOn() : getTextOff()); @@ -130,7 +136,9 @@ public void addOnCheckedChangeListener(OnCheckedChangeListener checkedChangeList * @param transactionType {@link org.gnucash.android.model.TransactionType} of the split */ public void setChecked(TransactionType transactionType){ - setChecked(Transaction.shouldDecreaseBalance(mAccountType, transactionType)); + // #876 +// setChecked(Transaction.shouldDecreaseBalance(mAccountType, transactionType)); + setChecked(TransactionType.CREDIT.equals(transactionType)); } /** @@ -141,12 +149,24 @@ public AccountType getAccountType(){ return mAccountType; } - public TransactionType getTransactionType(){ - if (mAccountType.hasDebitNormalBalance()){ - return isChecked() ? TransactionType.CREDIT : TransactionType.DEBIT; - } else { - return isChecked() ? TransactionType.DEBIT : TransactionType.CREDIT; - } + public TransactionType getTransactionType() { + + // #876 +// if (mAccountType.hasDebitNormalBalance()) { +// +// return isChecked() +// ? TransactionType.CREDIT +// : TransactionType.DEBIT; +// +// } else { +// +// return isChecked() +// ? TransactionType.DEBIT +// : TransactionType.CREDIT; +// } + return isChecked() + ? TransactionType.CREDIT + : TransactionType.DEBIT; } private class OnTypeChangedListener implements OnCheckedChangeListener{ @@ -163,32 +183,53 @@ public OnTypeChangedListener(CalculatorEditText amountEditText, TextView currenc } @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { - setText(isChecked ? getTextOn() : getTextOff()); - if (isChecked){ - int red = ContextCompat.getColor(getContext(), R.color.debit_red); - TransactionTypeSwitch.this.setTextColor(red); - mAmountEditText.setTextColor(red); - mCurrencyTextView.setTextColor(red); - } - else { - int green = ContextCompat.getColor(getContext(), R.color.credit_green); - TransactionTypeSwitch.this.setTextColor(green); - mAmountEditText.setTextColor(green); - mCurrencyTextView.setTextColor(green); + public void onCheckedChanged(CompoundButton compoundButton, + boolean isChecked) { + + setText(isChecked + ? getTextOn() // CREDIT + : getTextOff() // DEBIT + ); + + if (isChecked) { + // CREDIT + + // RED + int red = ContextCompat.getColor(getContext(), + R.color.debit_red); + setTextColor(red); + + } else { + // DEBIT + + // GREEN + int green = ContextCompat.getColor(getContext(), + R.color.credit_green); + setTextColor(green); } + BigDecimal amount = mAmountEditText.getValue(); - if (amount != null){ + + if (amount != null) { if ((isChecked && amount.signum() > 0) //we switched to debit but the amount is +ve - || (!isChecked && amount.signum() < 0)){ //credit but amount is -ve + || (!isChecked && amount.signum() < 0)) { //credit but amount is -ve + mAmountEditText.setValue(amount.negate()); } } for (OnCheckedChangeListener listener : mOnCheckedChangeListeners) { - listener.onCheckedChanged(compoundButton, isChecked); + listener.onCheckedChanged(compoundButton, + isChecked); } } + + private void setTextColor(final int color) { + + TransactionTypeSwitch.this.setTextColor(color); + mAmountEditText.setTextColor(color); + mCurrencyTextView.setTextColor(color); + } } }