|
@@ -76,6 +76,19 @@ public class ExpirationDatePickerDialogFragment
|
|
this.onExpiryDateListener = onExpiryDateListener;
|
|
this.onExpiryDateListener = onExpiryDateListener;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onStart() {
|
|
|
|
+ super.onStart();
|
|
|
|
+ final Dialog currentDialog = getDialog();
|
|
|
|
+ if (currentDialog != null) {
|
|
|
|
+ final DatePickerDialog dialog = (DatePickerDialog) currentDialog;
|
|
|
|
+ dialog.getButton(DatePickerDialog.BUTTON_NEUTRAL).setTextColor(themeColorUtils.primaryColor(getContext(), true));
|
|
|
|
+ dialog.getButton(DatePickerDialog.BUTTON_NEGATIVE).setTextColor(themeColorUtils.primaryColor(getContext(), true));
|
|
|
|
+ dialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTextColor(themeColorUtils.primaryColor(getContext(), true));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* {@inheritDoc}
|
|
* {@inheritDoc}
|
|
*
|
|
*
|
|
@@ -113,11 +126,6 @@ public class ExpirationDatePickerDialogFragment
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- dialog.show();
|
|
|
|
- dialog.getButton(DatePickerDialog.BUTTON_NEUTRAL).setTextColor(themeColorUtils.primaryColor(getContext(), true));
|
|
|
|
- dialog.getButton(DatePickerDialog.BUTTON_NEGATIVE).setTextColor(themeColorUtils.primaryColor(getContext(), true));
|
|
|
|
- dialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTextColor(themeColorUtils.primaryColor(getContext(), true));
|
|
|
|
-
|
|
|
|
// Prevent days in the past may be chosen
|
|
// Prevent days in the past may be chosen
|
|
DatePicker picker = dialog.getDatePicker();
|
|
DatePicker picker = dialog.getDatePicker();
|
|
picker.setMinDate(tomorrowInMillis - 1000);
|
|
picker.setMinDate(tomorrowInMillis - 1000);
|
|
@@ -130,6 +138,16 @@ public class ExpirationDatePickerDialogFragment
|
|
return dialog;
|
|
return dialog;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public long getCurrentSelectionMillis() {
|
|
|
|
+ final Dialog dialog = getDialog();
|
|
|
|
+ if (dialog != null) {
|
|
|
|
+ final DatePickerDialog datePickerDialog = (DatePickerDialog) dialog;
|
|
|
|
+ final DatePicker picker = datePickerDialog.getDatePicker();
|
|
|
|
+ return yearMonthDayToMillis(picker.getYear(), picker.getMonth(), picker.getDayOfMonth());
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Called when the user chooses an expiration date.
|
|
* Called when the user chooses an expiration date.
|
|
*
|
|
*
|
|
@@ -141,17 +159,21 @@ public class ExpirationDatePickerDialogFragment
|
|
@Override
|
|
@Override
|
|
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
|
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
|
|
|
|
|
- Calendar chosenDate = Calendar.getInstance();
|
|
|
|
- chosenDate.set(Calendar.YEAR, year);
|
|
|
|
- chosenDate.set(Calendar.MONTH, monthOfYear);
|
|
|
|
- chosenDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
|
|
|
- long chosenDateInMillis = chosenDate.getTimeInMillis();
|
|
|
|
|
|
+ long chosenDateInMillis = yearMonthDayToMillis(year, monthOfYear, dayOfMonth);
|
|
|
|
|
|
if (onExpiryDateListener != null) {
|
|
if (onExpiryDateListener != null) {
|
|
onExpiryDateListener.onDateSet(year, monthOfYear, dayOfMonth, chosenDateInMillis);
|
|
onExpiryDateListener.onDateSet(year, monthOfYear, dayOfMonth, chosenDateInMillis);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private long yearMonthDayToMillis(int year, int monthOfYear, int dayOfMonth) {
|
|
|
|
+ Calendar date = Calendar.getInstance();
|
|
|
|
+ date.set(Calendar.YEAR, year);
|
|
|
|
+ date.set(Calendar.MONTH, monthOfYear);
|
|
|
|
+ date.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
|
|
|
+ return date.getTimeInMillis();
|
|
|
|
+ }
|
|
|
|
+
|
|
public interface OnExpiryDateListener {
|
|
public interface OnExpiryDateListener {
|
|
void onDateSet(int year, int monthOfYear, int dayOfMonth, long chosenDateInMillis);
|
|
void onDateSet(int year, int monthOfYear, int dayOfMonth, long chosenDateInMillis);
|
|
|
|
|