handle repetition spinner
This commit is contained in:
parent
4cbccaca5c
commit
58066fc949
3 changed files with 55 additions and 7 deletions
|
@ -131,7 +131,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
final String description = cursor.getString(cursor.getColumnIndex(COL_DESCRIPTION));
|
||||
final int reminderMinutes = cursor.getInt(cursor.getColumnIndex(COL_REMINDER_MINUTES));
|
||||
cursor.close();
|
||||
return new Event(id, startTS, endTS, title, description, reminderMinutes);
|
||||
return new Event(id, startTS, endTS, title, description, reminderMinutes, 0);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -177,7 +177,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
final String title = cursor.getString(cursor.getColumnIndex(COL_TITLE));
|
||||
final String description = cursor.getString(cursor.getColumnIndex(COL_DESCRIPTION));
|
||||
final int reminderMinutes = cursor.getInt(cursor.getColumnIndex(COL_REMINDER_MINUTES));
|
||||
events.add(new Event(id, startTS, endTS, title, description, reminderMinutes));
|
||||
events.add(new Event(id, startTS, endTS, title, description, reminderMinutes, 0));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
|
|
|
@ -34,6 +34,10 @@ import butterknife.OnClick;
|
|||
import butterknife.OnItemSelected;
|
||||
|
||||
public class EventActivity extends SimpleActivity implements DBHelper.DBOperationsListener {
|
||||
private static final int DAILY = 86400;
|
||||
private static final int WEEKLY = 604800;
|
||||
private static final int YEARLY = 31536000;
|
||||
|
||||
@BindView(R.id.event_start_date) TextView mStartDate;
|
||||
@BindView(R.id.event_start_time) TextView mStartTime;
|
||||
@BindView(R.id.event_end_date) TextView mEndDate;
|
||||
|
@ -42,6 +46,7 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
|||
@BindView(R.id.event_description) EditText mDescriptionET;
|
||||
@BindView(R.id.event_reminder_other) EditText mReminderOtherET;
|
||||
@BindView(R.id.event_reminder) AppCompatSpinner mReminder;
|
||||
@BindView(R.id.event_repetition) AppCompatSpinner mRepetition;
|
||||
|
||||
private static DateTime mEventStartDateTime;
|
||||
private static DateTime mEventEndDateTime;
|
||||
|
@ -79,6 +84,7 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
|||
updateEndDate();
|
||||
updateEndTime();
|
||||
setupReminder();
|
||||
setupRepetition();
|
||||
|
||||
mWasEndDateSet = (event != null);
|
||||
mWasEndTimeSet = (event != null);
|
||||
|
@ -124,6 +130,23 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
|||
}
|
||||
}
|
||||
|
||||
private void setupRepetition() {
|
||||
switch (mEvent.getRepeatInterval()) {
|
||||
case DAILY:
|
||||
mReminder.setSelection(1);
|
||||
break;
|
||||
case WEEKLY:
|
||||
mReminder.setSelection(2);
|
||||
break;
|
||||
case YEARLY:
|
||||
mReminder.setSelection(3);
|
||||
break;
|
||||
default:
|
||||
mReminder.setSelection(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@OnItemSelected(R.id.event_reminder)
|
||||
public void handleReminder() {
|
||||
if (!mWasReminderInit) {
|
||||
|
@ -190,12 +213,12 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
|||
|
||||
final DBHelper dbHelper = DBHelper.newInstance(getApplicationContext(), this);
|
||||
final String description = mDescriptionET.getText().toString().trim();
|
||||
final int reminderMinutes = getReminderMinutes();
|
||||
mEvent.setStartTS(startTS);
|
||||
mEvent.setEndTS(endTS);
|
||||
mEvent.setTitle(title);
|
||||
mEvent.setDescription(description);
|
||||
mEvent.setReminderMinutes(reminderMinutes);
|
||||
mEvent.setReminderMinutes(getReminderMinutes());
|
||||
mEvent.setRepeatInterval(getRepeatInterval());
|
||||
if (mEvent.getId() == 0) {
|
||||
dbHelper.insert(mEvent);
|
||||
} else {
|
||||
|
@ -218,6 +241,19 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
|||
}
|
||||
}
|
||||
|
||||
private int getRepeatInterval() {
|
||||
switch (mRepetition.getSelectedItemPosition()) {
|
||||
case 1:
|
||||
return DAILY;
|
||||
case 2:
|
||||
return WEEKLY;
|
||||
case 3:
|
||||
return YEARLY;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStartDate() {
|
||||
mStartDate.setText(Formatter.getEventDate(getApplicationContext(), mEventStartDateTime));
|
||||
}
|
||||
|
|
|
@ -3,13 +3,14 @@ package com.simplemobiletools.calendar.models;
|
|||
import java.io.Serializable;
|
||||
|
||||
public class Event implements Serializable {
|
||||
private static final long serialVersionUID = -32456795132354616L;
|
||||
private static final long serialVersionUID = -32456795132344616L;
|
||||
private int mId;
|
||||
private int mStartTS;
|
||||
private int mEndTS;
|
||||
private String mTitle;
|
||||
private String mDescription;
|
||||
private int mReminderMinutes;
|
||||
private int mRepeatInterval;
|
||||
|
||||
public Event() {
|
||||
mId = 0;
|
||||
|
@ -18,15 +19,17 @@ public class Event implements Serializable {
|
|||
mTitle = "";
|
||||
mDescription = "";
|
||||
mReminderMinutes = 0;
|
||||
mRepeatInterval = 0;
|
||||
}
|
||||
|
||||
public Event(int id, int startTS, int endTS, String title, String description, int reminerMinutes) {
|
||||
public Event(int id, int startTS, int endTS, String title, String description, int reminderMinutes, int repeatInterval) {
|
||||
mId = id;
|
||||
mStartTS = startTS;
|
||||
mEndTS = endTS;
|
||||
mTitle = title;
|
||||
mDescription = description;
|
||||
mReminderMinutes = reminerMinutes;
|
||||
mReminderMinutes = reminderMinutes;
|
||||
mRepeatInterval = repeatInterval;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
@ -77,6 +80,14 @@ public class Event implements Serializable {
|
|||
mReminderMinutes = reminderMinutes;
|
||||
}
|
||||
|
||||
public int getRepeatInterval() {
|
||||
return mRepeatInterval;
|
||||
}
|
||||
|
||||
public void setRepeatInterval(int repeatInterval) {
|
||||
mRepeatInterval = repeatInterval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Event {" +
|
||||
|
@ -86,6 +97,7 @@ public class Event implements Serializable {
|
|||
", title=" + getTitle() +
|
||||
", description=" + getDescription() +
|
||||
", reminderMinutes=" + getReminderMinutes() +
|
||||
", repeatInterval=" + getRepeatInterval() +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue