|
|
|
|
@ -11,11 +11,11 @@ import static com.todoroo.andlib.utility.DateUtilities.now;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import androidx.room.Dao;
|
|
|
|
|
import androidx.room.Insert;
|
|
|
|
|
import androidx.room.Query;
|
|
|
|
|
import androidx.room.Update;
|
|
|
|
|
import com.todoroo.andlib.data.Property;
|
|
|
|
|
import com.todoroo.andlib.sql.Criterion;
|
|
|
|
|
import com.todoroo.andlib.sql.Functions;
|
|
|
|
|
import com.todoroo.andlib.sql.Query;
|
|
|
|
|
import com.todoroo.astrid.api.Filter;
|
|
|
|
|
import com.todoroo.astrid.api.PermaSql;
|
|
|
|
|
import com.todoroo.astrid.data.Task;
|
|
|
|
|
@ -47,45 +47,43 @@ public abstract class TaskDao {
|
|
|
|
|
return needsRefresh(now());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
@Query(
|
|
|
|
|
"SELECT * FROM tasks WHERE completed = 0 AND deleted = 0 AND (hideUntil > :now OR dueDate > :now)")
|
|
|
|
|
abstract List<Task> needsRefresh(long now);
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query("SELECT * FROM tasks WHERE _id = :id LIMIT 1")
|
|
|
|
|
@Query("SELECT * FROM tasks WHERE _id = :id LIMIT 1")
|
|
|
|
|
public abstract Task fetch(long id);
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query("SELECT * FROM tasks WHERE _id IN (:taskIds)")
|
|
|
|
|
@Query("SELECT * FROM tasks WHERE _id IN (:taskIds)")
|
|
|
|
|
public abstract List<Task> fetch(List<Long> taskIds);
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query("SELECT COUNT(1) FROM tasks WHERE timerStart > 0 AND deleted = 0")
|
|
|
|
|
@Query("SELECT COUNT(1) FROM tasks WHERE timerStart > 0 AND deleted = 0")
|
|
|
|
|
public abstract int activeTimers();
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
"SELECT tasks.* FROM tasks INNER JOIN notification ON tasks._id = notification.task")
|
|
|
|
|
@Query("SELECT tasks.* FROM tasks INNER JOIN notification ON tasks._id = notification.task")
|
|
|
|
|
public abstract List<Task> activeNotifications();
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query("SELECT * FROM tasks WHERE remoteId = :remoteId")
|
|
|
|
|
@Query("SELECT * FROM tasks WHERE remoteId = :remoteId")
|
|
|
|
|
public abstract Task fetch(String remoteId);
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query("SELECT * FROM tasks WHERE completed = 0 AND deleted = 0")
|
|
|
|
|
@Query("SELECT * FROM tasks WHERE completed = 0 AND deleted = 0")
|
|
|
|
|
abstract List<Task> getActiveTasks();
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query("SELECT * FROM tasks WHERE hideUntil < (strftime('%s','now')*1000)")
|
|
|
|
|
@Query("SELECT * FROM tasks WHERE hideUntil < (strftime('%s','now')*1000)")
|
|
|
|
|
abstract List<Task> getVisibleTasks();
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
@Query(
|
|
|
|
|
"SELECT * FROM tasks WHERE remoteId IN (:remoteIds) "
|
|
|
|
|
+ "AND recurrence NOT NULL AND LENGTH(recurrence) > 0")
|
|
|
|
|
public abstract List<Task> getRecurringTasks(List<String> remoteIds);
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
"UPDATE tasks SET completed = :completionDate " + "WHERE remoteId = :remoteId")
|
|
|
|
|
@Query("UPDATE tasks SET completed = :completionDate " + "WHERE remoteId = :remoteId")
|
|
|
|
|
public abstract void setCompletionDate(String remoteId, long completionDate);
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query("UPDATE tasks SET snoozeTime = :millis WHERE _id in (:taskIds)")
|
|
|
|
|
@Query("UPDATE tasks SET snoozeTime = :millis WHERE _id in (:taskIds)")
|
|
|
|
|
public abstract void snooze(List<Long> taskIds, long millis);
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
@Query(
|
|
|
|
|
"SELECT tasks.* FROM tasks "
|
|
|
|
|
+ "LEFT JOIN google_tasks ON tasks._id = google_tasks.task "
|
|
|
|
|
+ "WHERE list_id IN (SELECT remote_id FROM google_task_lists WHERE account = :account)"
|
|
|
|
|
@ -93,37 +91,35 @@ public abstract class TaskDao {
|
|
|
|
|
+ "OR google_tasks.remote_id = '')")
|
|
|
|
|
public abstract List<Task> getGoogleTasksToPush(String account);
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
@Query(
|
|
|
|
|
"SELECT tasks.* FROM tasks "
|
|
|
|
|
+ "LEFT JOIN caldav_tasks ON tasks._id = caldav_tasks.task "
|
|
|
|
|
+ "WHERE caldav_tasks.calendar = :calendar "
|
|
|
|
|
+ "AND tasks.modified > caldav_tasks.last_sync")
|
|
|
|
|
public abstract List<Task> getCaldavTasksToPush(String calendar);
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
@Query(
|
|
|
|
|
"SELECT * FROM TASKS "
|
|
|
|
|
+ "WHERE completed = 0 AND deleted = 0 AND (notificationFlags > 0 OR notifications > 0)")
|
|
|
|
|
public abstract List<Task> getTasksWithReminders();
|
|
|
|
|
|
|
|
|
|
// --- SQL clause generators
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query("SELECT * FROM tasks")
|
|
|
|
|
@Query("SELECT * FROM tasks")
|
|
|
|
|
public abstract List<Task> getAll();
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
"SELECT calendarUri FROM tasks " + "WHERE calendarUri NOT NULL AND calendarUri != ''")
|
|
|
|
|
@Query("SELECT calendarUri FROM tasks " + "WHERE calendarUri NOT NULL AND calendarUri != ''")
|
|
|
|
|
public abstract List<String> getAllCalendarEvents();
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
"UPDATE tasks SET calendarUri = '' " + "WHERE calendarUri NOT NULL AND calendarUri != ''")
|
|
|
|
|
@Query("UPDATE tasks SET calendarUri = '' " + "WHERE calendarUri NOT NULL AND calendarUri != ''")
|
|
|
|
|
public abstract int clearAllCalendarEvents();
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
@Query(
|
|
|
|
|
"SELECT calendarUri FROM tasks "
|
|
|
|
|
+ "WHERE completed > 0 AND calendarUri NOT NULL AND calendarUri != ''")
|
|
|
|
|
public abstract List<String> getCompletedCalendarEvents();
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
@Query(
|
|
|
|
|
"UPDATE tasks SET calendarUri = '' "
|
|
|
|
|
+ "WHERE completed > 0 AND calendarUri NOT NULL AND calendarUri != ''")
|
|
|
|
|
public abstract int clearCompletedCalendarEvents();
|
|
|
|
|
@ -175,7 +171,7 @@ public abstract class TaskDao {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@androidx.room.Query(
|
|
|
|
|
@Query(
|
|
|
|
|
"SELECT * FROM tasks "
|
|
|
|
|
+ "WHERE completed = 0 AND deleted = 0 AND hideUntil < (strftime('%s','now')*1000) "
|
|
|
|
|
+ "ORDER BY (CASE WHEN (dueDate=0) THEN (strftime('%s','now')*1000)*2 ELSE ((CASE WHEN (dueDate / 1000) % 60 > 0 THEN dueDate ELSE (dueDate + 43140000) END)) END) + 172800000 * importance ASC "
|
|
|
|
|
@ -224,8 +220,8 @@ public abstract class TaskDao {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Cursor getCursor(String queryTemplate, Property<?>... properties) {
|
|
|
|
|
Query query =
|
|
|
|
|
Query.select(properties)
|
|
|
|
|
com.todoroo.andlib.sql.Query query =
|
|
|
|
|
com.todoroo.andlib.sql.Query.select(properties)
|
|
|
|
|
.withQueryTemplate(PermaSql.replacePlaceholdersForQuery(queryTemplate));
|
|
|
|
|
String queryString = query.from(Task.TABLE).toString();
|
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
|
|