Search in sources :

Example 6 with Task

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

the class GeofenceNotificationIntentService method onHandleIntent.

@Override
protected void onHandleIntent(@Nullable Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        String errorMessage = GeofenceErrorMessages.getErrorString(this, geofencingEvent.getErrorCode());
        Log.e(TAG, errorMessage);
        return;
    }
    // Get the transition type.
    int geofenceTransition = geofencingEvent.getGeofenceTransition();
    // Log the transition type
    handleLogTransition(geofenceTransition);
    // Test that the reported transition was of interest.
    if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT || //|| geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER   //Skipping this transition because of alert spam issues
    geofenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) {
        for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
            List<Task> tasks = new ArrayList<>();
            try {
                tasks = new RemindyDAO(this).getLocationBasedTasksAssociatedWithPlace(Integer.valueOf(geofence.getRequestId()), geofenceTransition);
            } catch (CouldNotGetDataException e) {
            /* Do nothing */
            }
            if (tasks.size() > 0) {
                String notificationTitle = getGeofenceNotificationTitle(geofenceTransition, geofence);
                String notificationText = getGeofenceNotificationText(tasks);
                // Send notification and log the transition details.
                NotificationUtil.displayLocationBasedNotification(this, Integer.valueOf(geofence.getRequestId()), notificationTitle, notificationText, tasks);
                Log.i(TAG, notificationTitle + " " + notificationText);
            }
        }
    }
}
Also used : Task(ve.com.abicelis.remindy.model.Task) CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) ArrayList(java.util.ArrayList) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) GeofencingEvent(com.google.android.gms.location.GeofencingEvent) Geofence(com.google.android.gms.location.Geofence)

Example 7 with Task

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

the class TaskActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task);
    if (getIntent().hasExtra(TASK_TO_EDIT)) {
        mTask = (Task) getIntent().getSerializableExtra(TASK_TO_EDIT);
        editingTask = true;
    } else {
        mTask = new Task();
        editingTask = false;
    }
    mContainer = (LinearLayout) findViewById(R.id.activity_task_container);
    mViewpager = (ViewPager) findViewById(R.id.activity_task_viewpager);
    mTabLayout = (TabLayout) findViewById(R.id.activity_task_tab_layout);
    setUpToolbar();
    setupViewPagerAndTabLayout();
    mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
    mGoogleApiClient.connect();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Task(ve.com.abicelis.remindy.model.Task)

Example 8 with Task

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

the class TaskSortingUtil method generateProgrammedTaskHeaderList.

/* Programmed Tasks */
public ArrayList<TaskViewModel> generateProgrammedTaskHeaderList(List<Task> tasks, TaskSortType sortType, Resources resources) throws InvalidClassException {
    ArrayList<TaskViewModel> result = new ArrayList<>();
    clearTaskBuckets();
    if (sortType == TaskSortType.DATE) {
        //TODO: this comparator needs to take into account the RepeatingReminder's "next" event date to sort Tasks with RepeatingReminders properly
        Collections.sort(tasks, new TasksByReminderDateComparator());
        for (Task current : tasks) {
            if (current.getReminderType() == null)
                throw new NullPointerException("NULL ReminderType passed into TaskSortingUtil.generateProgrammedTaskHeaderList()");
            switch(current.getReminderType()) {
                case NONE:
                    throw new InvalidClassException("Wrong ReminderType passed into TaskSortingUtil.generateProgrammedTaskHeaderList()");
                case LOCATION_BASED:
                    tasksLocationBased.add(current);
                    break;
                case ONE_TIME:
                    insertProgrammedTaskIntoBucket(current, TaskUtil.getReminderEndCalendar(current.getReminder()));
                    break;
                case REPEATING:
                    insertProgrammedTaskIntoBucket(current, TaskUtil.getRepeatingReminderNextCalendar(((RepeatingReminder) current.getReminder())));
                    break;
                default:
                    throw new InvalidParameterException("Unhandled ReminderType passed into TaskSortingUtil.generateProgrammedTaskHeaderList()");
            }
        }
        if (tasksOverdue.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_overdue), true));
            dumpTaskBucketIntoViewModelList(tasksOverdue, result);
        }
        if (tasksLocationBased.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_location_based), false));
            dumpTaskBucketIntoViewModelList(tasksLocationBased, result);
        }
        if (tasksToday.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_today), false));
            dumpTaskBucketIntoViewModelList(tasksToday, result);
        }
        if (tasksTomorrow.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_tomorrow), false));
            dumpTaskBucketIntoViewModelList(tasksTomorrow, result);
        }
        if (tasksThisWeek.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_week), false));
            dumpTaskBucketIntoViewModelList(tasksThisWeek, result);
        }
        if (tasksNextWeek.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_next_week), false));
            dumpTaskBucketIntoViewModelList(tasksNextWeek, result);
        }
        if (tasksThisMonth.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_month), false));
            dumpTaskBucketIntoViewModelList(tasksThisMonth, result);
        }
        if (tasksNextMonth.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_next_month), false));
            dumpTaskBucketIntoViewModelList(tasksNextMonth, result);
        }
        if (tasksThisYear.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_year), false));
            dumpTaskBucketIntoViewModelList(tasksThisYear, result);
        }
        if (tasksNextYear.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_next_year), false));
            dumpTaskBucketIntoViewModelList(tasksNextYear, result);
        }
        if (tasksFuture.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_future), false));
            dumpTaskBucketIntoViewModelList(tasksFuture, result);
        }
    } else if (sortType == TaskSortType.PLACE) {
        handleSortingByPlace(tasks, result, resources);
    }
    return result;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Task(ve.com.abicelis.remindy.model.Task) TaskViewModel(ve.com.abicelis.remindy.viewmodel.TaskViewModel) TasksByReminderDateComparator(ve.com.abicelis.remindy.model.TasksByReminderDateComparator) InvalidClassException(java.io.InvalidClassException) ArrayList(java.util.ArrayList)

Example 9 with Task

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

the class TaskSortingUtil method generateDoneTaskHeaderList.

/* Done Tasks */
public ArrayList<TaskViewModel> generateDoneTaskHeaderList(List<Task> tasks, TaskSortType sortType, Resources resources) throws InvalidClassException {
    ArrayList<TaskViewModel> result = new ArrayList<>();
    clearTaskBuckets();
    if (sortType == TaskSortType.DATE) {
        //Sorting by doneDate!
        Collections.sort(tasks, new TasksByDoneDateComparator());
        for (Task current : tasks) {
            if (current.getReminderType() == null)
                throw new NullPointerException("NULL ReminderType passed into TaskSortingUtil.generateProgrammedTaskHeaderList()");
            insertDoneTaskIntoBucket(current, current.getDoneDate());
        }
        if (tasksToday.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_today), false));
            dumpTaskBucketIntoViewModelList(tasksToday, result);
        }
        if (tasksYesterday.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_yesterday), false));
            dumpTaskBucketIntoViewModelList(tasksYesterday, result);
        }
        if (tasksThisWeek.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_week), false));
            dumpTaskBucketIntoViewModelList(tasksThisWeek, result);
        }
        if (tasksLastWeek.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_last_week), false));
            dumpTaskBucketIntoViewModelList(tasksLastWeek, result);
        }
        if (tasksThisMonth.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_month), false));
            dumpTaskBucketIntoViewModelList(tasksThisMonth, result);
        }
        if (tasksLastMonth.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_last_month), false));
            dumpTaskBucketIntoViewModelList(tasksLastMonth, result);
        }
        if (tasksThisYear.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_this_year), false));
            dumpTaskBucketIntoViewModelList(tasksThisYear, result);
        }
        if (tasksLastYear.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_last_year), false));
            dumpTaskBucketIntoViewModelList(tasksLastYear, result);
        }
        if (tasksPast.size() > 0) {
            result.add(new TaskViewModel(resources.getString(R.string.task_header_past), false));
            dumpTaskBucketIntoViewModelList(tasksPast, result);
        }
    } else if (sortType == TaskSortType.PLACE) {
        handleSortingByPlace(tasks, result, resources);
    }
    return result;
}
Also used : Task(ve.com.abicelis.remindy.model.Task) TaskViewModel(ve.com.abicelis.remindy.viewmodel.TaskViewModel) TasksByDoneDateComparator(ve.com.abicelis.remindy.model.TasksByDoneDateComparator) ArrayList(java.util.ArrayList)

Example 10 with Task

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

the class NotificationUtil method displayLocationBasedNotification.

public static void displayLocationBasedNotification(Context context, int notificationId, String contentTitle, String contentText, List<Task> triggeredTasks) {
    NotificationCompat.Builder mBuilder;
    mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.icon_remindy_notification_small).setColor(ContextCompat.getColor(context, R.color.primary)).setVibrate(new long[] { 50, 50, 200, 50 }).setLights(ContextCompat.getColor(context, R.color.primary), 3000, 3000).setSound(Settings.System.DEFAULT_NOTIFICATION_URI).setContentTitle(contentTitle).setContentText(contentText).setAutoCancel(true).setPriority(Notification.PRIORITY_HIGH);
    if (triggeredTasks.size() == 1) {
        //Intent for "DONE" button on BigView style
        Intent setTaskDoneIntent = new Intent(context, TaskActionsIntentService.class);
        setTaskDoneIntent.setAction(TaskActionsIntentService.ACTION_SET_TASK_DONE);
        setTaskDoneIntent.putExtra(TaskActionsIntentService.PARAM_TASK_ID, triggeredTasks.get(0).getId());
        PendingIntent setTaskDonePendingIntent = PendingIntent.getService(context, triggeredTasks.get(0).getId(), setTaskDoneIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        //Intent for clicking notification
        Intent openTaskIntent = new Intent(context, TaskDetailActivity.class);
        openTaskIntent.putExtra(TASK_ID_TO_DISPLAY, triggeredTasks.get(0).getId());
        //openTaskIntent.setAction(String.valueOf(task.getId()));
        //openTaskIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        //openTaskIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        // Adds the back stack
        stackBuilder.addParentStack(TaskDetailActivity.class);
        // Adds the Intent to the top of the stack
        stackBuilder.addNextIntent(openTaskIntent);
        // Gets a PendingIntent containing the entire back stack
        PendingIntent openTaskPendingIntent = stackBuilder.getPendingIntent(triggeredTasks.get(0).getId(), PendingIntent.FLAG_UPDATE_CURRENT);
        //Add pendingIntent to notification
        mBuilder.setContentIntent(openTaskPendingIntent);
        mBuilder.addAction(R.drawable.icon_notification_done, context.getResources().getString(R.string.notification_big_view_set_done), setTaskDonePendingIntent);
        //Set BigView
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
    } else {
        //Intent for clicking notification
        Intent openHomeIntent = new Intent(context, HomeActivity.class);
        PendingIntent openHomePendingItent = PendingIntent.getActivity(context, Integer.MAX_VALUE, openHomeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        //InboxStyle BigView (Multiline!)
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle(contentTitle);
        for (Task task : triggeredTasks) inboxStyle.addLine("- " + task.getTitle());
        //Add pendingIntent to notification
        mBuilder.setContentIntent(openHomePendingItent);
        //Set BigView
        mBuilder.setStyle(inboxStyle);
    }
    // Get an instance of the NotificationManager service
    NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    // Builds the notification and issues it.
    mNotifyMgr.notify(triggeredTasks.get(0).getId(), mBuilder.build());
}
Also used : Task(ve.com.abicelis.remindy.model.Task) NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder)

Aggregations

Task (ve.com.abicelis.remindy.model.Task)21 CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)12 ArrayList (java.util.ArrayList)10 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)9 TaskViewModel (ve.com.abicelis.remindy.viewmodel.TaskViewModel)8 Cursor (android.database.Cursor)7 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)4 CouldNotDeleteDataException (ve.com.abicelis.remindy.exception.CouldNotDeleteDataException)3 OneTimeReminder (ve.com.abicelis.remindy.model.reminder.OneTimeReminder)3 RepeatingReminder (ve.com.abicelis.remindy.model.reminder.RepeatingReminder)3 TaskSortingUtil (ve.com.abicelis.remindy.util.sorting.TaskSortingUtil)3 NotificationManager (android.app.NotificationManager)2 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)2 Calendar (java.util.Calendar)2 CouldNotUpdateDataException (ve.com.abicelis.remindy.exception.CouldNotUpdateDataException)2 Time (ve.com.abicelis.remindy.model.Time)2 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1