@@ -41,6 +41,10 @@ public class TransactionTypeSwitch extends SwitchCompat {
41
41
42
42
private AccountType mAccountType = AccountType .EXPENSE ;
43
43
44
+ // View to update and colorize
45
+ private CalculatorEditText mAmountEditText ;
46
+ private TextView mCurrencyTextView ;
47
+
44
48
// Listeners to call in case of change in Transaction Type switch
45
49
List <OnCheckedChangeListener > mOnCheckedChangeListeners = new ArrayList <>();
46
50
@@ -135,9 +139,7 @@ public void setAccountType(AccountType accountType) {
135
139
// Set switch text and color
136
140
//
137
141
138
- // TODO TW C 2020-03-03 : A remettre
139
- setText (isChecked () ? getTextOn () : getTextOff ());
140
- // setSwitchTextAndColor(isChecked());
142
+ setSwitchTextAndColor (isChecked ());
141
143
142
144
invalidate ();
143
145
}
@@ -204,6 +206,47 @@ public TransactionType getTransactionType() {
204
206
: TransactionType .DEBIT ;
205
207
}
206
208
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
+
207
250
//
208
251
// Inner Class OnTypeChangedListener
209
252
//
@@ -215,19 +258,15 @@ public TransactionType getTransactionType() {
215
258
private class ColorizeOnTransactionTypeChangeListener
216
259
implements OnCheckedChangeListener {
217
260
218
- // View to update and colorize
219
- private CalculatorEditText mAmountEditText ;
220
- private TextView mCurrencyTextView ;
221
-
222
261
/**
223
262
* Constructor with the amount view
224
263
* @param amountEditText EditText displaying the amount value
225
264
* @param currencyTextView Currency symbol text view
226
265
*/
227
266
public ColorizeOnTransactionTypeChangeListener (CalculatorEditText amountEditText , TextView currencyTextView ){
228
267
229
- this . mAmountEditText = amountEditText ;
230
- this . mCurrencyTextView = currencyTextView ;
268
+ mAmountEditText = amountEditText ;
269
+ mCurrencyTextView = currencyTextView ;
231
270
}
232
271
233
272
@ Override
@@ -267,45 +306,5 @@ public void onCheckedChanged(CompoundButton compoundButton,
267
306
} // for
268
307
}
269
308
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
- }
310
309
}
311
310
}
0 commit comments