Search in sources :

Example 1 with OneTimeReminder

use of ve.com.abicelis.remindy.model.reminder.OneTimeReminder in project Remindy by abicelis.

the class ProgrammedOneTimeTaskViewHolder method setData.

public void setData(HomeAdapter adapter, Fragment fragment, Task current, int position, boolean isSelected, boolean nextItemIsATask) {
    mAdapter = adapter;
    mFragment = fragment;
    mCurrent = current;
    mReminderPosition = position;
    mCategoryIcon.setImageResource(mCurrent.getCategory().getIconRes());
    mContainer.setBackgroundColor((isSelected ? ContextCompat.getColor(fragment.getActivity(), R.color.gray_300) : Color.TRANSPARENT));
    mAttachmentList.setColorFilter(ContextCompat.getColor(mFragment.getActivity(), (hasAttachmentsOfType(AttachmentType.LIST) ? R.color.icons_enabled : R.color.icons_disabled)));
    mAttachmentLink.setColorFilter(ContextCompat.getColor(mFragment.getActivity(), (hasAttachmentsOfType(AttachmentType.LINK) ? R.color.icons_enabled : R.color.icons_disabled)));
    mAttachmentAudio.setColorFilter(ContextCompat.getColor(mFragment.getActivity(), (hasAttachmentsOfType(AttachmentType.AUDIO) ? R.color.icons_enabled : R.color.icons_disabled)));
    mAttachmentImage.setColorFilter(ContextCompat.getColor(mFragment.getActivity(), (hasAttachmentsOfType(AttachmentType.IMAGE) ? R.color.icons_enabled : R.color.icons_disabled)));
    mAttachmentText.setColorFilter(ContextCompat.getColor(mFragment.getActivity(), (hasAttachmentsOfType(AttachmentType.TEXT) ? R.color.icons_enabled : R.color.icons_disabled)));
    mTitle.setText(mCurrent.getTitle());
    if (!mCurrent.getDescription().isEmpty())
        mDescription.setText(mCurrent.getDescription());
    else
        mDescription.setText("");
    if (current.getReminderType() == ReminderType.ONE_TIME && current.getReminder() != null) {
        DateFormat df = SharedPreferenceUtil.getDateFormat(mFragment.getActivity());
        mDate.setText(df.formatCalendar(((OneTimeReminder) current.getReminder()).getDate()));
        mTime.setText(((OneTimeReminder) current.getReminder()).getTime().toString());
    } else {
        mDate.setText("-");
        mTime.setText("-");
    }
    mItemDecoration.setVisibility(nextItemIsATask ? View.VISIBLE : View.INVISIBLE);
}
Also used : OneTimeReminder(ve.com.abicelis.remindy.model.reminder.OneTimeReminder) DateFormat(ve.com.abicelis.remindy.enums.DateFormat)

Example 2 with OneTimeReminder

use of ve.com.abicelis.remindy.model.reminder.OneTimeReminder in project Remindy by abicelis.

the class RemindyDAO method getOneTimeReminderFromCursor.

private OneTimeReminder getOneTimeReminderFromCursor(Cursor cursor) {
    int id = cursor.getInt(cursor.getColumnIndex(RemindyContract.OneTimeReminderTable._ID));
    int taskId = cursor.getInt(cursor.getColumnIndex(RemindyContract.OneTimeReminderTable.COLUMN_NAME_TASK_FK.getName()));
    Calendar date = Calendar.getInstance();
    date.setTimeInMillis(cursor.getLong(cursor.getColumnIndex(RemindyContract.OneTimeReminderTable.COLUMN_NAME_DATE.getName())));
    Time time = new Time(cursor.getInt(cursor.getColumnIndex(RemindyContract.OneTimeReminderTable.COLUMN_NAME_TIME.getName())));
    time.setDisplayTimeFormat(SharedPreferenceUtil.getTimeFormat(mContext));
    return new OneTimeReminder(id, taskId, date, time);
}
Also used : OneTimeReminder(ve.com.abicelis.remindy.model.reminder.OneTimeReminder) Calendar(java.util.Calendar) Time(ve.com.abicelis.remindy.model.Time)

Example 3 with OneTimeReminder

use of ve.com.abicelis.remindy.model.reminder.OneTimeReminder 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 OneTimeReminder

use of ve.com.abicelis.remindy.model.reminder.OneTimeReminder in project Remindy by abicelis.

the class TaskActionsIntentService method onHandleIntent.

@Override
protected void onHandleIntent(@Nullable Intent intent) {
    if (intent == null || intent.getAction() == null)
        return;
    if (intent.getAction().equals(ACTION_SET_TASK_DONE)) {
        int taskId = intent.getIntExtra(PARAM_TASK_ID, -1);
        if (taskId != -1) {
            // Dismiss the notification
            NotificationManager mNotifyMgr = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
            mNotifyMgr.cancel(taskId);
            RemindyDAO dao = new RemindyDAO(getApplicationContext());
            try {
                Task task = dao.getTask(taskId);
                task.setDoneDate(CalendarUtil.getNewInstanceZeroedCalendar());
                task.setStatus(TaskStatus.DONE);
                dao.updateTask(task);
            } catch (CouldNotGetDataException | CouldNotUpdateDataException e) {
                Toast.makeText(this, getResources().getString(R.string.task_actions_service_could_not_set_done), Toast.LENGTH_SHORT).show();
            }
        }
    } else if (intent.getAction().equals(ACTION_POSTPONE_TASK)) {
        int taskId = intent.getIntExtra(PARAM_TASK_ID, -1);
        if (taskId != -1) {
            // Dismiss the notification
            NotificationManager mNotifyMgr = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
            mNotifyMgr.cancel(taskId);
            RemindyDAO dao = new RemindyDAO(getApplicationContext());
            try {
                Task task = dao.getTask(taskId);
                Time time;
                switch(task.getReminderType()) {
                    case REPEATING:
                        time = ((RepeatingReminder) task.getReminder()).getTime();
                        break;
                    case ONE_TIME:
                        time = ((OneTimeReminder) task.getReminder()).getTime();
                        break;
                    default:
                        // TODO: Show some kind of error?
                        return;
                }
                int timeInMinutes = time.getTimeInMinutes();
                timeInMinutes += POSTPONE_MINUTES;
                // Set max per day to 24:59:00
                timeInMinutes = (timeInMinutes >= 1440 ? 1339 : timeInMinutes);
                time.setTimeInMinutes(timeInMinutes);
                dao.updateTask(task);
                // Remove task from triggeredTasks list
                SharedPreferenceUtil.removeIdFromTriggeredTasks(getApplicationContext(), task.getId());
                // Update alarms
                AlarmManagerUtil.updateAlarms(getApplicationContext());
            } catch (CouldNotGetDataException | CouldNotUpdateDataException e) {
                Toast.makeText(this, getResources().getString(R.string.task_actions_service_could_not_set_done), Toast.LENGTH_SHORT).show();
            }
        }
    }
}
Also used : CouldNotUpdateDataException(ve.com.abicelis.remindy.exception.CouldNotUpdateDataException) Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) NotificationManager(android.app.NotificationManager) OneTimeReminder(ve.com.abicelis.remindy.model.reminder.OneTimeReminder) RepeatingReminder(ve.com.abicelis.remindy.model.reminder.RepeatingReminder) Time(ve.com.abicelis.remindy.model.Time) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO)

Example 5 with OneTimeReminder

use of ve.com.abicelis.remindy.model.reminder.OneTimeReminder in project Remindy by abicelis.

the class TriggerTaskNotificationReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "TriggerTaskNotificationReceiver");
    // Get TASK_ID_EXTRA
    int taskId;
    try {
        taskId = intent.getIntExtra(TASK_ID_EXTRA, -1);
    } catch (Exception e) {
        taskId = -1;
    }
    if (taskId != -1) {
        Task task;
        try {
            task = new RemindyDAO(context).getTask(taskId);
        } catch (CouldNotGetDataException e) {
            // TODO: Show some kind of error here
            return;
        }
        if (task != null) {
            Log.d(TAG, "Triggering task ID " + taskId);
            String triggerTime;
            switch(task.getReminderType()) {
                case ONE_TIME:
                    triggerTime = ((OneTimeReminder) task.getReminder()).getTime().toString();
                    break;
                case REPEATING:
                    triggerTime = ((RepeatingReminder) task.getReminder()).getTime().toString();
                    break;
                default:
                    // TODO: Show some kind of error here
                    return;
            }
            String contentTitle = String.format(Locale.getDefault(), context.getResources().getString(R.string.notification_service_normal_title), task.getTitle());
            int triggerMinutesBeforeNotification = SharedPreferenceUtil.getTriggerMinutesBeforeNotification(context).getMinutes();
            String contentText = String.format(Locale.getDefault(), context.getResources().getString(R.string.notification_service_normal_text), triggerMinutesBeforeNotification, triggerTime);
            NotificationUtil.displayNotification(context, task, contentTitle, contentText);
            // Add task to triggeredTasks list
            List<Integer> triggeredTasks = SharedPreferenceUtil.getTriggeredTaskList(context);
            triggeredTasks.add(task.getId());
            SharedPreferenceUtil.setTriggeredTaskList(triggeredTasks, context);
        }
    } else {
        Log.d(TAG, "TriggerTaskNotificationReceiver triggered with no TASK_ID_EXTRA!");
    }
    // Set next alarm
    AlarmManagerUtil.updateAlarms(context);
}
Also used : Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) OneTimeReminder(ve.com.abicelis.remindy.model.reminder.OneTimeReminder) RepeatingReminder(ve.com.abicelis.remindy.model.reminder.RepeatingReminder) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException)

Aggregations

OneTimeReminder (ve.com.abicelis.remindy.model.reminder.OneTimeReminder)8 RepeatingReminder (ve.com.abicelis.remindy.model.reminder.RepeatingReminder)6 Calendar (java.util.Calendar)3 CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)3 Task (ve.com.abicelis.remindy.model.Task)3 Time (ve.com.abicelis.remindy.model.Time)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)2 NotificationManager (android.app.NotificationManager)1 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)1 Bundle (android.os.Bundle)1 DateFormat (ve.com.abicelis.remindy.enums.DateFormat)1 CouldNotInsertDataException (ve.com.abicelis.remindy.exception.CouldNotInsertDataException)1 CouldNotUpdateDataException (ve.com.abicelis.remindy.exception.CouldNotUpdateDataException)1 LocationBasedReminder (ve.com.abicelis.remindy.model.reminder.LocationBasedReminder)1 TaskTriggerViewModel (ve.com.abicelis.remindy.viewmodel.TaskTriggerViewModel)1