Initialize NumberGridTimePickerDialog with Alarm's previous hour and minute. Expand collapsed ViewHolder when time is clicked.

This commit is contained in:
Phillip Hsu 2016-09-02 21:27:48 -07:00
parent 446d7a5334
commit b1ac2e60dd
4 changed files with 16 additions and 6 deletions

View File

@ -131,7 +131,7 @@ public class AlarmsFragment extends RecyclerViewFragment<
// If we keep a reference to the dialog, we keep its previous state as well. // If we keep a reference to the dialog, we keep its previous state as well.
// So the next time we call show() on it, the input field will show the // So the next time we call show() on it, the input field will show the
// last inputted time. // last inputted time.
BaseTimePickerDialog dialog = TimePickerHelper.newDialog(getActivity(), this); BaseTimePickerDialog dialog = TimePickerHelper.newDialog(getActivity(), this, 0, 0);
// DISREGARD THE LINT WARNING ABOUT DIALOG BEING NULL. // DISREGARD THE LINT WARNING ABOUT DIALOG BEING NULL.
dialog.show(getFragmentManager(), TAG_TIME_PICKER); dialog.show(getFragmentManager(), TAG_TIME_PICKER);
} }

View File

@ -198,7 +198,9 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
@OnClick(R.id.time) @OnClick(R.id.time)
void openTimePicker() { void openTimePicker() {
BaseTimePickerDialog dialog = TimePickerHelper.newDialog(getContext(), newOnTimeSetListener()); Alarm alarm = getAlarm();
BaseTimePickerDialog dialog = TimePickerHelper.newDialog(getContext(),
newOnTimeSetListener(), alarm.hour(), alarm.minutes());
dialog.show(mFragmentManager, AlarmsFragment.TAG_TIME_PICKER); dialog.show(mFragmentManager, AlarmsFragment.TAG_TIME_PICKER);
} }

View File

@ -98,4 +98,11 @@ public class CollapsedAlarmViewHolder extends BaseAlarmViewHolder {
void openLabelEditor() { void openLabelEditor() {
// DO NOT IMPLEMENT // DO NOT IMPLEMENT
} }
@Override
void openTimePicker() {
super.openTimePicker();
// Pretend we also clicked the itemView, so we get expanded.
onClick(itemView);
}
} }

View File

@ -13,7 +13,8 @@ import com.philliphsu.clock2.R;
*/ */
public final class TimePickerHelper { public final class TimePickerHelper {
public static BaseTimePickerDialog newDialog(Context context, BaseTimePickerDialog.OnTimeSetListener l) { public static BaseTimePickerDialog newDialog(Context context, BaseTimePickerDialog.OnTimeSetListener l,
int initialHourOfDay, int initialMinute) {
BaseTimePickerDialog dialog = null; BaseTimePickerDialog dialog = null;
String numpadStyle = context.getString(R.string.number_pad); String numpadStyle = context.getString(R.string.number_pad);
String gridStyle = context.getString(R.string.grid_selector); String gridStyle = context.getString(R.string.grid_selector);
@ -26,9 +27,9 @@ public final class TimePickerHelper {
dialog = NumpadTimePickerDialog.newInstance(l); dialog = NumpadTimePickerDialog.newInstance(l);
} else if (prefTimePickerStyle.equals(gridStyle)) { } else if (prefTimePickerStyle.equals(gridStyle)) {
dialog = NumberGridTimePickerDialog.newInstance( dialog = NumberGridTimePickerDialog.newInstance(
l, // OnTimeSetListener l,
0, // Initial hour of day initialHourOfDay,
0, // Initial minute initialMinute,
DateFormat.is24HourFormat(context)); DateFormat.is24HourFormat(context));
} }
// We don't have a default case, because we don't need one; prefTimePickerStyle // We don't have a default case, because we don't need one; prefTimePickerStyle