mirror of https://github.com/tasks/tasks
Convert some Room DAOs to Kotlin
parent
a0f483969f
commit
b193f7b75f
@ -1,35 +0,0 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface AlarmDao {
|
||||
|
||||
@Query(
|
||||
"SELECT alarms.* FROM alarms INNER JOIN tasks ON tasks._id = alarms.task "
|
||||
+ "WHERE tasks.completed = 0 AND tasks.deleted = 0 AND tasks.lastNotified < alarms.time "
|
||||
+ "ORDER BY time ASC")
|
||||
List<Alarm> getActiveAlarms();
|
||||
|
||||
@Query(
|
||||
"SELECT alarms.* FROM alarms INNER JOIN tasks ON tasks._id = alarms.task "
|
||||
+ "WHERE tasks._id = :taskId AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.lastNotified < alarms.time "
|
||||
+ "ORDER BY time ASC")
|
||||
List<Alarm> getActiveAlarms(long taskId);
|
||||
|
||||
@Query("SELECT * FROM alarms WHERE task = :taskId ORDER BY time ASC")
|
||||
List<Alarm> getAlarms(long taskId);
|
||||
|
||||
@Delete
|
||||
void delete(Alarm alarm);
|
||||
|
||||
@Insert
|
||||
long insert(Alarm alarm);
|
||||
|
||||
@Insert
|
||||
void insert(Iterable<Alarm> alarms);
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
|
||||
@Dao
|
||||
interface AlarmDao {
|
||||
@Query("SELECT alarms.* FROM alarms INNER JOIN tasks ON tasks._id = alarms.task "
|
||||
+ "WHERE tasks.completed = 0 AND tasks.deleted = 0 AND tasks.lastNotified < alarms.time "
|
||||
+ "ORDER BY time ASC")
|
||||
fun getActiveAlarms(): List<Alarm>
|
||||
|
||||
@Query("SELECT alarms.* FROM alarms INNER JOIN tasks ON tasks._id = alarms.task "
|
||||
+ "WHERE tasks._id = :taskId AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.lastNotified < alarms.time "
|
||||
+ "ORDER BY time ASC")
|
||||
fun getActiveAlarms(taskId: Long): List<Alarm>
|
||||
|
||||
@Query("SELECT * FROM alarms WHERE task = :taskId ORDER BY time ASC")
|
||||
fun getAlarms(taskId: Long): List<Alarm>
|
||||
|
||||
@Delete
|
||||
fun delete(alarm: Alarm)
|
||||
|
||||
@Insert
|
||||
fun insert(alarm: Alarm): Long
|
||||
|
||||
@Insert
|
||||
fun insert(alarms: Iterable<Alarm>)
|
||||
}
|
||||
@ -1,182 +0,0 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import static org.tasks.db.DbUtils.collect;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
import io.reactivex.Single;
|
||||
import java.util.List;
|
||||
import org.tasks.filters.CaldavFilters;
|
||||
|
||||
@Dao
|
||||
public abstract class CaldavDao {
|
||||
|
||||
@Query("SELECT * FROM caldav_lists")
|
||||
public abstract LiveData<List<CaldavCalendar>> subscribeToCalendars();
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_uuid = :uuid LIMIT 1")
|
||||
public abstract CaldavCalendar getCalendarByUuid(String uuid);
|
||||
|
||||
@Query("SELECT * FROM caldav_accounts WHERE cda_uuid = :uuid LIMIT 1")
|
||||
public abstract CaldavAccount getAccountByUuid(String uuid);
|
||||
|
||||
@Query("SELECT COUNT(*) FROM caldav_accounts")
|
||||
public abstract Single<Integer> accountCount();
|
||||
|
||||
@Query("SELECT * FROM caldav_accounts ORDER BY UPPER(cda_name) ASC")
|
||||
public abstract List<CaldavAccount> getAccounts();
|
||||
|
||||
@Query("UPDATE caldav_accounts SET cda_collapsed = :collapsed WHERE cda_id = :id")
|
||||
public abstract void setCollapsed(long id, boolean collapsed);
|
||||
|
||||
@Insert
|
||||
public abstract long insert(CaldavAccount caldavAccount);
|
||||
|
||||
@Update
|
||||
public abstract void update(CaldavAccount caldavAccount);
|
||||
|
||||
public void insert(CaldavCalendar caldavCalendar) {
|
||||
caldavCalendar.setId(insertInternal(caldavCalendar));
|
||||
}
|
||||
|
||||
@Insert
|
||||
abstract long insertInternal(CaldavCalendar caldavCalendar);
|
||||
|
||||
@Update
|
||||
public abstract void update(CaldavCalendar caldavCalendar);
|
||||
|
||||
@Insert
|
||||
public abstract long insert(CaldavTask caldavTask);
|
||||
|
||||
@Insert
|
||||
public abstract void insert(Iterable<CaldavTask> tasks);
|
||||
|
||||
@Update
|
||||
public abstract void update(CaldavTask caldavTask);
|
||||
|
||||
public void update(SubsetCaldav caldavTask) {
|
||||
update(caldavTask.getId(), caldavTask.getRemoteParent());
|
||||
}
|
||||
|
||||
@Query(
|
||||
"UPDATE caldav_tasks SET cd_remote_parent = :remoteParent WHERE cd_id = :id")
|
||||
abstract void update(long id,String remoteParent);
|
||||
|
||||
@Update
|
||||
public abstract void update(Iterable<CaldavTask> tasks);
|
||||
|
||||
@Delete
|
||||
public abstract void delete(CaldavTask caldavTask);
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_deleted > 0 AND cd_calendar = :calendar")
|
||||
public abstract List<CaldavTask> getDeleted(String calendar);
|
||||
|
||||
@Query("UPDATE caldav_tasks SET cd_deleted = :now WHERE cd_task IN (:tasks)")
|
||||
public abstract void markDeleted(long now, List<Long> tasks);
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_task = :taskId AND cd_deleted = 0 LIMIT 1")
|
||||
public abstract CaldavTask getTask(long taskId);
|
||||
|
||||
@Query("SELECT cd_remote_id FROM caldav_tasks WHERE cd_task = :taskId AND cd_deleted = 0")
|
||||
public abstract String getRemoteIdForTask(long taskId);
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_object = :object LIMIT 1")
|
||||
public abstract CaldavTask getTask(String calendar, String object);
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_remote_id = :remoteId")
|
||||
public abstract CaldavTask getTaskByRemoteId(String calendar, String remoteId);
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_task = :taskId")
|
||||
public abstract List<CaldavTask> getTasks(long taskId);
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_task in (:taskIds) AND cd_deleted = 0")
|
||||
public abstract List<CaldavTask> getTasks(List<Long> taskIds);
|
||||
|
||||
@Query(
|
||||
"SELECT task.*, caldav_task.* FROM tasks AS task "
|
||||
+ "INNER JOIN caldav_tasks AS caldav_task ON _id = cd_task "
|
||||
+ "WHERE cd_deleted = 0 AND cd_vtodo IS NOT NULL AND cd_vtodo != ''")
|
||||
public abstract List<CaldavTaskContainer> getTasks();
|
||||
|
||||
@Query(
|
||||
"SELECT task.*, caldav_task.* FROM tasks AS task "
|
||||
+ "INNER JOIN caldav_tasks AS caldav_task ON _id = cd_task "
|
||||
+ "WHERE cd_calendar = :calendar "
|
||||
+ "AND modified > cd_last_sync "
|
||||
+ "AND cd_deleted = 0")
|
||||
public abstract List<CaldavTaskContainer> getCaldavTasksToPush(String calendar);
|
||||
|
||||
@Query("SELECT * FROM caldav_lists ORDER BY cdl_name COLLATE NOCASE")
|
||||
public abstract List<CaldavCalendar> getCalendars();
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_uuid = :uuid LIMIT 1")
|
||||
public abstract CaldavCalendar getCalendar(String uuid);
|
||||
|
||||
@Query("SELECT cd_object FROM caldav_tasks WHERE cd_calendar = :calendar")
|
||||
public abstract List<String> getObjects(String calendar);
|
||||
|
||||
public List<Long> getTasks(String calendar, List<String> objects) {
|
||||
return collect(objects, b -> getTasksInternal(calendar, b));
|
||||
}
|
||||
|
||||
@Query("SELECT cd_task FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_object IN (:objects)")
|
||||
abstract List<Long> getTasksInternal(String calendar, List<String> objects);
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_account = :account AND cdl_url NOT IN (:urls)")
|
||||
public abstract List<CaldavCalendar> findDeletedCalendars(String account, List<String> urls);
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_account = :account AND cdl_url = :url LIMIT 1")
|
||||
public abstract CaldavCalendar getCalendarByUrl(String account, String url);
|
||||
|
||||
@Query(
|
||||
"SELECT caldav_accounts.* from caldav_accounts"
|
||||
+ " INNER JOIN caldav_tasks ON cd_task = :task"
|
||||
+ " INNER JOIN caldav_lists ON cd_calendar = cdl_uuid"
|
||||
+ " WHERE cdl_account = cda_uuid")
|
||||
public abstract CaldavAccount getAccountForTask(long task);
|
||||
|
||||
@Query("SELECT DISTINCT cd_calendar FROM caldav_tasks WHERE cd_deleted = 0 AND cd_task IN (:tasks)")
|
||||
public abstract List<String> getCalendars(List<Long> tasks);
|
||||
|
||||
@Query(
|
||||
"SELECT caldav_lists.*, COUNT(tasks._id) AS count"
|
||||
+ " FROM caldav_lists"
|
||||
+ " LEFT JOIN caldav_tasks ON caldav_tasks.cd_calendar = caldav_lists.cdl_uuid"
|
||||
+ " LEFT JOIN tasks ON caldav_tasks.cd_task = tasks._id AND tasks.deleted = 0 AND tasks.completed = 0 AND tasks.hideUntil < :now AND cd_deleted = 0"
|
||||
+ " WHERE caldav_lists.cdl_account = :uuid"
|
||||
+ " GROUP BY caldav_lists.cdl_uuid")
|
||||
public abstract List<CaldavFilters> getCaldavFilters(String uuid, long now);
|
||||
|
||||
@Query(
|
||||
"SELECT tasks._id FROM tasks "
|
||||
+ "INNER JOIN tags ON tags.task = tasks._id "
|
||||
+ "INNER JOIN caldav_tasks ON cd_task = tasks._id "
|
||||
+ "GROUP BY tasks._id")
|
||||
public abstract List<Long> getTasksWithTags();
|
||||
|
||||
@Query(
|
||||
"UPDATE tasks SET parent = IFNULL(("
|
||||
+ " SELECT p.cd_task FROM caldav_tasks AS p"
|
||||
+ " INNER JOIN caldav_tasks ON caldav_tasks.cd_task = tasks._id"
|
||||
+ " WHERE p.cd_remote_id = caldav_tasks.cd_remote_parent"
|
||||
+ " AND p.cd_calendar = caldav_tasks.cd_calendar"
|
||||
+ " AND p.cd_deleted = 0), 0)"
|
||||
+ "WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task WHERE cd_deleted = 0)")
|
||||
public abstract void updateParents();
|
||||
|
||||
@Query(
|
||||
"UPDATE tasks SET parent = IFNULL(("
|
||||
+ " SELECT p.cd_task FROM caldav_tasks AS p"
|
||||
+ " INNER JOIN caldav_tasks "
|
||||
+ " ON caldav_tasks.cd_task = tasks._id"
|
||||
+ " AND caldav_tasks.cd_calendar = :calendar"
|
||||
+ " WHERE p.cd_remote_id = caldav_tasks.cd_remote_parent"
|
||||
+ " AND p.cd_calendar = caldav_tasks.cd_calendar"
|
||||
+ " AND caldav_tasks.cd_deleted = 0), 0)"
|
||||
+ "WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task WHERE cd_deleted = 0 AND cd_calendar = :calendar)")
|
||||
public abstract void updateParents(String calendar);
|
||||
}
|
||||
@ -0,0 +1,167 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import io.reactivex.Single
|
||||
import org.tasks.db.DbUtils
|
||||
import org.tasks.filters.CaldavFilters
|
||||
|
||||
@Dao
|
||||
abstract class CaldavDao {
|
||||
@Query("SELECT * FROM caldav_lists")
|
||||
abstract fun subscribeToCalendars(): LiveData<List<CaldavCalendar>>
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_uuid = :uuid LIMIT 1")
|
||||
abstract fun getCalendarByUuid(uuid: String): CaldavCalendar?
|
||||
|
||||
@Query("SELECT * FROM caldav_accounts WHERE cda_uuid = :uuid LIMIT 1")
|
||||
abstract fun getAccountByUuid(uuid: String): CaldavAccount?
|
||||
|
||||
@Query("SELECT COUNT(*) FROM caldav_accounts")
|
||||
abstract fun accountCount(): Single<Int>
|
||||
|
||||
@Query("SELECT * FROM caldav_accounts ORDER BY UPPER(cda_name) ASC")
|
||||
abstract fun getAccounts(): List<CaldavAccount>
|
||||
|
||||
@Query("UPDATE caldav_accounts SET cda_collapsed = :collapsed WHERE cda_id = :id")
|
||||
abstract fun setCollapsed(id: Long, collapsed: Boolean)
|
||||
|
||||
@Insert
|
||||
abstract fun insert(caldavAccount: CaldavAccount): Long
|
||||
|
||||
@Update
|
||||
abstract fun update(caldavAccount: CaldavAccount)
|
||||
|
||||
fun insert(caldavCalendar: CaldavCalendar) {
|
||||
caldavCalendar.id = insertInternal(caldavCalendar)
|
||||
}
|
||||
|
||||
@Insert
|
||||
abstract fun insertInternal(caldavCalendar: CaldavCalendar): Long
|
||||
|
||||
@Update
|
||||
abstract fun update(caldavCalendar: CaldavCalendar)
|
||||
|
||||
@Insert
|
||||
abstract fun insert(caldavTask: CaldavTask): Long
|
||||
|
||||
@Insert
|
||||
abstract fun insert(tasks: Iterable<CaldavTask>)
|
||||
|
||||
@Update
|
||||
abstract fun update(caldavTask: CaldavTask)
|
||||
|
||||
fun update(caldavTask: SubsetCaldav) {
|
||||
update(caldavTask.id, caldavTask.remoteParent)
|
||||
}
|
||||
|
||||
@Query("UPDATE caldav_tasks SET cd_remote_parent = :remoteParent WHERE cd_id = :id")
|
||||
abstract fun update(id: Long, remoteParent: String)
|
||||
|
||||
@Update
|
||||
abstract fun update(tasks: Iterable<CaldavTask>)
|
||||
|
||||
@Delete
|
||||
abstract fun delete(caldavTask: CaldavTask)
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_deleted > 0 AND cd_calendar = :calendar")
|
||||
abstract fun getDeleted(calendar: String): List<CaldavTask>
|
||||
|
||||
@Query("UPDATE caldav_tasks SET cd_deleted = :now WHERE cd_task IN (:tasks)")
|
||||
abstract fun markDeleted(now: Long, tasks: List<Long>)
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_task = :taskId AND cd_deleted = 0 LIMIT 1")
|
||||
abstract fun getTask(taskId: Long): CaldavTask?
|
||||
|
||||
@Query("SELECT cd_remote_id FROM caldav_tasks WHERE cd_task = :taskId AND cd_deleted = 0")
|
||||
abstract fun getRemoteIdForTask(taskId: Long): String?
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_object = :obj LIMIT 1")
|
||||
abstract fun getTask(calendar: String, obj: String): CaldavTask?
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_remote_id = :remoteId")
|
||||
abstract fun getTaskByRemoteId(calendar: String, remoteId: String): CaldavTask?
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_task = :taskId")
|
||||
abstract fun getTasks(taskId: Long): List<CaldavTask>
|
||||
|
||||
@Query("SELECT * FROM caldav_tasks WHERE cd_task in (:taskIds) AND cd_deleted = 0")
|
||||
abstract fun getTasks(taskIds: List<Long>): List<CaldavTask>
|
||||
|
||||
@Query("SELECT task.*, caldav_task.* FROM tasks AS task "
|
||||
+ "INNER JOIN caldav_tasks AS caldav_task ON _id = cd_task "
|
||||
+ "WHERE cd_deleted = 0 AND cd_vtodo IS NOT NULL AND cd_vtodo != ''")
|
||||
abstract fun getTasks(): List<CaldavTaskContainer>
|
||||
|
||||
@Query("SELECT task.*, caldav_task.* FROM tasks AS task "
|
||||
+ "INNER JOIN caldav_tasks AS caldav_task ON _id = cd_task "
|
||||
+ "WHERE cd_calendar = :calendar "
|
||||
+ "AND modified > cd_last_sync "
|
||||
+ "AND cd_deleted = 0")
|
||||
abstract fun getCaldavTasksToPush(calendar: String): List<CaldavTaskContainer>
|
||||
|
||||
@Query("SELECT * FROM caldav_lists ORDER BY cdl_name COLLATE NOCASE")
|
||||
abstract fun getCalendars(): List<CaldavCalendar>
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_uuid = :uuid LIMIT 1")
|
||||
abstract fun getCalendar(uuid: String): CaldavCalendar?
|
||||
|
||||
@Query("SELECT cd_object FROM caldav_tasks WHERE cd_calendar = :calendar")
|
||||
abstract fun getObjects(calendar: String): List<String>
|
||||
|
||||
fun getTasks(calendar: String, objects: List<String>): List<Long> {
|
||||
return DbUtils.collect(objects) { getTasksInternal(calendar, it!!) }
|
||||
}
|
||||
|
||||
@Query("SELECT cd_task FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_object IN (:objects)")
|
||||
abstract fun getTasksInternal(calendar: String, objects: List<String>): List<Long>
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_account = :account AND cdl_url NOT IN (:urls)")
|
||||
abstract fun findDeletedCalendars(account: String, urls: List<String>): List<CaldavCalendar>
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_account = :account AND cdl_url = :url LIMIT 1")
|
||||
abstract fun getCalendarByUrl(account: String, url: String): CaldavCalendar?
|
||||
|
||||
@Query("SELECT caldav_accounts.* from caldav_accounts"
|
||||
+ " INNER JOIN caldav_tasks ON cd_task = :task"
|
||||
+ " INNER JOIN caldav_lists ON cd_calendar = cdl_uuid"
|
||||
+ " WHERE cdl_account = cda_uuid")
|
||||
abstract fun getAccountForTask(task: Long): CaldavAccount?
|
||||
|
||||
@Query("SELECT DISTINCT cd_calendar FROM caldav_tasks WHERE cd_deleted = 0 AND cd_task IN (:tasks)")
|
||||
abstract fun getCalendars(tasks: List<Long>): List<String>
|
||||
|
||||
@Query("SELECT caldav_lists.*, COUNT(tasks._id) AS count"
|
||||
+ " FROM caldav_lists"
|
||||
+ " LEFT JOIN caldav_tasks ON caldav_tasks.cd_calendar = caldav_lists.cdl_uuid"
|
||||
+ " LEFT JOIN tasks ON caldav_tasks.cd_task = tasks._id AND tasks.deleted = 0 AND tasks.completed = 0 AND tasks.hideUntil < :now AND cd_deleted = 0"
|
||||
+ " WHERE caldav_lists.cdl_account = :uuid"
|
||||
+ " GROUP BY caldav_lists.cdl_uuid")
|
||||
abstract fun getCaldavFilters(uuid: String, now: Long): List<CaldavFilters>
|
||||
|
||||
@Query("SELECT tasks._id FROM tasks "
|
||||
+ "INNER JOIN tags ON tags.task = tasks._id "
|
||||
+ "INNER JOIN caldav_tasks ON cd_task = tasks._id "
|
||||
+ "GROUP BY tasks._id")
|
||||
abstract fun getTasksWithTags(): List<Long>
|
||||
|
||||
@Query("UPDATE tasks SET parent = IFNULL(("
|
||||
+ " SELECT p.cd_task FROM caldav_tasks AS p"
|
||||
+ " INNER JOIN caldav_tasks ON caldav_tasks.cd_task = tasks._id"
|
||||
+ " WHERE p.cd_remote_id = caldav_tasks.cd_remote_parent"
|
||||
+ " AND p.cd_calendar = caldav_tasks.cd_calendar"
|
||||
+ " AND p.cd_deleted = 0), 0)"
|
||||
+ "WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task WHERE cd_deleted = 0)")
|
||||
abstract fun updateParents()
|
||||
|
||||
@Query("UPDATE tasks SET parent = IFNULL(("
|
||||
+ " SELECT p.cd_task FROM caldav_tasks AS p"
|
||||
+ " INNER JOIN caldav_tasks "
|
||||
+ " ON caldav_tasks.cd_task = tasks._id"
|
||||
+ " AND caldav_tasks.cd_calendar = :calendar"
|
||||
+ " WHERE p.cd_remote_id = caldav_tasks.cd_remote_parent"
|
||||
+ " AND p.cd_calendar = caldav_tasks.cd_calendar"
|
||||
+ " AND caldav_tasks.cd_deleted = 0), 0)"
|
||||
+ "WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task WHERE cd_deleted = 0 AND cd_calendar = :calendar)")
|
||||
abstract fun updateParents(calendar: String)
|
||||
}
|
||||
@ -1,116 +0,0 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import static org.tasks.db.DbUtils.batch;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Transaction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public abstract class DeletionDao {
|
||||
|
||||
@Query("SELECT _id FROM tasks WHERE deleted > 0")
|
||||
public abstract List<Long> getDeleted();
|
||||
|
||||
@Query("DELETE FROM caldav_tasks WHERE cd_task IN(:ids)")
|
||||
abstract void deleteCaldavTasks(List<Long> ids);
|
||||
|
||||
@Query("DELETE FROM google_tasks WHERE gt_task IN(:ids)")
|
||||
abstract void deleteGoogleTasks(List<Long> ids);
|
||||
|
||||
@Query("DELETE FROM tags WHERE task IN(:ids)")
|
||||
abstract void deleteTags(List<Long> ids);
|
||||
|
||||
@Query("DELETE FROM geofences WHERE task IN(:ids)")
|
||||
abstract void deleteGeofences(List<Long> ids);
|
||||
|
||||
@Query("DELETE FROM alarms WHERE task IN(:ids)")
|
||||
abstract void deleteAlarms(List<Long> ids);
|
||||
|
||||
@Query("DELETE FROM tasks WHERE _id IN(:ids)")
|
||||
abstract void deleteTasks(List<Long> ids);
|
||||
|
||||
@Transaction
|
||||
public void delete(List<Long> ids) {
|
||||
batch(ids, b -> {
|
||||
deleteAlarms(b);
|
||||
deleteGeofences(b);
|
||||
deleteTags(b);
|
||||
deleteGoogleTasks(b);
|
||||
deleteCaldavTasks(b);
|
||||
deleteTasks(b);
|
||||
});
|
||||
}
|
||||
|
||||
@Query("UPDATE tasks "
|
||||
+ "SET modified = (strftime('%s','now')*1000), deleted = (strftime('%s','now')*1000)"
|
||||
+ "WHERE _id IN(:ids)")
|
||||
abstract void markDeletedInternal(List<Long> ids);
|
||||
|
||||
public void markDeleted(Iterable<Long> ids) {
|
||||
batch(ids, this::markDeletedInternal);
|
||||
}
|
||||
|
||||
@Query("SELECT gt_task FROM google_tasks WHERE gt_deleted = 0 AND gt_list_id = :listId")
|
||||
abstract List<Long> getActiveGoogleTasks(String listId);
|
||||
|
||||
@Delete
|
||||
abstract void deleteGoogleTaskList(GoogleTaskList googleTaskList);
|
||||
|
||||
@Transaction
|
||||
public List<Long> delete(GoogleTaskList googleTaskList) {
|
||||
List<Long> tasks = getActiveGoogleTasks(googleTaskList.getRemoteId());
|
||||
delete(tasks);
|
||||
deleteGoogleTaskList(googleTaskList);
|
||||
return tasks;
|
||||
}
|
||||
|
||||
@Delete
|
||||
abstract void deleteGoogleTaskAccount(GoogleTaskAccount googleTaskAccount);
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_account = :account ORDER BY gtl_title ASC")
|
||||
abstract List<GoogleTaskList> getLists(String account);
|
||||
|
||||
@Transaction
|
||||
public List<Long> delete(GoogleTaskAccount googleTaskAccount) {
|
||||
List<Long> deleted = new ArrayList<>();
|
||||
for (GoogleTaskList list : getLists(googleTaskAccount.getAccount())) {
|
||||
deleted.addAll(delete(list));
|
||||
}
|
||||
deleteGoogleTaskAccount(googleTaskAccount);
|
||||
return deleted;
|
||||
}
|
||||
|
||||
@Query("SELECT cd_task FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_deleted = 0")
|
||||
abstract List<Long> getActiveCaldavTasks(String calendar);
|
||||
|
||||
@Delete
|
||||
abstract void deleteCaldavCalendar(CaldavCalendar caldavCalendar);
|
||||
|
||||
@Transaction
|
||||
public List<Long> delete(CaldavCalendar caldavCalendar) {
|
||||
List<Long> tasks = getActiveCaldavTasks(caldavCalendar.getUuid());
|
||||
delete(tasks);
|
||||
deleteCaldavCalendar(caldavCalendar);
|
||||
return tasks;
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_account = :account")
|
||||
abstract List<CaldavCalendar> getCalendars(String account);
|
||||
|
||||
@Delete
|
||||
abstract void deleteCaldavAccount(CaldavAccount caldavAccount);
|
||||
|
||||
@Transaction
|
||||
public List<Long> delete(CaldavAccount caldavAccount) {
|
||||
List<Long> deleted = new ArrayList<>();
|
||||
for (CaldavCalendar calendar : getCalendars(caldavAccount.getUuid())) {
|
||||
deleted.addAll(delete(calendar));
|
||||
}
|
||||
deleteCaldavAccount(caldavAccount);
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import org.tasks.db.DbUtils
|
||||
import java.util.*
|
||||
|
||||
@Dao
|
||||
abstract class DeletionDao {
|
||||
@Query("SELECT _id FROM tasks WHERE deleted > 0")
|
||||
abstract fun getDeleted(): List<Long>
|
||||
|
||||
@Query("DELETE FROM caldav_tasks WHERE cd_task IN(:ids)")
|
||||
abstract fun deleteCaldavTasks(ids: List<Long>)
|
||||
|
||||
@Query("DELETE FROM google_tasks WHERE gt_task IN(:ids)")
|
||||
abstract fun deleteGoogleTasks(ids: List<Long>)
|
||||
|
||||
@Query("DELETE FROM tags WHERE task IN(:ids)")
|
||||
abstract fun deleteTags(ids: List<Long>)
|
||||
|
||||
@Query("DELETE FROM geofences WHERE task IN(:ids)")
|
||||
abstract fun deleteGeofences(ids: List<Long>)
|
||||
|
||||
@Query("DELETE FROM alarms WHERE task IN(:ids)")
|
||||
abstract fun deleteAlarms(ids: List<Long>)
|
||||
|
||||
@Query("DELETE FROM tasks WHERE _id IN(:ids)")
|
||||
abstract fun deleteTasks(ids: List<Long>)
|
||||
|
||||
@Transaction
|
||||
open fun delete(ids: List<Long>) {
|
||||
DbUtils.batch(ids) {
|
||||
deleteAlarms(it)
|
||||
deleteGeofences(it)
|
||||
deleteTags(it)
|
||||
deleteGoogleTasks(it)
|
||||
deleteCaldavTasks(it)
|
||||
deleteTasks(it)
|
||||
}
|
||||
}
|
||||
|
||||
@Query("UPDATE tasks "
|
||||
+ "SET modified = (strftime('%s','now')*1000), deleted = (strftime('%s','now')*1000)"
|
||||
+ "WHERE _id IN(:ids)")
|
||||
abstract fun markDeletedInternal(ids: List<Long>)
|
||||
|
||||
fun markDeleted(ids: Iterable<Long>) {
|
||||
DbUtils.batch(ids, this::markDeletedInternal)
|
||||
}
|
||||
|
||||
@Query("SELECT gt_task FROM google_tasks WHERE gt_deleted = 0 AND gt_list_id = :listId")
|
||||
abstract fun getActiveGoogleTasks(listId: String): List<Long>
|
||||
|
||||
@Delete
|
||||
abstract fun deleteGoogleTaskList(googleTaskList: GoogleTaskList)
|
||||
|
||||
@Transaction
|
||||
open fun delete(googleTaskList: GoogleTaskList): List<Long> {
|
||||
val tasks = getActiveGoogleTasks(googleTaskList.remoteId)
|
||||
delete(tasks)
|
||||
deleteGoogleTaskList(googleTaskList)
|
||||
return tasks
|
||||
}
|
||||
|
||||
@Delete
|
||||
abstract fun deleteGoogleTaskAccount(googleTaskAccount: GoogleTaskAccount)
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_account = :account ORDER BY gtl_title ASC")
|
||||
abstract fun getLists(account: String): List<GoogleTaskList>
|
||||
|
||||
@Transaction
|
||||
open fun delete(googleTaskAccount: GoogleTaskAccount): List<Long> {
|
||||
val deleted = ArrayList<Long>()
|
||||
for (list in getLists(googleTaskAccount.account)) {
|
||||
deleted.addAll(delete(list))
|
||||
}
|
||||
deleteGoogleTaskAccount(googleTaskAccount)
|
||||
return deleted
|
||||
}
|
||||
|
||||
@Query("SELECT cd_task FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_deleted = 0")
|
||||
abstract fun getActiveCaldavTasks(calendar: String): List<Long>
|
||||
|
||||
@Delete
|
||||
abstract fun deleteCaldavCalendar(caldavCalendar: CaldavCalendar)
|
||||
|
||||
@Transaction
|
||||
open fun delete(caldavCalendar: CaldavCalendar): List<Long> {
|
||||
val tasks = getActiveCaldavTasks(caldavCalendar.uuid!!)
|
||||
delete(tasks)
|
||||
deleteCaldavCalendar(caldavCalendar)
|
||||
return tasks
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_account = :account")
|
||||
abstract fun getCalendars(account: String): List<CaldavCalendar>
|
||||
|
||||
@Delete
|
||||
abstract fun deleteCaldavAccount(caldavAccount: CaldavAccount)
|
||||
|
||||
@Transaction
|
||||
open fun delete(caldavAccount: CaldavAccount): List<Long> {
|
||||
val deleted = ArrayList<Long>()
|
||||
for (calendar in getCalendars(caldavAccount.uuid!!)) {
|
||||
deleted.addAll(delete(calendar))
|
||||
}
|
||||
deleteCaldavAccount(caldavAccount)
|
||||
return deleted
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface FilterDao {
|
||||
|
||||
@Update
|
||||
void update(Filter filter);
|
||||
|
||||
@Query("DELETE FROM filters WHERE _id = :id")
|
||||
void delete(long id);
|
||||
|
||||
@Query("SELECT * FROM filters WHERE title = :title COLLATE NOCASE LIMIT 1")
|
||||
Filter getByName(String title);
|
||||
|
||||
@Insert
|
||||
long insert(Filter filter);
|
||||
|
||||
@Query("SELECT * FROM filters")
|
||||
List<Filter> getFilters();
|
||||
|
||||
@Query("SELECT * FROM filters WHERE _id = :id LIMIT 1")
|
||||
Filter getById(long id);
|
||||
|
||||
@Query("SELECT * FROM filters")
|
||||
List<Filter> getAll();
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
|
||||
@Dao
|
||||
interface FilterDao {
|
||||
@Update
|
||||
fun update(filter: Filter)
|
||||
|
||||
@Query("DELETE FROM filters WHERE _id = :id")
|
||||
fun delete(id: Long)
|
||||
|
||||
@Query("SELECT * FROM filters WHERE title = :title COLLATE NOCASE LIMIT 1")
|
||||
fun getByName(title: String): Filter?
|
||||
|
||||
@Insert
|
||||
fun insert(filter: Filter): Long
|
||||
|
||||
@Query("SELECT * FROM filters")
|
||||
fun getFilters(): List<Filter>
|
||||
|
||||
@Query("SELECT * FROM filters WHERE _id = :id LIMIT 1")
|
||||
fun getById(id: Long): Filter?
|
||||
|
||||
@Query("SELECT * FROM filters")
|
||||
fun getAll(): List<Filter>
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
import io.reactivex.Single;
|
||||
import java.util.List;
|
||||
import org.tasks.filters.GoogleTaskFilters;
|
||||
|
||||
@Dao
|
||||
public interface GoogleTaskListDao {
|
||||
|
||||
@Query("SELECT COUNT(*) FROM google_task_accounts")
|
||||
Single<Integer> accountCount();
|
||||
|
||||
@Query("SELECT * FROM google_task_accounts")
|
||||
List<GoogleTaskAccount> getAccounts();
|
||||
|
||||
@Query("SELECT * FROM google_task_accounts WHERE gta_account = :account COLLATE NOCASE LIMIT 1")
|
||||
GoogleTaskAccount getAccount(String account);
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_id = :id")
|
||||
GoogleTaskList getById(long id);
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_account = :account ORDER BY gtl_title ASC")
|
||||
List<GoogleTaskList> getLists(String account);
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_remote_id = :remoteId LIMIT 1")
|
||||
GoogleTaskList getByRemoteId(String remoteId);
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_remote_id IN (:remoteIds)")
|
||||
List<GoogleTaskList> getByRemoteId(List<String> remoteIds);
|
||||
|
||||
@Query("SELECT * FROM google_task_lists")
|
||||
LiveData<List<GoogleTaskList>> subscribeToLists();
|
||||
|
||||
@Query(
|
||||
"SELECT * FROM google_task_lists WHERE gtl_remote_id = :remoteId AND IFNULL(gtl_account, '') = ''")
|
||||
GoogleTaskList findExistingList(String remoteId);
|
||||
|
||||
@Query("SELECT * FROM google_task_lists")
|
||||
List<GoogleTaskList> getAllLists();
|
||||
|
||||
@Query("UPDATE google_task_lists SET gtl_last_sync = 0 WHERE gtl_account = :account")
|
||||
void resetLastSync(String account);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
long insertOrReplace(GoogleTaskList googleTaskList);
|
||||
|
||||
@Insert
|
||||
long insert(GoogleTaskList googleTaskList);
|
||||
|
||||
@Insert
|
||||
void insert(GoogleTaskAccount googleTaskAccount);
|
||||
|
||||
@Update
|
||||
void update(GoogleTaskAccount account);
|
||||
|
||||
@Update
|
||||
void update(GoogleTaskList list);
|
||||
|
||||
@Query(
|
||||
"SELECT google_task_lists.*, COUNT(tasks._id) AS count"
|
||||
+ " FROM google_task_lists "
|
||||
+ " LEFT JOIN google_tasks ON google_tasks.gt_list_id = google_task_lists.gtl_remote_id"
|
||||
+ " LEFT JOIN tasks ON google_tasks.gt_task = tasks._id AND tasks.deleted = 0 AND tasks.completed = 0 AND tasks.hideUntil < :now AND gt_deleted = 0"
|
||||
+ " WHERE google_task_lists.gtl_account = :account"
|
||||
+ " GROUP BY google_task_lists.gtl_remote_id")
|
||||
List<GoogleTaskFilters> getGoogleTaskFilters(String account, long now);
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import io.reactivex.Single
|
||||
import org.tasks.filters.GoogleTaskFilters
|
||||
|
||||
@Dao
|
||||
interface GoogleTaskListDao {
|
||||
@Query("SELECT COUNT(*) FROM google_task_accounts")
|
||||
fun accountCount(): Single<Int>
|
||||
|
||||
@Query("SELECT * FROM google_task_accounts")
|
||||
fun getAccounts(): List<GoogleTaskAccount>
|
||||
|
||||
@Query("SELECT * FROM google_task_accounts WHERE gta_account = :account COLLATE NOCASE LIMIT 1")
|
||||
fun getAccount(account: String): GoogleTaskAccount?
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_id = :id")
|
||||
fun getById(id: Long): GoogleTaskList?
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_account = :account ORDER BY gtl_title ASC")
|
||||
fun getLists(account: String): List<GoogleTaskList>
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_remote_id = :remoteId LIMIT 1")
|
||||
fun getByRemoteId(remoteId: String): GoogleTaskList?
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_remote_id IN (:remoteIds)")
|
||||
fun getByRemoteId(remoteIds: List<String>): List<GoogleTaskList>
|
||||
|
||||
@Query("SELECT * FROM google_task_lists")
|
||||
fun subscribeToLists(): LiveData<List<GoogleTaskList>>
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_remote_id = :remoteId AND IFNULL(gtl_account, '') = ''")
|
||||
fun findExistingList(remoteId: String): GoogleTaskList?
|
||||
|
||||
@Query("SELECT * FROM google_task_lists")
|
||||
fun getAllLists(): List<GoogleTaskList>
|
||||
|
||||
@Query("UPDATE google_task_lists SET gtl_last_sync = 0 WHERE gtl_account = :account")
|
||||
fun resetLastSync(account: String)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertOrReplace(googleTaskList: GoogleTaskList): Long
|
||||
|
||||
@Insert
|
||||
fun insert(googleTaskList: GoogleTaskList): Long
|
||||
|
||||
@Insert
|
||||
fun insert(googleTaskAccount: GoogleTaskAccount)
|
||||
|
||||
@Update
|
||||
fun update(account: GoogleTaskAccount)
|
||||
|
||||
@Update
|
||||
fun update(list: GoogleTaskList)
|
||||
|
||||
@Query("SELECT google_task_lists.*, COUNT(tasks._id) AS count"
|
||||
+ " FROM google_task_lists "
|
||||
+ " LEFT JOIN google_tasks ON google_tasks.gt_list_id = google_task_lists.gtl_remote_id"
|
||||
+ " LEFT JOIN tasks ON google_tasks.gt_task = tasks._id AND tasks.deleted = 0 AND tasks.completed = 0 AND tasks.hideUntil < :now AND gt_deleted = 0"
|
||||
+ " WHERE google_task_lists.gtl_account = :account"
|
||||
+ " GROUP BY google_task_lists.gtl_remote_id")
|
||||
fun getGoogleTaskFilters(account: String, now: Long): List<GoogleTaskFilters>
|
||||
}
|
||||
@ -1,126 +0,0 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
import io.reactivex.Single;
|
||||
import java.util.List;
|
||||
import org.tasks.filters.LocationFilters;
|
||||
|
||||
@Dao
|
||||
public interface LocationDao {
|
||||
|
||||
@Query(
|
||||
"SELECT places.*"
|
||||
+ " FROM places"
|
||||
+ " INNER JOIN geofences ON geofences.place = places.uid"
|
||||
+ " INNER JOIN tasks ON geofences.task = tasks._id"
|
||||
+ " WHERE tasks.completed = 0 AND tasks.deleted = 0"
|
||||
+ " AND (geofences.arrival > 0 OR geofences.departure > 0)"
|
||||
+ " GROUP BY places.uid")
|
||||
List<Place> getPlacesWithGeofences();
|
||||
|
||||
@Query(
|
||||
"SELECT places.*,"
|
||||
+ " max(geofences.arrival) as arrival,"
|
||||
+ " max(geofences.departure) as departure,"
|
||||
+ " min(geofences.radius) as radius"
|
||||
+ " FROM places"
|
||||
+ " INNER JOIN geofences ON geofences.place = places.uid"
|
||||
+ " INNER JOIN tasks ON tasks._id = geofences.task"
|
||||
+ " WHERE place = :uid AND tasks.completed = 0 AND tasks.deleted = 0"
|
||||
+ " AND (geofences.arrival > 0 OR geofences.departure > 0)"
|
||||
+ " GROUP BY places.uid")
|
||||
MergedGeofence getGeofencesByPlace(String uid);
|
||||
|
||||
@Query("DELETE FROM geofences WHERE place = :place")
|
||||
void deleteGeofencesByPlace(String place);
|
||||
|
||||
@Query(
|
||||
"SELECT geofences.* FROM geofences"
|
||||
+ " INNER JOIN tasks ON tasks._id = geofences.task"
|
||||
+ " WHERE place = :place AND arrival = 1 AND tasks.completed = 0"
|
||||
+ " AND tasks.deleted = 0 AND tasks.snoozeTime < :now AND tasks.hideUntil < :now")
|
||||
List<Geofence> getArrivalGeofences(String place, long now);
|
||||
|
||||
@Query(
|
||||
"SELECT geofences.* FROM geofences"
|
||||
+ " INNER JOIN tasks ON tasks._id = geofences.task"
|
||||
+ " WHERE place = :place AND departure = 1 AND tasks.completed = 0"
|
||||
+ " AND tasks.deleted = 0 AND tasks.snoozeTime < :now AND tasks.hideUntil < :now")
|
||||
List<Geofence> getDepartureGeofences(String place, long now);
|
||||
|
||||
@Query(
|
||||
"SELECT * FROM geofences"
|
||||
+ " INNER JOIN places ON geofences.place = places.uid"
|
||||
+ " WHERE task = :taskId ORDER BY name ASC LIMIT 1")
|
||||
Location getGeofences(long taskId);
|
||||
|
||||
@Query(
|
||||
"SELECT geofences.*, places.* FROM geofences INNER JOIN places ON geofences.place = places.uid INNER JOIN tasks ON tasks._id = geofences.task WHERE tasks._id = :taskId AND tasks.deleted = 0 AND tasks.completed = 0")
|
||||
List<Location> getActiveGeofences(long taskId);
|
||||
|
||||
@Query("SELECT places.*"
|
||||
+ " FROM places"
|
||||
+ " INNER JOIN geofences ON geofences.place = places.uid"
|
||||
+ " WHERE geofences.task = :taskId")
|
||||
Place getPlaceForTask(long taskId);
|
||||
|
||||
@Query(
|
||||
"SELECT geofences.*, places.* FROM geofences INNER JOIN places ON geofences.place = places.uid INNER JOIN tasks ON tasks._id = geofences.task WHERE tasks.deleted = 0 AND tasks.completed = 0")
|
||||
List<Location> getActiveGeofences();
|
||||
|
||||
@Query("SELECT COUNT(*) FROM geofences")
|
||||
Single<Integer> geofenceCount();
|
||||
|
||||
@Delete
|
||||
void delete(Geofence location);
|
||||
|
||||
@Delete
|
||||
void delete(Place place);
|
||||
|
||||
@Insert
|
||||
long insert(Geofence location);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
long insert(Place place);
|
||||
|
||||
@Update
|
||||
void update(Place place);
|
||||
|
||||
@Update
|
||||
void update(Geofence geofence);
|
||||
|
||||
@Query("SELECT * FROM places WHERE uid = :uid LIMIT 1")
|
||||
Place getByUid(String uid);
|
||||
|
||||
@Query("SELECT * FROM geofences WHERE task = :taskId")
|
||||
List<Geofence> getGeofencesForTask(long taskId);
|
||||
|
||||
@Query("SELECT * FROM places")
|
||||
List<Place> getPlaces();
|
||||
|
||||
@Query("SELECT * FROM places WHERE place_id = :id")
|
||||
Place getPlace(long id);
|
||||
|
||||
@Query("SELECT * FROM places WHERE uid = :uid")
|
||||
Place getPlace(String uid);
|
||||
|
||||
@Query(
|
||||
"SELECT places.*, IFNULL(COUNT(geofence_id),0) AS count FROM places LEFT OUTER JOIN geofences ON geofences.place = places.uid GROUP BY uid ORDER BY COUNT(geofence_id) DESC")
|
||||
LiveData<List<PlaceUsage>> getPlaceUsage();
|
||||
|
||||
@Query("SELECT * FROM places WHERE latitude LIKE :latitude AND longitude LIKE :longitude")
|
||||
Place findPlace(String latitude, String longitude);
|
||||
|
||||
@Query("SELECT places.*, COUNT(tasks._id) AS count FROM places "
|
||||
+ " LEFT JOIN geofences ON geofences.place = places.uid "
|
||||
+ " LEFT JOIN tasks ON geofences.task = tasks._id AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.hideUntil < :now"
|
||||
+ " GROUP BY places.uid"
|
||||
+ " ORDER BY name COLLATE NOCASE ASC")
|
||||
List<LocationFilters> getPlaceFilters(long now);
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import io.reactivex.Single
|
||||
import org.tasks.filters.LocationFilters
|
||||
|
||||
@Dao
|
||||
interface LocationDao {
|
||||
@Query("SELECT places.*"
|
||||
+ " FROM places"
|
||||
+ " INNER JOIN geofences ON geofences.place = places.uid"
|
||||
+ " INNER JOIN tasks ON geofences.task = tasks._id"
|
||||
+ " WHERE tasks.completed = 0 AND tasks.deleted = 0"
|
||||
+ " AND (geofences.arrival > 0 OR geofences.departure > 0)"
|
||||
+ " GROUP BY places.uid")
|
||||
fun getPlacesWithGeofences(): List<Place>
|
||||
|
||||
@Query("SELECT places.*,"
|
||||
+ " max(geofences.arrival) as arrival,"
|
||||
+ " max(geofences.departure) as departure,"
|
||||
+ " min(geofences.radius) as radius"
|
||||
+ " FROM places"
|
||||
+ " INNER JOIN geofences ON geofences.place = places.uid"
|
||||
+ " INNER JOIN tasks ON tasks._id = geofences.task"
|
||||
+ " WHERE place = :uid AND tasks.completed = 0 AND tasks.deleted = 0"
|
||||
+ " AND (geofences.arrival > 0 OR geofences.departure > 0)"
|
||||
+ " GROUP BY places.uid")
|
||||
fun getGeofencesByPlace(uid: String): MergedGeofence?
|
||||
|
||||
@Query("DELETE FROM geofences WHERE place = :place")
|
||||
fun deleteGeofencesByPlace(place: String)
|
||||
|
||||
@Query("SELECT geofences.* FROM geofences"
|
||||
+ " INNER JOIN tasks ON tasks._id = geofences.task"
|
||||
+ " WHERE place = :place AND arrival = 1 AND tasks.completed = 0"
|
||||
+ " AND tasks.deleted = 0 AND tasks.snoozeTime < :now AND tasks.hideUntil < :now")
|
||||
fun getArrivalGeofences(place: String, now: Long): List<Geofence>
|
||||
|
||||
@Query("SELECT geofences.* FROM geofences"
|
||||
+ " INNER JOIN tasks ON tasks._id = geofences.task"
|
||||
+ " WHERE place = :place AND departure = 1 AND tasks.completed = 0"
|
||||
+ " AND tasks.deleted = 0 AND tasks.snoozeTime < :now AND tasks.hideUntil < :now")
|
||||
fun getDepartureGeofences(place: String, now: Long): List<Geofence>
|
||||
|
||||
@Query("SELECT * FROM geofences"
|
||||
+ " INNER JOIN places ON geofences.place = places.uid"
|
||||
+ " WHERE task = :taskId ORDER BY name ASC LIMIT 1")
|
||||
fun getGeofences(taskId: Long): Location?
|
||||
|
||||
@Query("SELECT geofences.*, places.* FROM geofences INNER JOIN places ON geofences.place = places.uid INNER JOIN tasks ON tasks._id = geofences.task WHERE tasks._id = :taskId AND tasks.deleted = 0 AND tasks.completed = 0")
|
||||
fun getActiveGeofences(taskId: Long): List<Location>
|
||||
|
||||
@Query("SELECT places.*"
|
||||
+ " FROM places"
|
||||
+ " INNER JOIN geofences ON geofences.place = places.uid"
|
||||
+ " WHERE geofences.task = :taskId")
|
||||
fun getPlaceForTask(taskId: Long): Place?
|
||||
|
||||
@Query("SELECT geofences.*, places.* FROM geofences INNER JOIN places ON geofences.place = places.uid INNER JOIN tasks ON tasks._id = geofences.task WHERE tasks.deleted = 0 AND tasks.completed = 0")
|
||||
fun getActiveGeofences(): List<Location>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM geofences")
|
||||
fun geofenceCount(): Single<Int>
|
||||
|
||||
@Delete
|
||||
fun delete(location: Geofence)
|
||||
|
||||
@Delete
|
||||
fun delete(place: Place)
|
||||
|
||||
@Insert
|
||||
fun insert(location: Geofence): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(place: Place): Long
|
||||
|
||||
@Update
|
||||
fun update(place: Place)
|
||||
|
||||
@Update
|
||||
fun update(geofence: Geofence)
|
||||
|
||||
@Query("SELECT * FROM places WHERE uid = :uid LIMIT 1")
|
||||
fun getByUid(uid: String): Place?
|
||||
|
||||
@Query("SELECT * FROM geofences WHERE task = :taskId")
|
||||
fun getGeofencesForTask(taskId: Long): List<Geofence>
|
||||
|
||||
@Query("SELECT * FROM places")
|
||||
fun getPlaces(): List<Place>
|
||||
|
||||
@Query("SELECT * FROM places WHERE place_id = :id")
|
||||
fun getPlace(id: Long): Place?
|
||||
|
||||
@Query("SELECT * FROM places WHERE uid = :uid")
|
||||
fun getPlace(uid: String): Place?
|
||||
|
||||
@Query("SELECT places.*, IFNULL(COUNT(geofence_id),0) AS count FROM places LEFT OUTER JOIN geofences ON geofences.place = places.uid GROUP BY uid ORDER BY COUNT(geofence_id) DESC")
|
||||
fun getPlaceUsage(): LiveData<List<PlaceUsage>>
|
||||
|
||||
@Query("SELECT * FROM places WHERE latitude LIKE :latitude AND longitude LIKE :longitude")
|
||||
fun findPlace(latitude: String, longitude: String): Place?
|
||||
|
||||
@Query("SELECT places.*, COUNT(tasks._id) AS count FROM places "
|
||||
+ " LEFT JOIN geofences ON geofences.place = places.uid "
|
||||
+ " LEFT JOIN tasks ON geofences.task = tasks._id AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.hideUntil < :now"
|
||||
+ " GROUP BY places.uid"
|
||||
+ " ORDER BY name COLLATE NOCASE ASC")
|
||||
fun getPlaceFilters(now: Long): List<LocationFilters>
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.helper.UUIDHelper;
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public abstract class TaskAttachmentDao {
|
||||
|
||||
@Query("SELECT * FROM task_attachments WHERE task_id = :taskUuid")
|
||||
public abstract List<TaskAttachment> getAttachments(String taskUuid);
|
||||
|
||||
@Query(
|
||||
"SELECT task_attachments.* FROM task_attachments INNER JOIN tasks ON tasks._id = :task WHERE task_id = tasks.remoteId")
|
||||
public abstract List<TaskAttachment> getAttachments(long task);
|
||||
|
||||
@Query("SELECT * FROM task_attachments")
|
||||
public abstract List<TaskAttachment> getAttachments();
|
||||
|
||||
@Delete
|
||||
public abstract void delete(TaskAttachment taskAttachment);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public abstract void insert(TaskAttachment attachment);
|
||||
|
||||
@Update
|
||||
public abstract void update(TaskAttachment attachment);
|
||||
|
||||
public void createNew(TaskAttachment attachment) {
|
||||
if (Task.isUuidEmpty(attachment.getRemoteId())) {
|
||||
attachment.setRemoteId(UUIDHelper.newUUID());
|
||||
}
|
||||
insert(attachment);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.*
|
||||
import com.todoroo.astrid.data.Task
|
||||
import com.todoroo.astrid.helper.UUIDHelper
|
||||
|
||||
@Dao
|
||||
abstract class TaskAttachmentDao {
|
||||
@Query("SELECT * FROM task_attachments WHERE task_id = :taskUuid")
|
||||
abstract fun getAttachments(taskUuid: String): List<TaskAttachment>
|
||||
|
||||
@Query("SELECT task_attachments.* FROM task_attachments INNER JOIN tasks ON tasks._id = :task WHERE task_id = tasks.remoteId")
|
||||
abstract fun getAttachments(task: Long): List<TaskAttachment>
|
||||
|
||||
@Query("SELECT * FROM task_attachments")
|
||||
abstract fun getAttachments(): List<TaskAttachment>
|
||||
|
||||
@Delete
|
||||
abstract fun delete(taskAttachment: TaskAttachment)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract fun insert(attachment: TaskAttachment)
|
||||
|
||||
@Update
|
||||
abstract fun update(attachment: TaskAttachment)
|
||||
|
||||
fun createNew(attachment: TaskAttachment) {
|
||||
if (Task.isUuidEmpty(attachment.remoteId)) {
|
||||
attachment.remoteId = UUIDHelper.newUUID()
|
||||
}
|
||||
insert(attachment)
|
||||
}
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
@Dao
|
||||
public abstract class TaskListMetadataDao {
|
||||
|
||||
@Query("SELECT * from task_list_metadata where tag_uuid = :tagUuid OR filter = :tagUuid LIMIT 1")
|
||||
public abstract TaskListMetadata fetchByTagOrFilter(String tagUuid);
|
||||
|
||||
@Update
|
||||
public abstract void update(TaskListMetadata taskListMetadata);
|
||||
|
||||
@Insert
|
||||
abstract long insert(TaskListMetadata taskListMetadata);
|
||||
|
||||
public void createNew(TaskListMetadata taskListMetadata) {
|
||||
taskListMetadata.setId(insert(taskListMetadata));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
|
||||
@Dao
|
||||
abstract class TaskListMetadataDao {
|
||||
@Query("SELECT * from task_list_metadata where tag_uuid = :tagUuid OR filter = :tagUuid LIMIT 1")
|
||||
abstract fun fetchByTagOrFilter(tagUuid: String): TaskListMetadata?
|
||||
|
||||
@Update
|
||||
abstract fun update(taskListMetadata: TaskListMetadata)
|
||||
|
||||
@Insert
|
||||
abstract fun insert(taskListMetadata: TaskListMetadata): Long
|
||||
|
||||
fun createNew(taskListMetadata: TaskListMetadata) {
|
||||
taskListMetadata.id = insert(taskListMetadata)
|
||||
}
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
package org.tasks.data;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.helper.UUIDHelper;
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public abstract class UserActivityDao {
|
||||
|
||||
@Insert
|
||||
public abstract void insert(UserActivity userActivity);
|
||||
|
||||
@Update
|
||||
public abstract void update(UserActivity userActivity);
|
||||
|
||||
@Delete
|
||||
public abstract void delete(UserActivity userActivity);
|
||||
|
||||
@Query("SELECT * FROM userActivity WHERE target_id = :taskUuid ORDER BY created_at DESC ")
|
||||
public abstract List<UserActivity> getCommentsForTask(String taskUuid);
|
||||
|
||||
@Query(
|
||||
"SELECT userActivity.* FROM userActivity INNER JOIN tasks ON tasks._id = :task WHERE target_id = tasks.remoteId")
|
||||
public abstract List<UserActivity> getComments(long task);
|
||||
|
||||
@Query("SELECT * FROM userActivity")
|
||||
public abstract List<UserActivity> getComments();
|
||||
|
||||
public void createNew(UserActivity item) {
|
||||
if (item.getCreated() == null || item.getCreated() == 0L) {
|
||||
item.setCreated(DateUtilities.now());
|
||||
}
|
||||
if (Task.isUuidEmpty(item.getRemoteId())) {
|
||||
item.setRemoteId(UUIDHelper.newUUID());
|
||||
}
|
||||
insert(item);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.*
|
||||
import com.todoroo.andlib.utility.DateUtilities
|
||||
import com.todoroo.astrid.data.Task
|
||||
import com.todoroo.astrid.helper.UUIDHelper
|
||||
|
||||
@Dao
|
||||
abstract class UserActivityDao {
|
||||
@Insert
|
||||
abstract fun insert(userActivity: UserActivity)
|
||||
|
||||
@Update
|
||||
abstract fun update(userActivity: UserActivity)
|
||||
|
||||
@Delete
|
||||
abstract fun delete(userActivity: UserActivity)
|
||||
|
||||
@Query("SELECT * FROM userActivity WHERE target_id = :taskUuid ORDER BY created_at DESC ")
|
||||
abstract fun getCommentsForTask(taskUuid: String): List<UserActivity>
|
||||
|
||||
@Query("SELECT userActivity.* FROM userActivity INNER JOIN tasks ON tasks._id = :task WHERE target_id = tasks.remoteId")
|
||||
abstract fun getComments(task: Long): List<UserActivity>
|
||||
|
||||
@Query("SELECT * FROM userActivity")
|
||||
abstract fun getComments(): List<UserActivity>
|
||||
|
||||
fun createNew(item: UserActivity) {
|
||||
if (item.created == null || item.created == 0L) {
|
||||
item.created = DateUtilities.now()
|
||||
}
|
||||
if (Task.isUuidEmpty(item.remoteId)) {
|
||||
item.remoteId = UUIDHelper.newUUID()
|
||||
}
|
||||
insert(item)
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package org.tasks.notifications;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface NotificationDao {
|
||||
|
||||
@Query("SELECT task FROM notification")
|
||||
List<Long> getAll();
|
||||
|
||||
@Query("SELECT * FROM notification ORDER BY timestamp DESC")
|
||||
List<Notification> getAllOrdered();
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<Notification> notifications);
|
||||
|
||||
@Query("DELETE FROM notification WHERE task = :taskId")
|
||||
void delete(long taskId);
|
||||
|
||||
@Query("DELETE FROM notification WHERE task IN(:taskIds)")
|
||||
void deleteAll(List<Long> taskIds);
|
||||
|
||||
@Query("SELECT MAX(timestamp) FROM notification")
|
||||
long latestTimestamp();
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package org.tasks.notifications
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
|
||||
@Dao
|
||||
interface NotificationDao {
|
||||
@Query("SELECT task FROM notification")
|
||||
fun getAll(): List<Long>
|
||||
|
||||
@Query("SELECT * FROM notification ORDER BY timestamp DESC")
|
||||
fun getAllOrdered(): List<Notification>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertAll(notifications: List<Notification>)
|
||||
|
||||
@Query("DELETE FROM notification WHERE task = :taskId")
|
||||
fun delete(taskId: Long)
|
||||
|
||||
@Query("DELETE FROM notification WHERE task IN(:taskIds)")
|
||||
fun deleteAll(taskIds: List<Long>)
|
||||
|
||||
@Query("SELECT MAX(timestamp) FROM notification")
|
||||
fun latestTimestamp(): Long
|
||||
}
|
||||
Loading…
Reference in New Issue