Skip to content

Commit

Permalink
Fix for datefragment crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Nov 22, 2023
1 parent 036c582 commit 26d821b
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ private void setDate() {
};

new DateFragment()
.setActivity(getActivity())
.setListener(listener)
.setCalendar(initDate)
.show(((FragmentActivity) getActivity()).getSupportFragmentManager(), "date");
Expand Down Expand Up @@ -372,7 +371,6 @@ private void setDueDate(final int offset) {
};

new DateFragment()
.setActivity(getActivity())
.setListener(listener)
.setCalendar(initDate)
.setMessage(getContext().getString(R.string.due_date))
Expand All @@ -391,7 +389,6 @@ public static class DateFragment extends DialogFragment {
private DatePickerDialog.OnClickListener _extraListener;
private String _extraLabel;

private Activity _activity;
private int _year;
private int _month;
private int _day;
Expand All @@ -417,11 +414,6 @@ public DateFragment setExtraLabel(String label) {
return this;
}

public DateFragment setActivity(Activity activity) {
_activity = activity;
return this;
}

public DateFragment setYear(int year) {
_year = year;
return this;
Expand Down Expand Up @@ -451,10 +443,10 @@ public DateFragment setCalendar(Calendar calendar) {

@NonNull
@Override
public DatePickerDialog onCreateDialog(Bundle savedInstanceState) {
public DatePickerDialog onCreateDialog(final Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);

DatePickerDialog dialog = new DatePickerDialog(_activity, _listener, _year, _month, _day);
final DatePickerDialog dialog = new DatePickerDialog(getContext(), _listener, _year, _month, _day);

if (_message != null && !_message.isEmpty()) {
dialog.setMessage(_message);
Expand All @@ -466,5 +458,14 @@ public DatePickerDialog onCreateDialog(Bundle savedInstanceState) {

return dialog;
}

@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Do not auto-recreate
if (savedInstanceState != null) {
dismiss();
}
}
}
}

0 comments on commit 26d821b

Please sign in to comment.