Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show previously picked time when editing alarm's time #784

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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