@Override protected void startDataLoad(boolean forceRefresh) { ReminderList.getInstance().clearCurrentReminder(); if (!ReminderList.getInstance().isSaveInProgress()) { ReminderList.getInstance().loadData(forceRefresh); } else { loadAfterSave = true; } }
private void updateEndTime() { ReminderItem remind = ReminderList.getInstance().getCurrentReminder(); if (remind == null) { return; } UtilsTime.setTime(endHour, endMinute, endAM, endPM, remind.getEndTime()); }
private void updateStartTime() { ReminderItem remind = ReminderList.getInstance().getCurrentReminder(); if (remind == null) { return; } UtilsTime.setTime(startHour, startMinute, startAM, startPM, remind.getStartTime()); }
/** Apply reminder items to this view */ private void applyItems() { ArrayList<ReminderItem> data = ReminderList.getInstance().getData(); if (data.isEmpty()) { applyData(null); } else { ArrayList<BaseRecycleContainer> reminders = new ArrayList<>(); for (ReminderItem item : data) { reminders.add(new ReminderContainer(item)); } applyData(reminders); } }
private void updateTimingType() { ReminderItem remind = ReminderList.getInstance().getCurrentReminder(); if (remind == null) { return; } if (remind.isRangeTiming()) { timing.setText(AppUtil.getContext().getString(R.string.range)); specificGroupContainer.setVisibility(View.GONE); rangeGroupContainer.setVisibility(View.VISIBLE); } else { timing.setText(AppUtil.getContext().getString(R.string.specific)); specificGroupContainer.setVisibility(View.VISIBLE); rangeGroupContainer.setVisibility(View.GONE); } }
/** @param event Event listener */ @Subscribe public final void onReminderListEvent(@NonNull ReminderList.ReminderListEvent event) { switch (event) { case DATA_LOAD_PASS: applyItems(); break; case DATA_LOAD_FAIL: Utils.toastLong(getResources().getString(R.string.data_load_fail)); applyItems(); break; case DATA_SAVE_PASS: if (loadAfterSave) { ReminderList.getInstance().loadData(false); loadAfterSave = false; } break; case DATA_SAVE_FAIL: if (loadAfterSave) { ReminderList.getInstance().loadData(false); loadAfterSave = false; } break; } }
private void generateNumberTimePerDay() { ReminderItem remind = ReminderList.getInstance().getCurrentReminder(); if (remind == null) { return; } int diffMinutes = (remind.getEndTime().hour * 60 + remind.getEndTime().minute) - (remind.getStartTime().hour * 60 + remind.getStartTime().minute); int max = Math.max(diffMinutes / 10, 1); remind.setNumberPerDay(Math.min(remind.getNumberPerDay(), max)); List<String> perDayList = new ArrayList<>(); for (int i = 0; i < max; i++) { perDayList.add(Integer.toString(i + 1)); } ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>( parent.getContext(), R.layout.support_simple_spinner_dropdown_item, perDayList); spinnerArrayAdapter.setDropDownViewResource(R.layout.simple_drop_down_item); timeSpinner.setAdapter(spinnerArrayAdapter); timeSpinner.setSelection(remind.getNumberPerDay() - 1); }
public final void bindItem(EditReminderItem item) { ReminderItem remind = ReminderList.getInstance().getCurrentReminder(); if (remind == null) { return; } updateTimingType(); updateStartTime(); updateEndTime(); generateNumberTimePerDay(); timingContainer.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String title = AppUtil.getContext().getString(R.string.timing_type); String[] items = new String[] { AppUtil.getContext().getString(R.string.range), AppUtil.getContext().getString(R.string.specific) }; Bus.postObject( new SingleChoiceRequest( title, items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ReminderItem remind = ReminderList.getInstance().getCurrentReminder(); if (remind == null) { return; } if (which == 0) { remind.setRangeTiming(true); } else { remind.setRangeTiming(false); } updateTimingType(); } }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // On Negative. Unused } })); } }); timesContainer.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ReminderItem remind = ReminderList.getInstance().getCurrentReminder(); if (remind == null) { return; } Bus.postObject( new EditTimesRequest( remind.getSpecificTimeList(), new EditTimesDialog.EditTimesListener() { @Override public void onPositive(ArrayList<TimeItem> times) { ReminderItem remind = ReminderList.getInstance().getCurrentReminder(); if (remind == null) { return; } remind.setSpecificTimeList(times); } }, new View.OnClickListener() { @Override public void onClick(View v) {} }, true)); } }); final TimePickerDialog.OnTimeSetListener timeStartListener = new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet( @NonNull RadialPickerLayout radialPickerLayout, int hourOfDay, int minute) { ReminderItem remind = ReminderList.getInstance().getCurrentReminder(); if (remind == null) { return; } int diffMinutes = (remind.getEndTime().hour * 60 + remind.getEndTime().minute) - (hourOfDay * 60 + minute); if (diffMinutes >= 0) { remind.updateStartTime().hour = hourOfDay; remind.updateStartTime().minute = minute; UtilsTime.setTime(startHour, startMinute, startAM, startPM, remind.getStartTime()); generateNumberTimePerDay(); } else { Utils.toastShort( AppUtil.getContext().getResources().getString(R.string.error_time_difference)); } } }; startTimeContainer.setOnClickListener( new View.OnClickListener() { @Override public void onClick(@NonNull View v) { ReminderItem currentReminder = ReminderList.getInstance().getCurrentReminder(); if (currentReminder == null) { return; } Bus.postObject( new TimePickerRequest( timeStartListener, currentReminder.getStartTime().hour, currentReminder.getStartTime().minute, currentReminder.getStartTime().is24Hour())); } }); final TimePickerDialog.OnTimeSetListener timeEndListener = new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet( @NonNull RadialPickerLayout radialPickerLayout, int hourOfDay, int minute) { ReminderItem remind = ReminderList.getInstance().getCurrentReminder(); if (remind == null) { return; } int diffMinutes = (hourOfDay * 60 + minute) - (remind.getStartTime().hour * 60 + remind.getStartTime().minute); if (diffMinutes >= 0) { remind.updateEndTime().hour = hourOfDay; remind.updateEndTime().minute = minute; UtilsTime.setTime(endHour, endMinute, endAM, endPM, remind.getEndTime()); generateNumberTimePerDay(); } else { Utils.toastShort( AppUtil.getContext().getResources().getString(R.string.error_time_difference)); } } }; endTimeContainer.setOnClickListener( new View.OnClickListener() { @Override public void onClick(@NonNull View v) { ReminderItem currentReminder = ReminderList.getInstance().getCurrentReminder(); if (currentReminder == null) { return; } Bus.postObject( new TimePickerRequest( timeEndListener, currentReminder.getEndTime().hour, currentReminder.getEndTime().minute, currentReminder.getEndTime().is24Hour())); } }); timeSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected( @NonNull AdapterView<?> parent, @NonNull View view, int position, long id) { ReminderItem currentReminder = ReminderList.getInstance().getCurrentReminder(); if (currentReminder == null) { return; } currentReminder.setNumberPerDay(position + 1); } @Override public void onNothingSelected(AdapterView<?> parent) {} }); numTimesContainer.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { timeSpinner.performClick(); } }); }
@Override protected void itemClick(@NonNull BaseRecycleContainer baseRecycleContainer) { ReminderList.getInstance().setCurrentReminder((ReminderItem) baseRecycleContainer.getItem()); mListener.onReminderItemClicked(); }