From 24a5fba7c5166eef548f9ea21939894e8e77c4bb Mon Sep 17 00:00:00 2001 From: werman Date: Fri, 3 Apr 2020 00:08:38 +0300 Subject: [PATCH] Show previously picked time when editing alarm's time Closes: #776 --- .../radiodroid2/alarm/FragmentAlarm.java | 2 +- .../radiodroid2/alarm/TimePickerFragment.java | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/net/programmierecke/radiodroid2/alarm/FragmentAlarm.java b/app/src/main/java/net/programmierecke/radiodroid2/alarm/FragmentAlarm.java index de4df101f..f70e1c569 100644 --- a/app/src/main/java/net/programmierecke/radiodroid2/alarm/FragmentAlarm.java +++ b/app/src/main/java/net/programmierecke/radiodroid2/alarm/FragmentAlarm.java @@ -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"); } diff --git a/app/src/main/java/net/programmierecke/radiodroid2/alarm/TimePickerFragment.java b/app/src/main/java/net/programmierecke/radiodroid2/alarm/TimePickerFragment.java index f147839bd..0b89d67db 100644 --- a/app/src/main/java/net/programmierecke/radiodroid2/alarm/TimePickerFragment.java +++ b/app/src/main/java/net/programmierecke/radiodroid2/alarm/TimePickerFragment.java @@ -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) { @@ -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; } }