77
88package com .reactcommunity .rndatetimepicker ;
99
10+ import static com .reactcommunity .rndatetimepicker .Common .getDisplayDate ;
1011import static com .reactcommunity .rndatetimepicker .Common .setButtonTextColor ;
1112
1213import android .annotation .SuppressLint ;
@@ -39,6 +40,7 @@ public class RNDatePickerDialogFragment extends DialogFragment {
3940 @ Nullable
4041 private static OnClickListener mOnNeutralButtonActionListener ;
4142
43+ @ NonNull
4244 @ Override
4345 public Dialog onCreateDialog (Bundle savedInstanceState ) {
4446 Bundle args = getArguments ();
@@ -62,33 +64,31 @@ DatePickerDialog getDialog(
6264 final int month = date .month ();
6365 final int day = date .day ();
6466
65- RNDatePickerDisplay display = RNDatePickerDisplay . DEFAULT ;
67+ RNDatePickerDisplay display = getDisplayDate ( args ) ;
6668
6769 if (args != null && args .getString (RNConstants .ARG_DISPLAY , null ) != null ) {
6870 display = RNDatePickerDisplay .valueOf (args .getString (RNConstants .ARG_DISPLAY ).toUpperCase (Locale .US ));
6971 }
7072
71- switch (display ) {
72- case SPINNER :
73- return new RNDismissableDatePickerDialog (
74- activityContext ,
75- R .style .SpinnerDatePickerDialog ,
76- onDateSetListener ,
77- year ,
78- month ,
79- day ,
80- display
81- );
82- default :
83- return new RNDismissableDatePickerDialog (
84- activityContext ,
85- onDateSetListener ,
86- year ,
87- month ,
88- day ,
89- display
90- );
73+ if (display == RNDatePickerDisplay .SPINNER ) {
74+ return new RNDismissableDatePickerDialog (
75+ activityContext ,
76+ R .style .SpinnerDatePickerDialog ,
77+ onDateSetListener ,
78+ year ,
79+ month ,
80+ day ,
81+ display
82+ );
9183 }
84+ return new RNDismissableDatePickerDialog (
85+ activityContext ,
86+ onDateSetListener ,
87+ year ,
88+ month ,
89+ day ,
90+ display
91+ );
9292 }
9393
9494 static DatePickerDialog createDialog (
@@ -100,18 +100,23 @@ static DatePickerDialog createDialog(
100100
101101 DatePickerDialog dialog = getDialog (args , activityContext , onDateSetListener );
102102
103- if (args != null && args .containsKey (RNConstants .ARG_NEUTRAL_BUTTON_LABEL )) {
104- dialog .setButton (DialogInterface .BUTTON_NEUTRAL , args .getString (RNConstants .ARG_NEUTRAL_BUTTON_LABEL ), mOnNeutralButtonActionListener );
105- }
106- if (args != null && args .containsKey (RNConstants .ARG_POSITIVE_BUTTON_LABEL )) {
107- dialog .setButton (DialogInterface .BUTTON_POSITIVE , args .getString (RNConstants .ARG_POSITIVE_BUTTON_LABEL ), dialog );
108- }
109- if (args != null && args .containsKey (RNConstants .ARG_NEGATIVE_BUTTON_LABEL )) {
110- dialog .setButton (DialogInterface .BUTTON_NEGATIVE , args .getString (RNConstants .ARG_NEGATIVE_BUTTON_LABEL ), dialog );
103+ if (args != null ) {
104+ if (args .containsKey (RNConstants .ARG_NEUTRAL_BUTTON_LABEL )) {
105+ dialog .setButton (DialogInterface .BUTTON_NEUTRAL , args .getString (RNConstants .ARG_NEUTRAL_BUTTON_LABEL ), mOnNeutralButtonActionListener );
106+ }
107+ if (args .containsKey (RNConstants .ARG_POSITIVE_BUTTON_LABEL )) {
108+ dialog .setButton (DialogInterface .BUTTON_POSITIVE , args .getString (RNConstants .ARG_POSITIVE_BUTTON_LABEL ), dialog );
109+ }
110+ if (args .containsKey (RNConstants .ARG_NEGATIVE_BUTTON_LABEL )) {
111+ dialog .setButton (DialogInterface .BUTTON_NEGATIVE , args .getString (RNConstants .ARG_NEGATIVE_BUTTON_LABEL ), dialog );
112+ }
113+ RNDatePickerDisplay display = getDisplayDate (args );
114+ if (display == RNDatePickerDisplay .SPINNER ) {
115+ dialog .setOnShowListener (setButtonTextColor (activityContext , dialog ));
116+ }
111117 }
112118
113119 final DatePicker datePicker = dialog .getDatePicker ();
114- dialog .setOnShowListener (setButtonTextColor (activityContext , dialog ));
115120
116121 Integer timeZoneOffsetInMilliseconds = getTimeZoneOffset (args );
117122 if (timeZoneOffsetInMilliseconds != null ) {
@@ -164,7 +169,7 @@ private static int getOffset(Calendar c, Integer timeZoneOffsetInMilliseconds) {
164169 }
165170
166171 @ Override
167- public void onDismiss (DialogInterface dialog ) {
172+ public void onDismiss (@ NonNull DialogInterface dialog ) {
168173 super .onDismiss (dialog );
169174 if (mOnDismissListener != null ) {
170175 mOnDismissListener .onDismiss (dialog );
0 commit comments