Use DateAndTimePickerActivity in ReminderControlSet

pull/281/head
Alex Baker 10 years ago
parent 090bf5e645
commit 2d53e51978

@ -79,8 +79,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tasks.R;
import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.dialogs.DateAndTimePickerDialog;
import org.tasks.injection.InjectingFragment;
import org.tasks.location.GeofenceService;
import org.tasks.notifications.NotificationManager;
@ -187,6 +185,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
private TimerActionControlSet timerAction;
private EditNoteActivity editNotes;
private HideUntilControlSet hideUntilControls;
private ReminderControlSet reminderControlSet;
@InjectView(R.id.title) EditText title;
@InjectView(R.id.pager) ViewPager mPager;
@ -387,7 +386,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
controlSetMap.put(getString(R.string.TEA_ctrl_notes_pref),
notesControlSet);
ReminderControlSet reminderControlSet = new ReminderControlSet(alarmService, geofenceService, this);
reminderControlSet = new ReminderControlSet(alarmService, geofenceService, this);
controls.add(reminderControlSet);
controlSetMap.put(getString(R.string.TEA_ctrl_reminders_pref), reminderControlSet);
@ -921,6 +920,13 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
log.error("Invalid timestamp");
}
return;
} else if (requestCode == ReminderControlSet.REQUEST_NEW_ALARM && resultCode == Activity.RESULT_OK) {
long timestamp = data.getLongExtra(DateAndTimePickerActivity.EXTRA_TIMESTAMP, 0L);
if (timestamp > 0) {
reminderControlSet.addAlarmRow(timestamp);
} else {
log.error("Invalid timestamp");
}
} else if (editNotes != null && editNotes.activityResult(requestCode, resultCode, data)) {
return;
} else if (requestCode == REQUEST_CODE_RECORD && resultCode == Activity.RESULT_OK) {

@ -5,7 +5,6 @@
*/
package com.todoroo.astrid.ui;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
@ -23,12 +22,10 @@ import com.todoroo.astrid.helper.TaskEditControlSetBase;
import org.joda.time.DateTime;
import org.tasks.R;
import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.dialogs.DateAndTimePickerDialog;
import java.util.Date;
import static org.tasks.date.DateTimeUtils.newDate;
import static org.tasks.date.DateTimeUtils.newDateTime;
/**
* Control set for specifying when a task should be hidden

@ -5,6 +5,7 @@
*/
package com.todoroo.astrid.ui;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@ -28,7 +29,7 @@ import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tasks.R;
import org.tasks.dialogs.DateAndTimePickerDialog;
import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.dialogs.LocationPickerDialog;
import org.tasks.location.Geofence;
import org.tasks.location.GeofenceService;
@ -53,6 +54,8 @@ public class ReminderControlSet extends TaskEditControlSetBase implements Adapte
private static final Logger log = LoggerFactory.getLogger(ReminderControlSet.class);
private static final String FRAG_TAG_LOCATION_PICKER = "frag_tag_location_picker";
public static final int REQUEST_NEW_ALARM = 12152;
private Spinner mode;
private Spinner addSpinner;
private TextView modeDisplay;
@ -95,32 +98,24 @@ public class ReminderControlSet extends TaskEditControlSetBase implements Adapte
}
private void addNewAlarm() {
pickNewAlarm(newDateTime().withMillisOfDay(0), new DateAndTimePickerDialog.OnDateTimePicked() {
@Override
public void onDateTimePicked(DateTime dateTime) {
addAlarmRow(dateTime.getMillis());
}
});
}
private void pickNewAlarm(DateTime initial, DateAndTimePickerDialog.OnDateTimePicked onDateTimePicked) {
DateAndTimePickerDialog.dateAndTimePickerDialog(taskEditFragment.getFragmentManager(),
taskEditFragment.getActivity(), initial, onDateTimePicked, null);
taskEditFragment.startActivityForResult(new Intent(taskEditFragment.getActivity(), DateAndTimePickerActivity.class) {{
putExtra(DateAndTimePickerActivity.EXTRA_TIMESTAMP, newDateTime().withMillisOfDay(0).getMillis());
}}, REQUEST_NEW_ALARM);
}
private void addAlarmRow(final Long timestamp) {
public void addAlarmRow(final Long timestamp) {
final View alertItem = addAlarmRow(getDisplayString(timestamp), timestamp, null);
TextView display = (TextView) alertItem.findViewById(R.id.alarm_string);
display.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
pickNewAlarm(newDateTime(timestamp), new DateAndTimePickerDialog.OnDateTimePicked() {
@Override
public void onDateTimePicked(DateTime dateTime) {
long millis = dateTime.getMillis();
addAlarmRow(alertItem, getDisplayString(millis), millis, null);
}
});
// pickNewAlarm(newDateTime(timestamp), new DateAndTimePickerDialog.OnDateTimePicked() {
// @Override
// public void onDateTimePicked(DateTime dateTime) {
// long millis = dateTime.getMillis();
// addAlarmRow(alertItem, getDisplayString(millis), millis, null);
// }
// });
}
});
}

@ -1,70 +0,0 @@
package org.tasks.dialogs;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v4.app.FragmentManager;
import android.text.format.DateFormat;
import com.fourmob.datetimepicker.date.DatePickerDialog;
import com.sleepbot.datetimepicker.time.RadialPickerLayout;
import com.sleepbot.datetimepicker.time.TimePickerDialog;
import org.joda.time.DateTime;
import static org.tasks.date.DateTimeUtils.newDateTime;
public class DateAndTimePickerDialog {
public interface OnDatePicked {
void onDatePicked(DateTime date);
}
public interface OnTimePicked {
void onTimePicked(int millisOfDay);
}
public interface OnDateTimePicked {
void onDateTimePicked(DateTime dateTime);
}
private static final String FRAG_TAG_DATE_PICKER = "frag_tag_date_picker";
private static final String FRAG_TAG_TIME_PICKER = "frag_tag_time_picker";
public static void datePickerDialog(FragmentManager fragmentManager, DateTime initial, final OnDatePicked onDatePicked, DialogInterface.OnDismissListener dismissed) {
MyDatePickerDialog dialog = new MyDatePickerDialog();
dialog.initialize(new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
onDatePicked.onDatePicked(newDateTime().withYear(year).withMonthOfYear(month + 1).withDayOfMonth(day).withMillisOfDay(0));
}
}, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth(), false);
dialog.setOnDismissListener(dismissed);
dialog.show(fragmentManager, FRAG_TAG_DATE_PICKER);
}
public static void timePickerDialog(FragmentManager fragmentManager, Context context, DateTime initial, final OnTimePicked onTimePicked, DialogInterface.OnDismissListener dismissed) {
MyTimePickerDialog dialog = new MyTimePickerDialog();
dialog.initialize(new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(RadialPickerLayout radialPickerLayout, int hours, int minutes) {
onTimePicked.onTimePicked(newDateTime().withMillisOfDay(0).withHourOfDay(hours).withMinuteOfHour(minutes).getMillisOfDay());
}
}, initial.getHourOfDay(), initial.getMinuteOfHour(), DateFormat.is24HourFormat(context), false);
dialog.setOnDismissListener(dismissed);
dialog.show(fragmentManager, FRAG_TAG_TIME_PICKER);
}
public static void dateAndTimePickerDialog(final FragmentManager fragmentManager, final Context context, final DateTime dateTime, final OnDateTimePicked dateTimePicked, final DialogInterface.OnDismissListener dismissed) {
datePickerDialog(fragmentManager, dateTime, new OnDatePicked() {
@Override
public void onDatePicked(final DateTime date) {
timePickerDialog(fragmentManager, context, dateTime, new OnTimePicked() {
@Override
public void onTimePicked(int millisOfDay) {
dateTimePicked.onDateTimePicked(date.withMillisOfDay(millisOfDay));
}
}, dismissed);
}
}, dismissed);
}
}
Loading…
Cancel
Save