forked from codinguser/gnucash-android
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codinguser#876 - Correct errors in debit/credit labels vs GnuCash Win…
…dows. isChecked() : true == CREDIT. CREDIT => red, DEBIT => green
- Loading branch information
Showing
1 changed file
with
85 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
*/ | ||
|
@@ -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); | ||
} | ||
} | ||
} |