33import android .annotation .SuppressLint ;
44import android .app .DatePickerDialog ;
55import android .app .TimePickerDialog ;
6- import android .graphics .drawable .ColorDrawable ;
7- import android .os .Build ;
86import android .support .annotation .Nullable ;
9- import android .support .annotation .StyleRes ;
107import android .support .v7 .widget .AppCompatSpinner ;
118import android .text .InputFilter ;
129import android .text .Spanned ;
1512import android .view .Menu ;
1613import android .view .MenuItem ;
1714import android .view .View ;
18- import android .view .Window ;
19- import android .view .WindowManager ;
2015import android .view .inputmethod .EditorInfo ;
2116import android .widget .AdapterView ;
2217import android .widget .ArrayAdapter ;
2520import android .widget .EditText ;
2621import android .widget .TextView ;
2722import android .widget .TimePicker ;
28- import android .widget .Toast ;
2923
3024import com .blogspot .e_kanivets .moneytracker .R ;
3125import com .blogspot .e_kanivets .moneytracker .activity .base .BaseBackActivity ;
3630import com .blogspot .e_kanivets .moneytracker .controller .data .RecordController ;
3731import com .blogspot .e_kanivets .moneytracker .entity .data .Account ;
3832import com .blogspot .e_kanivets .moneytracker .entity .data .Record ;
33+ import com .blogspot .e_kanivets .moneytracker .ui .AddRecordUiDecorator ;
3934import com .blogspot .e_kanivets .moneytracker .util .CategoryAutoCompleter ;
4035import com .blogspot .e_kanivets .moneytracker .util .validator .IValidator ;
4136import com .blogspot .e_kanivets .moneytracker .util .validator .RecordValidator ;
@@ -72,8 +67,6 @@ public class AddRecordActivity extends BaseBackActivity {
7267
7368 private List <Account > accountList ;
7469 private long timestamp ;
75- @ StyleRes
76- private int dialogTheme ;
7770
7871 @ Inject
7972 CategoryController categoryController ;
@@ -85,6 +78,7 @@ public class AddRecordActivity extends BaseBackActivity {
8578 FormatController formatController ;
8679
8780 private IValidator <Record > recordValidator ;
81+ private AddRecordUiDecorator uiDecorator ;
8882
8983 @ Bind (R .id .content )
9084 View contentView ;
@@ -111,6 +105,8 @@ protected boolean initData() {
111105 super .initData ();
112106 getAppComponent ().inject (AddRecordActivity .this );
113107
108+ uiDecorator = new AddRecordUiDecorator (AddRecordActivity .this );
109+
114110 record = getIntent ().getParcelableExtra (KEY_RECORD );
115111 mode = (Mode ) getIntent ().getSerializableExtra (KEY_MODE );
116112 type = getIntent ().getIntExtra (KEY_TYPE , -1 );
@@ -140,44 +136,9 @@ protected void initViews() {
140136 etPrice .setText (formatController .formatPrecisionNone (record .getFullPrice ()));
141137 }
142138
139+ uiDecorator .decorateActionBar (getSupportActionBar (), mode , type );
143140 presentSpinnerAccount ();
144141
145- dialogTheme = 0 ;
146- if (getSupportActionBar () != null ) {
147- switch (type ) {
148- case Record .TYPE_EXPENSE :
149- if (mode == Mode .MODE_ADD )
150- getSupportActionBar ().setTitle (R .string .title_add_expense );
151- else getSupportActionBar ().setTitle (R .string .title_edit_expense );
152- getSupportActionBar ().setBackgroundDrawable (
153- new ColorDrawable (getResources ().getColor (R .color .red_light )));
154- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
155- Window window = getWindow ();
156- window .addFlags (WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS );
157- window .setStatusBarColor (getResources ().getColor (R .color .red_dark ));
158- dialogTheme = R .style .RedDialogTheme ;
159- }
160- break ;
161-
162- case Record .TYPE_INCOME :
163- if (mode == Mode .MODE_ADD )
164- getSupportActionBar ().setTitle (R .string .title_add_income );
165- else getSupportActionBar ().setTitle (R .string .title_edit_income );
166- getSupportActionBar ().setBackgroundDrawable (
167- new ColorDrawable (getResources ().getColor (R .color .green_light )));
168- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
169- Window window = getWindow ();
170- window .addFlags (WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS );
171- window .setStatusBarColor (getResources ().getColor (R .color .green_dark ));
172- dialogTheme = R .style .GreenDialogTheme ;
173- }
174- break ;
175-
176- default :
177- break ;
178- }
179- }
180-
181142 etCategory .setAdapter (new CategoryAutoCompleteAdapter (AddRecordActivity .this ,
182143 R .layout .view_category_item , new CategoryAutoCompleter (categoryController )));
183144 etCategory .setOnItemClickListener (new AdapterView .OnItemClickListener () {
@@ -215,9 +176,6 @@ public boolean onPrepareOptionsMenu(Menu menu) {
215176 menu .removeItem (R .id .action_delete );
216177 break ;
217178
218- case MODE_EDIT :
219- break ;
220-
221179 default :
222180 break ;
223181 }
@@ -253,7 +211,7 @@ public void selectDate() {
253211
254212 Calendar calendar = Calendar .getInstance ();
255213 calendar .setTimeInMillis (timestamp );
256- DatePickerDialog dialog = new DatePickerDialog (AddRecordActivity .this , dialogTheme ,
214+ DatePickerDialog dialog = new DatePickerDialog (AddRecordActivity .this , uiDecorator . getTheme ( type ) ,
257215 new DatePickerDialog .OnDateSetListener () {
258216 @ Override
259217 public void onDateSet (DatePicker view , int year , int monthOfYear , int dayOfMonth ) {
@@ -284,7 +242,7 @@ public void selectTime() {
284242
285243 Calendar calendar = Calendar .getInstance ();
286244 calendar .setTimeInMillis (timestamp );
287- TimePickerDialog dialog = new TimePickerDialog (AddRecordActivity .this , dialogTheme ,
245+ TimePickerDialog dialog = new TimePickerDialog (AddRecordActivity .this , uiDecorator . getTheme ( type ) ,
288246 new TimePickerDialog .OnTimeSetListener () {
289247 @ Override
290248 public void onTimeSet (TimePicker view , int hourOfDay , int minute ) {
0 commit comments