use of ve.com.abicelis.remindy.model.reminder.LocationBasedReminder in project Remindy by abicelis.
the class EditLocationBasedReminderFragment method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
// If fragment was just called, expect a reminder at REMINDER_ARGUMENT
if (getArguments().containsKey(REMINDER_ARGUMENT))
mReminder = (LocationBasedReminder) getArguments().getSerializable(REMINDER_ARGUMENT);
else
Toast.makeText(getActivity(), getResources().getString(R.string.error_unexpected), Toast.LENGTH_SHORT).show();
mDao = new RemindyDAO(getActivity());
mPlaces = mDao.getPlaces();
// Set mReminder to the first place if empty
if (mReminder.getPlace() == null)
mReminder.setPlace(mPlaces.get(0));
for (Place p : mPlaces) mPlaceTypes.add(p.getAlias());
}
use of ve.com.abicelis.remindy.model.reminder.LocationBasedReminder in project Remindy by abicelis.
the class ReminderFragment method handleLocationBasedTaskReminderSelected.
private void handleLocationBasedTaskReminderSelected() {
Bundle bundle = new Bundle();
mReminder = (useReminderFlag ? mTask.getReminder() : new LocationBasedReminder());
mFragment = new EditLocationBasedReminderFragment();
bundle.putSerializable(EditLocationBasedReminderFragment.REMINDER_ARGUMENT, mReminder);
mFragment.setArguments(bundle);
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_reminder_reminder_placeholder, mFragment).commit();
}
use of ve.com.abicelis.remindy.model.reminder.LocationBasedReminder in project Remindy by abicelis.
the class RemindyDAO method insertReminderOfTask.
/**
* Inserts a new Reminder into the database.
* @param taskId The id of the Task associated to the Reminder
* @param reminder The Reminder to insert
*/
public long insertReminderOfTask(int taskId, Reminder reminder) throws CouldNotInsertDataException {
SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
ContentValues values;
String tableName;
reminder.setTaskId(taskId);
switch(reminder.getType()) {
case ONE_TIME:
values = getValuesFromOneTimeReminder((OneTimeReminder) reminder);
tableName = RemindyContract.OneTimeReminderTable.TABLE_NAME;
break;
case REPEATING:
values = getValuesFromRepeatingReminder((RepeatingReminder) reminder);
tableName = RemindyContract.RepeatingReminderTable.TABLE_NAME;
break;
case LOCATION_BASED:
values = getValuesFromLocationBasedReminder((LocationBasedReminder) reminder);
tableName = RemindyContract.LocationBasedReminderTable.TABLE_NAME;
break;
default:
throw new CouldNotInsertDataException("ReminderType is invalid. Type=" + reminder.getType());
}
long newRowId;
newRowId = db.insert(tableName, null, values);
if (newRowId == -1)
throw new CouldNotInsertDataException("There was a problem inserting the Reminder: " + reminder.toString());
return newRowId;
}
use of ve.com.abicelis.remindy.model.reminder.LocationBasedReminder in project Remindy by abicelis.
the class RemindyDAO method getReminderOfTask.
/**
* Returns a Reminder given its taskId and reminderType
* @param taskId The ID of the task
* @param reminderType The Type of reminder
*/
public Reminder getReminderOfTask(int taskId, @NonNull ReminderType reminderType) throws CouldNotGetDataException, SQLiteConstraintException {
SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
Reminder reminder;
String tableName, whereClause;
switch(reminderType) {
case ONE_TIME:
whereClause = RemindyContract.OneTimeReminderTable.COLUMN_NAME_TASK_FK.getName() + " =?";
tableName = RemindyContract.OneTimeReminderTable.TABLE_NAME;
break;
case REPEATING:
whereClause = RemindyContract.RepeatingReminderTable.COLUMN_NAME_TASK_FK.getName() + " =?";
tableName = RemindyContract.RepeatingReminderTable.TABLE_NAME;
break;
case LOCATION_BASED:
whereClause = RemindyContract.LocationBasedReminderTable.COLUMN_NAME_TASK_FK.getName() + " =?";
tableName = RemindyContract.LocationBasedReminderTable.TABLE_NAME;
break;
default:
throw new CouldNotGetDataException("ReminderType is invalid. Type=" + reminderType);
}
Cursor cursor = db.query(tableName, null, whereClause, new String[] { String.valueOf(taskId) }, null, null, null);
try {
if (cursor.getCount() == 0)
throw new CouldNotGetDataException("Specified Reminder not found in the database. Passed id=" + taskId);
if (cursor.getCount() > 1)
throw new SQLiteConstraintException("Database UNIQUE constraint failure, more than one Reminder found. Passed id=" + taskId);
cursor.moveToNext();
switch(reminderType) {
case ONE_TIME:
reminder = getOneTimeReminderFromCursor(cursor);
break;
case REPEATING:
reminder = getRepeatingReminderFromCursor(cursor);
break;
case LOCATION_BASED:
reminder = getLocationBasedReminderFromCursor(cursor);
int placeId = ((LocationBasedReminder) reminder).getPlaceId();
try {
((LocationBasedReminder) reminder).setPlace(getPlace(placeId));
} catch (PlaceNotFoundException | SQLiteConstraintException e) {
throw new CouldNotGetDataException("Error trying to get Place for Location-based Reminder", e);
}
break;
default:
throw new CouldNotGetDataException("ReminderType is invalid. Type=" + reminderType);
}
} finally {
cursor.close();
}
return reminder;
}
use of ve.com.abicelis.remindy.model.reminder.LocationBasedReminder in project Remindy by abicelis.
the class TasksByPlaceComparator method compare.
@Override
public int compare(Task o1, Task o2) {
if (o1.getReminder() == null || o1.getReminderType() != ReminderType.LOCATION_BASED)
return 1;
if (o2.getReminder() == null || o2.getReminderType() != ReminderType.LOCATION_BASED)
return -1;
LocationBasedReminder o1reminder = (LocationBasedReminder) o1.getReminder();
LocationBasedReminder o2reminder = (LocationBasedReminder) o2.getReminder();
return o1reminder.getPlace().getAlias().compareTo(o2reminder.getPlace().getAlias());
}
Aggregations