Search in sources :

Example 1 with LocationBasedReminder

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());
}
Also used : LocationBasedReminder(ve.com.abicelis.remindy.model.reminder.LocationBasedReminder) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) Place(ve.com.abicelis.remindy.model.Place)

Example 2 with LocationBasedReminder

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();
}
Also used : LocationBasedReminder(ve.com.abicelis.remindy.model.reminder.LocationBasedReminder) Bundle(android.os.Bundle)

Example 3 with LocationBasedReminder

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;
}
Also used : ContentValues(android.content.ContentValues) OneTimeReminder(ve.com.abicelis.remindy.model.reminder.OneTimeReminder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) LocationBasedReminder(ve.com.abicelis.remindy.model.reminder.LocationBasedReminder) RepeatingReminder(ve.com.abicelis.remindy.model.reminder.RepeatingReminder) CouldNotInsertDataException(ve.com.abicelis.remindy.exception.CouldNotInsertDataException)

Example 4 with LocationBasedReminder

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;
}
Also used : CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) RepeatingReminder(ve.com.abicelis.remindy.model.reminder.RepeatingReminder) Reminder(ve.com.abicelis.remindy.model.reminder.Reminder) LocationBasedReminder(ve.com.abicelis.remindy.model.reminder.LocationBasedReminder) OneTimeReminder(ve.com.abicelis.remindy.model.reminder.OneTimeReminder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) LocationBasedReminder(ve.com.abicelis.remindy.model.reminder.LocationBasedReminder) PlaceNotFoundException(ve.com.abicelis.remindy.exception.PlaceNotFoundException) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException) Cursor(android.database.Cursor)

Example 5 with LocationBasedReminder

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());
}
Also used : LocationBasedReminder(ve.com.abicelis.remindy.model.reminder.LocationBasedReminder)

Aggregations

LocationBasedReminder (ve.com.abicelis.remindy.model.reminder.LocationBasedReminder)5 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 OneTimeReminder (ve.com.abicelis.remindy.model.reminder.OneTimeReminder)2 RepeatingReminder (ve.com.abicelis.remindy.model.reminder.RepeatingReminder)2 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)1 Bundle (android.os.Bundle)1 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)1 CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)1 CouldNotInsertDataException (ve.com.abicelis.remindy.exception.CouldNotInsertDataException)1 PlaceNotFoundException (ve.com.abicelis.remindy.exception.PlaceNotFoundException)1 Place (ve.com.abicelis.remindy.model.Place)1 Reminder (ve.com.abicelis.remindy.model.reminder.Reminder)1