Skip to content

Commit

Permalink
Show previously picked time when editing alarm's time (#784)
Browse files Browse the repository at this point in the history
Closes: #776
  • Loading branch information
werman authored Apr 5, 2020
1 parent 6bc56d9 commit 70aa0ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void RefreshListAndView() {
DataRadioStationAlarm clickedAlarm = null;
private void ClickOnItem(DataRadioStationAlarm anObject) {
clickedAlarm = anObject;
TimePickerFragment newFragment = new TimePickerFragment();
TimePickerFragment newFragment = new TimePickerFragment(clickedAlarm.hour, clickedAlarm.minute);
newFragment.setCallback(this);
newFragment.show(getActivity().getSupportFragmentManager(), "timePicker");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,27 @@
import java.util.Calendar;

public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
TimePickerDialog.OnTimeSetListener callback;
private TimePickerDialog.OnTimeSetListener callback;
private int initialHour;
private int initialMinute;

public TimePickerFragment() {
final Calendar c = Calendar.getInstance();
this.initialHour = c.get(Calendar.HOUR_OF_DAY);
this.initialMinute = c.get(Calendar.MINUTE);
}

public TimePickerFragment(int initialHour, int initialMinute) {
this.initialHour = initialHour;
this.initialMinute = initialMinute;
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);

// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), Utils.getTimePickerThemeResId(getActivity()), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
return new TimePickerDialog(getActivity(), Utils.getTimePickerThemeResId(getActivity()),
this, initialHour, initialMinute, DateFormat.is24HourFormat(getActivity()));
}

public void setCallback(TimePickerDialog.OnTimeSetListener callback) {
Expand All @@ -35,8 +44,8 @@ public void setCallback(TimePickerDialog.OnTimeSetListener callback) {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// this is needed, because on some devices onTimeSet is called twice!!
if (callback != null){
callback.onTimeSet(view,hourOfDay,minute);
if (callback != null) {
callback.onTimeSet(view, hourOfDay, minute);
callback = null;
}
}
Expand Down

0 comments on commit 70aa0ed

Please sign in to comment.