Skip to content

Commit

Permalink
codinguser#876 - Move attributes from ColorizeOnTransactionTypeChange…
Browse files Browse the repository at this point in the history
…Listener to TransactionTypeSwitch
  • Loading branch information
JeanGarf committed Mar 3, 2020
1 parent c329455 commit 02e6a02
Showing 1 changed file with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class TransactionTypeSwitch extends SwitchCompat {

private AccountType mAccountType = AccountType.EXPENSE;

// View to update and colorize
private CalculatorEditText mAmountEditText;
private TextView mCurrencyTextView;

// Listeners to call in case of change in Transaction Type switch
List<OnCheckedChangeListener> mOnCheckedChangeListeners = new ArrayList<>();

Expand Down Expand Up @@ -135,9 +139,7 @@ public void setAccountType(AccountType accountType) {
// Set switch text and color
//

// TODO TW C 2020-03-03 : A remettre
setText(isChecked() ? getTextOn() : getTextOff());
// setSwitchTextAndColor(isChecked());
setSwitchTextAndColor(isChecked());

invalidate();
}
Expand Down Expand Up @@ -204,6 +206,47 @@ public TransactionType getTransactionType() {
: TransactionType.DEBIT;
}

private void setSwitchTextAndColor(final boolean isCredit) {

//
// Set switch text
//

setText(isCredit
? getTextOn() // CREDIT
: getTextOff() // DEBIT
);

//
// Set text color
//

// TODO TW C 2020-03-02 : A renommer et commenter
if ((mAccountType.isResultAccount() && !isCredit) || (!mAccountType.isResultAccount() && isCredit)) {
// CREDIT

// RED
int red = ContextCompat.getColor(getContext(),
R.color.debit_red);
setAllTextsColor(red);

} else {
// DEBIT

// GREEN
int green = ContextCompat.getColor(getContext(),
R.color.credit_green);
setAllTextsColor(green);
}
}

private void setAllTextsColor(final int color) {

TransactionTypeSwitch.this.setTextColor(color);
mAmountEditText.setTextColor(color);
mCurrencyTextView.setTextColor(color);
}

//
// Inner Class OnTypeChangedListener
//
Expand All @@ -215,19 +258,15 @@ public TransactionType getTransactionType() {
private class ColorizeOnTransactionTypeChangeListener
implements OnCheckedChangeListener{

// View to update and colorize
private CalculatorEditText mAmountEditText;
private TextView mCurrencyTextView;

/**
* Constructor with the amount view
* @param amountEditText EditText displaying the amount value
* @param currencyTextView Currency symbol text view
*/
public ColorizeOnTransactionTypeChangeListener(CalculatorEditText amountEditText, TextView currencyTextView){

this.mAmountEditText = amountEditText;
this.mCurrencyTextView = currencyTextView;
mAmountEditText = amountEditText;
mCurrencyTextView = currencyTextView;
}

@Override
Expand Down Expand Up @@ -267,45 +306,5 @@ public void onCheckedChanged(CompoundButton compoundButton,
} // for
}

public void setSwitchTextAndColor(final boolean isCredit) {

//
// Set switch text
//

setText(isCredit
? getTextOn() // CREDIT
: getTextOff() // DEBIT
);

//
// Set text color
//

// TODO TW C 2020-03-02 : A renommer et commenter
if ((mAccountType.isResultAccount() && !isCredit) || (!mAccountType.isResultAccount() && isCredit)) {
// 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);
}
}

private void setTextColor(final int color) {

TransactionTypeSwitch.this.setTextColor(color);
mAmountEditText.setTextColor(color);
mCurrencyTextView.setTextColor(color);
}
}
}

0 comments on commit 02e6a02

Please sign in to comment.