Skip to content

Commit 02e6a02

Browse files
committed
codinguser#876 - Move attributes from ColorizeOnTransactionTypeChangeListener to TransactionTypeSwitch
1 parent c329455 commit 02e6a02

File tree

1 file changed

+48
-49
lines changed

1 file changed

+48
-49
lines changed

app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public class TransactionTypeSwitch extends SwitchCompat {
4141

4242
private AccountType mAccountType = AccountType.EXPENSE;
4343

44+
// View to update and colorize
45+
private CalculatorEditText mAmountEditText;
46+
private TextView mCurrencyTextView;
47+
4448
// Listeners to call in case of change in Transaction Type switch
4549
List<OnCheckedChangeListener> mOnCheckedChangeListeners = new ArrayList<>();
4650

@@ -135,9 +139,7 @@ public void setAccountType(AccountType accountType) {
135139
// Set switch text and color
136140
//
137141

138-
// TODO TW C 2020-03-03 : A remettre
139-
setText(isChecked() ? getTextOn() : getTextOff());
140-
// setSwitchTextAndColor(isChecked());
142+
setSwitchTextAndColor(isChecked());
141143

142144
invalidate();
143145
}
@@ -204,6 +206,47 @@ public TransactionType getTransactionType() {
204206
: TransactionType.DEBIT;
205207
}
206208

209+
private void setSwitchTextAndColor(final boolean isCredit) {
210+
211+
//
212+
// Set switch text
213+
//
214+
215+
setText(isCredit
216+
? getTextOn() // CREDIT
217+
: getTextOff() // DEBIT
218+
);
219+
220+
//
221+
// Set text color
222+
//
223+
224+
// TODO TW C 2020-03-02 : A renommer et commenter
225+
if ((mAccountType.isResultAccount() && !isCredit) || (!mAccountType.isResultAccount() && isCredit)) {
226+
// CREDIT
227+
228+
// RED
229+
int red = ContextCompat.getColor(getContext(),
230+
R.color.debit_red);
231+
setAllTextsColor(red);
232+
233+
} else {
234+
// DEBIT
235+
236+
// GREEN
237+
int green = ContextCompat.getColor(getContext(),
238+
R.color.credit_green);
239+
setAllTextsColor(green);
240+
}
241+
}
242+
243+
private void setAllTextsColor(final int color) {
244+
245+
TransactionTypeSwitch.this.setTextColor(color);
246+
mAmountEditText.setTextColor(color);
247+
mCurrencyTextView.setTextColor(color);
248+
}
249+
207250
//
208251
// Inner Class OnTypeChangedListener
209252
//
@@ -215,19 +258,15 @@ public TransactionType getTransactionType() {
215258
private class ColorizeOnTransactionTypeChangeListener
216259
implements OnCheckedChangeListener{
217260

218-
// View to update and colorize
219-
private CalculatorEditText mAmountEditText;
220-
private TextView mCurrencyTextView;
221-
222261
/**
223262
* Constructor with the amount view
224263
* @param amountEditText EditText displaying the amount value
225264
* @param currencyTextView Currency symbol text view
226265
*/
227266
public ColorizeOnTransactionTypeChangeListener(CalculatorEditText amountEditText, TextView currencyTextView){
228267

229-
this.mAmountEditText = amountEditText;
230-
this.mCurrencyTextView = currencyTextView;
268+
mAmountEditText = amountEditText;
269+
mCurrencyTextView = currencyTextView;
231270
}
232271

233272
@Override
@@ -267,45 +306,5 @@ public void onCheckedChanged(CompoundButton compoundButton,
267306
} // for
268307
}
269308

270-
public void setSwitchTextAndColor(final boolean isCredit) {
271-
272-
//
273-
// Set switch text
274-
//
275-
276-
setText(isCredit
277-
? getTextOn() // CREDIT
278-
: getTextOff() // DEBIT
279-
);
280-
281-
//
282-
// Set text color
283-
//
284-
285-
// TODO TW C 2020-03-02 : A renommer et commenter
286-
if ((mAccountType.isResultAccount() && !isCredit) || (!mAccountType.isResultAccount() && isCredit)) {
287-
// CREDIT
288-
289-
// RED
290-
int red = ContextCompat.getColor(getContext(),
291-
R.color.debit_red);
292-
setTextColor(red);
293-
294-
} else {
295-
// DEBIT
296-
297-
// GREEN
298-
int green = ContextCompat.getColor(getContext(),
299-
R.color.credit_green);
300-
setTextColor(green);
301-
}
302-
}
303-
304-
private void setTextColor(final int color) {
305-
306-
TransactionTypeSwitch.this.setTextColor(color);
307-
mAmountEditText.setTextColor(color);
308-
mCurrencyTextView.setTextColor(color);
309-
}
310309
}
311310
}

0 commit comments

Comments
 (0)