mirror of https://github.com/tasks/tasks
Blocking daos delegate to suspending daos
parent
122a2c2170
commit
f6dd3a63e6
@ -1,31 +1,31 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Dao
|
||||
interface AlarmDaoBlocking {
|
||||
@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>
|
||||
@Deprecated("use coroutines")
|
||||
class AlarmDaoBlocking @Inject constructor(private val dao: AlarmDao) {
|
||||
fun getActiveAlarms(): List<Alarm> = runBlocking {
|
||||
dao.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")
|
||||
fun getActiveAlarms(taskId: Long): List<Alarm>
|
||||
fun getActiveAlarms(taskId: Long): List<Alarm> = runBlocking {
|
||||
dao.getActiveAlarms(taskId)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM alarms WHERE task = :taskId ORDER BY time ASC")
|
||||
fun getAlarms(taskId: Long): List<Alarm>
|
||||
fun getAlarms(taskId: Long): List<Alarm> = runBlocking {
|
||||
dao.getAlarms(taskId)
|
||||
}
|
||||
|
||||
@Delete
|
||||
fun delete(alarm: Alarm)
|
||||
fun delete(alarm: Alarm) = runBlocking {
|
||||
dao.delete(alarm)
|
||||
}
|
||||
|
||||
@Insert
|
||||
fun insert(alarm: Alarm): Long
|
||||
fun insert(alarm: Alarm): Long = runBlocking {
|
||||
dao.insert(alarm)
|
||||
}
|
||||
|
||||
@Insert
|
||||
fun insert(alarms: Iterable<Alarm>)
|
||||
fun insert(alarms: Iterable<Alarm>) = runBlocking {
|
||||
dao.insert(alarms)
|
||||
}
|
||||
}
|
@ -1,47 +1,38 @@
|
||||
package org.tasks.data
|
||||
|
||||
import android.database.Cursor
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
import androidx.room.RawQuery
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.todoroo.astrid.data.Task
|
||||
|
||||
@Dao
|
||||
interface ContentProviderDaoBlocking {
|
||||
@Query("SELECT name FROM tags WHERE task = :taskId ORDER BY UPPER(name) ASC")
|
||||
fun getTagNames(taskId: Long): List<String>
|
||||
|
||||
@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
|
||||
LIMIT 100""")
|
||||
fun getAstrid2TaskProviderTasks(): List<Task>
|
||||
|
||||
@Query("SELECT * FROM tagdata WHERE name IS NOT NULL AND name != '' ORDER BY UPPER(name) ASC")
|
||||
fun tagDataOrderedByName(): List<TagData>
|
||||
|
||||
@Query("SELECT * FROM tasks")
|
||||
fun getTasks(): Cursor
|
||||
|
||||
@Query("""
|
||||
SELECT caldav_lists.*, caldav_accounts.cda_name
|
||||
FROM caldav_lists
|
||||
INNER JOIN caldav_accounts ON cdl_account = cda_uuid""")
|
||||
fun getLists(): Cursor
|
||||
|
||||
@Query("SELECT * FROM google_task_lists")
|
||||
fun getGoogleTaskLists(): Cursor
|
||||
|
||||
@RawQuery
|
||||
fun rawQuery(query: SupportSQLiteQuery): Cursor
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Deprecated("use coroutines")
|
||||
class ContentProviderDaoBlocking @Inject constructor(private val dao: ContentProviderDao) {
|
||||
fun getTagNames(taskId: Long): List<String> = runBlocking {
|
||||
dao.getTagNames(taskId)
|
||||
}
|
||||
|
||||
fun getAstrid2TaskProviderTasks(): List<Task> = runBlocking {
|
||||
dao.getAstrid2TaskProviderTasks()
|
||||
}
|
||||
|
||||
fun tagDataOrderedByName(): List<TagData> = runBlocking {
|
||||
dao.tagDataOrderedByName()
|
||||
}
|
||||
|
||||
fun getTasks(): Cursor {
|
||||
return dao.getTasks()
|
||||
}
|
||||
|
||||
fun getLists(): Cursor {
|
||||
return dao.getLists()
|
||||
}
|
||||
|
||||
fun getGoogleTaskLists(): Cursor {
|
||||
return dao.getGoogleTaskLists()
|
||||
}
|
||||
|
||||
fun rawQuery(query: SupportSQLiteQuery): Cursor {
|
||||
return dao.rawQuery(query)
|
||||
}
|
||||
}
|
@ -1,114 +1,95 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import org.tasks.data.CaldavDao.Companion.LOCAL
|
||||
import org.tasks.db.DbUtils.eachChunk
|
||||
import java.util.*
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Dao
|
||||
abstract class DeletionDaoBlocking {
|
||||
@Query("DELETE FROM caldav_tasks WHERE cd_task IN(:ids)")
|
||||
abstract fun deleteCaldavTasks(ids: List<Long>)
|
||||
@Deprecated("use coroutines")
|
||||
class DeletionDaoBlocking @Inject constructor(private val dao: DeletionDao) {
|
||||
fun deleteCaldavTasks(ids: List<Long>) = runBlocking {
|
||||
dao.deleteCaldavTasks(ids)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM google_tasks WHERE gt_task IN(:ids)")
|
||||
abstract fun deleteGoogleTasks(ids: List<Long>)
|
||||
fun deleteGoogleTasks(ids: List<Long>) = runBlocking {
|
||||
dao.deleteGoogleTasks(ids)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM tags WHERE task IN(:ids)")
|
||||
abstract fun deleteTags(ids: List<Long>)
|
||||
fun deleteTags(ids: List<Long>) = runBlocking {
|
||||
dao.deleteTags(ids)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM geofences WHERE task IN(:ids)")
|
||||
abstract fun deleteGeofences(ids: List<Long>)
|
||||
fun deleteGeofences(ids: List<Long>) = runBlocking {
|
||||
dao.deleteGeofences(ids)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM alarms WHERE task IN(:ids)")
|
||||
abstract fun deleteAlarms(ids: List<Long>)
|
||||
fun deleteAlarms(ids: List<Long>) = runBlocking {
|
||||
dao.deleteAlarms(ids)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM tasks WHERE _id IN(:ids)")
|
||||
abstract fun deleteTasks(ids: List<Long>)
|
||||
fun deleteTasks(ids: List<Long>) = runBlocking {
|
||||
dao.deleteTasks(ids)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open fun delete(ids: List<Long>) {
|
||||
ids.eachChunk {
|
||||
deleteAlarms(it)
|
||||
deleteGeofences(it)
|
||||
deleteTags(it)
|
||||
deleteGoogleTasks(it)
|
||||
deleteCaldavTasks(it)
|
||||
deleteTasks(it)
|
||||
}
|
||||
fun delete(ids: List<Long>) = runBlocking {
|
||||
dao.delete(ids)
|
||||
}
|
||||
|
||||
@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 markDeletedInternal(ids: List<Long>) = runBlocking {
|
||||
dao.markDeletedInternal(ids)
|
||||
}
|
||||
|
||||
fun markDeleted(ids: Iterable<Long>) {
|
||||
ids.eachChunk(this::markDeletedInternal)
|
||||
fun markDeleted(ids: Iterable<Long>) = runBlocking {
|
||||
dao.markDeleted(ids)
|
||||
}
|
||||
|
||||
@Query("SELECT gt_task FROM google_tasks WHERE gt_deleted = 0 AND gt_list_id = :listId")
|
||||
abstract fun getActiveGoogleTasks(listId: String): List<Long>
|
||||
fun getActiveGoogleTasks(listId: String): List<Long> = runBlocking {
|
||||
dao.getActiveGoogleTasks(listId)
|
||||
}
|
||||
|
||||
@Delete
|
||||
abstract fun deleteGoogleTaskList(googleTaskList: GoogleTaskList)
|
||||
fun deleteGoogleTaskList(googleTaskList: GoogleTaskList) = runBlocking {
|
||||
dao.deleteGoogleTaskList(googleTaskList)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open fun delete(googleTaskList: GoogleTaskList): List<Long> {
|
||||
val tasks = getActiveGoogleTasks(googleTaskList.remoteId!!)
|
||||
delete(tasks)
|
||||
deleteGoogleTaskList(googleTaskList)
|
||||
return tasks
|
||||
fun delete(googleTaskList: GoogleTaskList): List<Long> = runBlocking {
|
||||
dao.delete(googleTaskList)
|
||||
}
|
||||
|
||||
@Delete
|
||||
abstract fun deleteGoogleTaskAccount(googleTaskAccount: GoogleTaskAccount)
|
||||
fun deleteGoogleTaskAccount(googleTaskAccount: GoogleTaskAccount) = runBlocking {
|
||||
dao.deleteGoogleTaskAccount(googleTaskAccount)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_account = :account ORDER BY gtl_title ASC")
|
||||
abstract fun getLists(account: String): List<GoogleTaskList>
|
||||
fun getLists(account: String): List<GoogleTaskList> = runBlocking {
|
||||
dao.getLists(account)
|
||||
}
|
||||
|
||||
@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
|
||||
fun delete(googleTaskAccount: GoogleTaskAccount): List<Long> = runBlocking {
|
||||
dao.delete(googleTaskAccount)
|
||||
}
|
||||
|
||||
@Query("SELECT cd_task FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_deleted = 0")
|
||||
abstract fun getActiveCaldavTasks(calendar: String): List<Long>
|
||||
fun getActiveCaldavTasks(calendar: String): List<Long> = runBlocking {
|
||||
dao.getActiveCaldavTasks(calendar)
|
||||
}
|
||||
|
||||
@Delete
|
||||
abstract fun deleteCaldavCalendar(caldavCalendar: CaldavCalendar)
|
||||
fun deleteCaldavCalendar(caldavCalendar: CaldavCalendar) = runBlocking {
|
||||
dao.deleteCaldavCalendar(caldavCalendar)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open fun delete(caldavCalendar: CaldavCalendar): List<Long> {
|
||||
val tasks = getActiveCaldavTasks(caldavCalendar.uuid!!)
|
||||
delete(tasks)
|
||||
deleteCaldavCalendar(caldavCalendar)
|
||||
return tasks
|
||||
fun delete(caldavCalendar: CaldavCalendar): List<Long> = runBlocking {
|
||||
dao.delete(caldavCalendar)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM caldav_lists WHERE cdl_account = :account")
|
||||
abstract fun getCalendars(account: String): List<CaldavCalendar>
|
||||
fun getCalendars(account: String): List<CaldavCalendar> = runBlocking {
|
||||
dao.getCalendars(account)
|
||||
}
|
||||
|
||||
@Delete
|
||||
abstract fun deleteCaldavAccount(caldavAccount: CaldavAccount)
|
||||
fun deleteCaldavAccount(caldavAccount: CaldavAccount) = runBlocking {
|
||||
dao.deleteCaldavAccount(caldavAccount)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM tasks WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task INNER JOIN caldav_lists ON cdl_uuid = cd_calendar WHERE cdl_account = '$LOCAL' AND deleted > 0)")
|
||||
abstract fun purgeDeleted()
|
||||
fun purgeDeleted() = runBlocking {
|
||||
dao.purgeDeleted()
|
||||
}
|
||||
|
||||
@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
|
||||
fun delete(caldavAccount: CaldavAccount): List<Long> = runBlocking {
|
||||
dao.delete(caldavAccount)
|
||||
}
|
||||
}
|
@ -1,37 +1,43 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.todoroo.astrid.api.FilterListItem.NO_ORDER
|
||||
|
||||
@Dao
|
||||
interface FilterDaoBlocking {
|
||||
@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>
|
||||
|
||||
@Query("UPDATE filters SET f_order = $NO_ORDER")
|
||||
fun resetOrders()
|
||||
|
||||
@Query("UPDATE filters SET f_order = :order WHERE _id = :id")
|
||||
fun setOrder(id: Long, order: Int)
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Deprecated("use coroutines")
|
||||
class FilterDaoBlocking @Inject constructor(private val dao: FilterDao) {
|
||||
fun update(filter: Filter) = runBlocking {
|
||||
dao.update(filter)
|
||||
}
|
||||
|
||||
fun delete(id: Long) = runBlocking {
|
||||
dao.delete(id)
|
||||
}
|
||||
|
||||
fun getByName(title: String): Filter? = runBlocking {
|
||||
dao.getByName(title)
|
||||
}
|
||||
|
||||
fun insert(filter: Filter): Long = runBlocking {
|
||||
dao.insert(filter)
|
||||
}
|
||||
|
||||
fun getFilters(): List<Filter> = runBlocking {
|
||||
dao.getFilters()
|
||||
}
|
||||
|
||||
fun getById(id: Long): Filter? = runBlocking {
|
||||
dao.getById(id)
|
||||
}
|
||||
|
||||
fun getAll(): List<Filter> = runBlocking {
|
||||
dao.getAll()
|
||||
}
|
||||
|
||||
fun resetOrders() = runBlocking {
|
||||
dao.resetOrders()
|
||||
}
|
||||
|
||||
fun setOrder(id: Long, order: Int) = runBlocking {
|
||||
dao.setOrder(id, order)
|
||||
}
|
||||
}
|
@ -1,179 +1,137 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.*
|
||||
import com.todoroo.astrid.data.Task
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.tasks.time.DateTimeUtils.currentTimeMillis
|
||||
import javax.inject.Inject
|
||||
|
||||
@Dao
|
||||
abstract class GoogleTaskDaoBlocking {
|
||||
@Insert
|
||||
abstract fun insert(task: GoogleTask): Long
|
||||
@Deprecated("use coroutines")
|
||||
class GoogleTaskDaoBlocking @Inject constructor(private val dao: GoogleTaskDao) {
|
||||
fun insert(task: GoogleTask): Long = runBlocking {
|
||||
dao.insert(task)
|
||||
}
|
||||
|
||||
fun insert(tasks: Iterable<GoogleTask>) = runBlocking {
|
||||
dao.insert(tasks)
|
||||
}
|
||||
|
||||
fun insertAndShift(task: GoogleTask, top: Boolean) = runBlocking {
|
||||
dao.insertAndShift(task, top)
|
||||
}
|
||||
|
||||
fun shiftDown(listId: String, parent: Long, position: Long) = runBlocking {
|
||||
dao.shiftDown(listId, parent, position)
|
||||
}
|
||||
|
||||
fun shiftUp(listId: String, parent: Long, from: Long, to: Long) = runBlocking {
|
||||
dao.shiftUp(listId, parent, from, to)
|
||||
}
|
||||
|
||||
fun shiftDown(listId: String, parent: Long, from: Long, to: Long) = runBlocking {
|
||||
dao.shiftDown(listId, parent, from, to)
|
||||
}
|
||||
|
||||
fun shiftUp(listId: String, parent: Long, position: Long) = runBlocking {
|
||||
dao.shiftUp(listId, parent, position)
|
||||
}
|
||||
|
||||
fun move(task: SubsetGoogleTask, newParent: Long, newPosition: Long) = runBlocking {
|
||||
dao.move(task, newParent, newPosition)
|
||||
}
|
||||
|
||||
fun setCollapsed(id: Long, collapsed: Boolean) = runBlocking {
|
||||
dao.setCollapsed(id, collapsed)
|
||||
}
|
||||
|
||||
fun getByTaskId(taskId: Long): GoogleTask? = runBlocking {
|
||||
dao.getByTaskId(taskId)
|
||||
}
|
||||
|
||||
fun update(googleTask: GoogleTask) = runBlocking {
|
||||
dao.update(googleTask)
|
||||
}
|
||||
|
||||
fun update(id: Long, parent: Long, order: Long) = runBlocking {
|
||||
dao.update(id, parent, order)
|
||||
}
|
||||
|
||||
fun markDeleted(task: Long, now: Long = currentTimeMillis()) = runBlocking {
|
||||
dao.markDeleted(task, now)
|
||||
}
|
||||
|
||||
fun delete(deleted: GoogleTask) = runBlocking {
|
||||
dao.delete(deleted)
|
||||
}
|
||||
|
||||
@Insert
|
||||
abstract fun insert(tasks: Iterable<GoogleTask>)
|
||||
fun getByRemoteId(remoteId: String): GoogleTask? = runBlocking {
|
||||
dao.getByRemoteId(remoteId)
|
||||
}
|
||||
|
||||
fun getDeletedByTaskId(taskId: Long): List<GoogleTask> = runBlocking {
|
||||
dao.getDeletedByTaskId(taskId)
|
||||
}
|
||||
|
||||
fun getAllByTaskId(taskId: Long): List<GoogleTask> = runBlocking {
|
||||
dao.getAllByTaskId(taskId)
|
||||
}
|
||||
|
||||
fun getLists(tasks: List<Long>): List<String> = runBlocking {
|
||||
dao.getLists(tasks)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open fun insertAndShift(task: GoogleTask, top: Boolean) {
|
||||
if (top) {
|
||||
task.order = 0
|
||||
shiftDown(task.listId!!, task.parent, 0)
|
||||
} else {
|
||||
task.order = getBottom(task.listId!!, task.parent)
|
||||
}
|
||||
task.id = insert(task)
|
||||
fun getChildren(ids: List<Long>): List<Long> = runBlocking {
|
||||
dao.getChildren(ids)
|
||||
}
|
||||
|
||||
@Query("UPDATE google_tasks SET gt_order = gt_order + 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order >= :position")
|
||||
abstract fun shiftDown(listId: String, parent: Long, position: Long)
|
||||
fun getChildTasks(taskId: Long): List<Task> = runBlocking {
|
||||
dao.getChildTasks(taskId)
|
||||
}
|
||||
|
||||
fun getChildren(id: Long): List<GoogleTask> = runBlocking {
|
||||
dao.getChildren(id)
|
||||
}
|
||||
|
||||
@Query("UPDATE google_tasks SET gt_order = gt_order - 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order > :from AND gt_order <= :to")
|
||||
abstract fun shiftUp(listId: String, parent: Long, from: Long, to: Long)
|
||||
fun getBottom(listId: String, parent: Long): Long = runBlocking {
|
||||
dao.getBottom(listId, parent)
|
||||
}
|
||||
|
||||
@Query("UPDATE google_tasks SET gt_order = gt_order + 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order < :from AND gt_order >= :to")
|
||||
abstract fun shiftDown(listId: String, parent: Long, from: Long, to: Long)
|
||||
fun getPrevious(listId: String, parent: Long, order: Long): String? = runBlocking {
|
||||
dao.getPrevious(listId, parent, order)
|
||||
}
|
||||
|
||||
fun getRemoteId(task: Long): String? = runBlocking {
|
||||
dao.getRemoteId(task)
|
||||
}
|
||||
|
||||
@Query("UPDATE google_tasks SET gt_order = gt_order - 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order >= :position")
|
||||
abstract fun shiftUp(listId: String, parent: Long, position: Long)
|
||||
fun getTask(remoteId: String): Long = runBlocking {
|
||||
dao.getTask(remoteId)
|
||||
}
|
||||
|
||||
fun getByLocalOrder(listId: String): List<GoogleTask> = runBlocking {
|
||||
dao.getByLocalOrder(listId)
|
||||
}
|
||||
|
||||
fun getByRemoteOrder(listId: String): List<GoogleTask> = runBlocking {
|
||||
dao.getByRemoteOrder(listId)
|
||||
}
|
||||
|
||||
fun updateParents() = runBlocking {
|
||||
dao.updateParents()
|
||||
}
|
||||
|
||||
fun updateParents(listId: String) = runBlocking {
|
||||
dao.updateParents(listId)
|
||||
}
|
||||
|
||||
fun updatePosition(id: String, parent: String, position: String) = runBlocking {
|
||||
dao.updatePosition(id, parent, position)
|
||||
}
|
||||
|
||||
fun reposition(listId: String) = runBlocking {
|
||||
dao.reposition(listId)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open fun move(task: SubsetGoogleTask, newParent: Long, newPosition: Long) {
|
||||
val previousParent = task.parent
|
||||
val previousPosition = task.order
|
||||
if (newParent == previousParent) {
|
||||
if (previousPosition < newPosition) {
|
||||
shiftUp(task.listId, newParent, previousPosition, newPosition)
|
||||
} else {
|
||||
shiftDown(task.listId, newParent, previousPosition, newPosition)
|
||||
}
|
||||
} else {
|
||||
shiftUp(task.listId, previousParent, previousPosition)
|
||||
shiftDown(task.listId, newParent, newPosition)
|
||||
}
|
||||
task.parent = newParent
|
||||
task.order = newPosition
|
||||
update(task)
|
||||
}
|
||||
|
||||
@Query("UPDATE google_task_accounts SET gta_collapsed = :collapsed WHERE gta_id = :id")
|
||||
abstract fun setCollapsed(id: Long, collapsed: Boolean)
|
||||
|
||||
@Query("SELECT * FROM google_tasks WHERE gt_task = :taskId AND gt_deleted = 0 LIMIT 1")
|
||||
abstract fun getByTaskId(taskId: Long): GoogleTask?
|
||||
|
||||
@Update
|
||||
abstract fun update(googleTask: GoogleTask)
|
||||
|
||||
private fun update(googleTask: SubsetGoogleTask) {
|
||||
update(googleTask.id, googleTask.parent, googleTask.order)
|
||||
}
|
||||
|
||||
@Query("UPDATE google_tasks SET gt_order = :order, gt_parent = :parent, gt_moved = 1 WHERE gt_id = :id")
|
||||
abstract fun update(id: Long, parent: Long, order: Long)
|
||||
|
||||
@Query("UPDATE google_tasks SET gt_deleted = :now WHERE gt_task = :task OR gt_parent = :task")
|
||||
abstract fun markDeleted(task: Long, now: Long = currentTimeMillis())
|
||||
|
||||
@Delete
|
||||
abstract fun delete(deleted: GoogleTask)
|
||||
|
||||
@Query("SELECT * FROM google_tasks WHERE gt_remote_id = :remoteId LIMIT 1")
|
||||
abstract fun getByRemoteId(remoteId: String): GoogleTask?
|
||||
|
||||
@Query("SELECT * FROM google_tasks WHERE gt_task = :taskId AND gt_deleted > 0")
|
||||
abstract fun getDeletedByTaskId(taskId: Long): List<GoogleTask>
|
||||
|
||||
@Query("SELECT * FROM google_tasks WHERE gt_task = :taskId")
|
||||
abstract fun getAllByTaskId(taskId: Long): List<GoogleTask>
|
||||
|
||||
@Query("SELECT DISTINCT gt_list_id FROM google_tasks WHERE gt_deleted = 0 AND gt_task IN (:tasks)")
|
||||
abstract fun getLists(tasks: List<Long>): List<String>
|
||||
|
||||
@Query("SELECT gt_task FROM google_tasks WHERE gt_parent IN (:ids) AND gt_deleted = 0")
|
||||
abstract fun getChildren(ids: List<Long>): List<Long>
|
||||
|
||||
@Query("SELECT tasks.* FROM tasks JOIN google_tasks ON tasks._id = gt_task WHERE gt_parent = :taskId")
|
||||
abstract fun getChildTasks(taskId: Long): List<Task>
|
||||
|
||||
@Query("SELECT * FROM google_tasks WHERE gt_parent = :id AND gt_deleted = 0")
|
||||
abstract fun getChildren(id: Long): List<GoogleTask>
|
||||
|
||||
@Query("SELECT IFNULL(MAX(gt_order), -1) + 1 FROM google_tasks WHERE gt_list_id = :listId AND gt_parent = :parent")
|
||||
abstract fun getBottom(listId: String, parent: Long): Long
|
||||
|
||||
@Query("SELECT gt_remote_id FROM google_tasks JOIN tasks ON tasks._id = gt_task WHERE deleted = 0 AND gt_list_id = :listId AND gt_parent = :parent AND gt_order < :order AND gt_remote_id IS NOT NULL AND gt_remote_id != '' ORDER BY gt_order DESC")
|
||||
abstract fun getPrevious(listId: String, parent: Long, order: Long): String?
|
||||
|
||||
@Query("SELECT gt_remote_id FROM google_tasks WHERE gt_task = :task")
|
||||
abstract fun getRemoteId(task: Long): String?
|
||||
|
||||
@Query("SELECT gt_task FROM google_tasks WHERE gt_remote_id = :remoteId")
|
||||
abstract fun getTask(remoteId: String): Long
|
||||
|
||||
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
|
||||
@Query("SELECT google_tasks.*, gt_order AS primary_sort, NULL AS secondary_sort FROM google_tasks JOIN tasks ON tasks._id = gt_task WHERE gt_parent = 0 AND gt_list_id = :listId AND tasks.deleted = 0 UNION SELECT c.*, p.gt_order AS primary_sort, c.gt_order AS secondary_sort FROM google_tasks AS c LEFT JOIN google_tasks AS p ON c.gt_parent = p.gt_task JOIN tasks ON tasks._id = c.gt_task WHERE c.gt_parent > 0 AND c.gt_list_id = :listId AND tasks.deleted = 0 ORDER BY primary_sort ASC, secondary_sort ASC")
|
||||
abstract fun getByLocalOrder(listId: String): List<GoogleTask>
|
||||
|
||||
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
|
||||
@Query("SELECT google_tasks.*, gt_remote_order AS primary_sort, NULL AS secondary_sort FROM google_tasks JOIN tasks ON tasks._id = gt_task WHERE gt_parent = 0 AND gt_list_id = :listId AND tasks.deleted = 0 UNION SELECT c.*, p.gt_remote_order AS primary_sort, c.gt_remote_order AS secondary_sort FROM google_tasks AS c LEFT JOIN google_tasks AS p ON c.gt_parent = p.gt_task JOIN tasks ON tasks._id = c.gt_task WHERE c.gt_parent > 0 AND c.gt_list_id = :listId AND tasks.deleted = 0 ORDER BY primary_sort ASC, secondary_sort ASC")
|
||||
abstract fun getByRemoteOrder(listId: String): List<GoogleTask>
|
||||
|
||||
@Query("UPDATE google_tasks"
|
||||
+ " SET gt_parent = IFNULL(("
|
||||
+ " SELECT gt_task FROM google_tasks AS p"
|
||||
+ " WHERE p.gt_remote_id = google_tasks.gt_remote_parent"
|
||||
+ " AND p.gt_list_id = google_tasks.gt_list_id "
|
||||
+ " AND p.gt_deleted = 0),"
|
||||
+ " 0)"
|
||||
+ " WHERE gt_moved = 0")
|
||||
abstract fun updateParents()
|
||||
|
||||
@Query("UPDATE google_tasks SET gt_parent = IFNULL((SELECT gt_task FROM google_tasks AS p WHERE p.gt_remote_id = google_tasks.gt_remote_parent), 0) WHERE gt_list_id = :listId AND gt_moved = 0")
|
||||
abstract fun updateParents(listId: String)
|
||||
|
||||
@Query("UPDATE google_tasks SET gt_remote_parent = :parent, gt_remote_order = :position WHERE gt_remote_id = :id")
|
||||
abstract fun updatePosition(id: String, parent: String, position: String)
|
||||
|
||||
@Transaction
|
||||
open fun reposition(listId: String) {
|
||||
updateParents(listId)
|
||||
val orderedTasks = getByRemoteOrder(listId)
|
||||
var subtasks = 0L
|
||||
var parent = 0L
|
||||
for (task in orderedTasks) {
|
||||
if (task.parent > 0) {
|
||||
if (task.order != subtasks && !task.isMoved) {
|
||||
task.order = subtasks
|
||||
update(task)
|
||||
}
|
||||
subtasks++
|
||||
} else {
|
||||
subtasks = 0
|
||||
if (task.order != parent && !task.isMoved) {
|
||||
task.order = parent
|
||||
update(task)
|
||||
}
|
||||
parent++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun validateSorting(listId: String) {
|
||||
val orderedTasks = getByLocalOrder(listId)
|
||||
var subtasks = 0L
|
||||
var parent = 0L
|
||||
for (task in orderedTasks) {
|
||||
if (task.parent > 0) {
|
||||
if (task.order != subtasks) {
|
||||
throw IllegalStateException("Subtask violation, expected $subtasks but was ${task.order}")
|
||||
}
|
||||
subtasks++
|
||||
} else {
|
||||
subtasks = 0
|
||||
if (task.order != parent) {
|
||||
throw IllegalStateException("Parent violation, expected $parent but was ${task.order}")
|
||||
}
|
||||
parent++
|
||||
}
|
||||
}
|
||||
fun validateSorting(listId: String) = runBlocking {
|
||||
dao.validateSorting(listId)
|
||||
}
|
||||
}
|
@ -1,72 +1,86 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import com.todoroo.astrid.api.FilterListItem.NO_ORDER
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.tasks.filters.GoogleTaskFilters
|
||||
import org.tasks.time.DateTimeUtils.currentTimeMillis
|
||||
import javax.inject.Inject
|
||||
|
||||
@Dao
|
||||
interface GoogleTaskListDaoBlocking {
|
||||
@Query("SELECT COUNT(*) FROM google_task_accounts")
|
||||
fun accountCount(): Int
|
||||
@Deprecated("use coroutines")
|
||||
class GoogleTaskListDaoBlocking @Inject constructor(private val dao: GoogleTaskListDao) {
|
||||
fun accountCount(): Int = runBlocking {
|
||||
dao.accountCount()
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM google_task_accounts")
|
||||
fun getAccounts(): List<GoogleTaskAccount>
|
||||
fun getAccounts(): List<GoogleTaskAccount> = runBlocking {
|
||||
dao.getAccounts()
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM google_task_accounts WHERE gta_account = :account COLLATE NOCASE LIMIT 1")
|
||||
fun getAccount(account: String): GoogleTaskAccount?
|
||||
fun getAccount(account: String): GoogleTaskAccount? = runBlocking {
|
||||
dao.getAccount(account)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_id = :id")
|
||||
fun getById(id: Long): GoogleTaskList?
|
||||
fun getById(id: Long): GoogleTaskList? = runBlocking {
|
||||
dao.getById(id)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_account = :account ORDER BY gtl_title ASC")
|
||||
fun getLists(account: String): List<GoogleTaskList>
|
||||
fun getLists(account: String): List<GoogleTaskList> = runBlocking {
|
||||
dao.getLists(account)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_remote_id = :remoteId LIMIT 1")
|
||||
fun getByRemoteId(remoteId: String): GoogleTaskList?
|
||||
fun getByRemoteId(remoteId: String): GoogleTaskList? = runBlocking {
|
||||
dao.getByRemoteId(remoteId)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_remote_id IN (:remoteIds)")
|
||||
fun getByRemoteId(remoteIds: List<String>): List<GoogleTaskList>
|
||||
fun getByRemoteId(remoteIds: List<String>): List<GoogleTaskList> = runBlocking {
|
||||
dao.getByRemoteId(remoteIds)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM google_task_lists")
|
||||
fun subscribeToLists(): LiveData<List<GoogleTaskList>>
|
||||
fun subscribeToLists(): LiveData<List<GoogleTaskList>> {
|
||||
return dao.subscribeToLists()
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM google_task_lists WHERE gtl_remote_id = :remoteId AND IFNULL(gtl_account, '') = ''")
|
||||
fun findExistingList(remoteId: String): GoogleTaskList?
|
||||
fun findExistingList(remoteId: String): GoogleTaskList? = runBlocking {
|
||||
dao.findExistingList(remoteId)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM google_task_lists")
|
||||
fun getAllLists(): List<GoogleTaskList>
|
||||
fun getAllLists(): List<GoogleTaskList> = runBlocking {
|
||||
dao.getAllLists()
|
||||
}
|
||||
|
||||
@Query("UPDATE google_task_lists SET gtl_last_sync = 0 WHERE gtl_account = :account")
|
||||
fun resetLastSync(account: String)
|
||||
fun resetLastSync(account: String) = runBlocking {
|
||||
dao.resetLastSync(account)
|
||||
}
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertOrReplace(googleTaskList: GoogleTaskList): Long
|
||||
fun insertOrReplace(googleTaskList: GoogleTaskList): Long = runBlocking {
|
||||
dao.insertOrReplace(googleTaskList)
|
||||
}
|
||||
|
||||
@Insert
|
||||
fun insert(googleTaskList: GoogleTaskList): Long
|
||||
fun insert(googleTaskList: GoogleTaskList): Long = runBlocking {
|
||||
dao.insert(googleTaskList)
|
||||
}
|
||||
|
||||
@Insert
|
||||
fun insert(googleTaskAccount: GoogleTaskAccount)
|
||||
fun insert(googleTaskAccount: GoogleTaskAccount) = runBlocking {
|
||||
dao.insert(googleTaskAccount)
|
||||
}
|
||||
|
||||
@Update
|
||||
fun update(account: GoogleTaskAccount)
|
||||
fun update(account: GoogleTaskAccount) = runBlocking {
|
||||
dao.update(account)
|
||||
}
|
||||
|
||||
@Update
|
||||
fun update(list: GoogleTaskList)
|
||||
fun update(list: GoogleTaskList) = runBlocking {
|
||||
dao.update(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")
|
||||
fun getGoogleTaskFilters(account: String, now: Long = currentTimeMillis()): List<GoogleTaskFilters>
|
||||
fun getGoogleTaskFilters(account: String, now: Long = currentTimeMillis()): List<GoogleTaskFilters> = runBlocking {
|
||||
dao.getGoogleTaskFilters(account, now)
|
||||
}
|
||||
|
||||
@Query("UPDATE google_task_lists SET gtl_remote_order = $NO_ORDER")
|
||||
fun resetOrders()
|
||||
fun resetOrders() = runBlocking {
|
||||
dao.resetOrders()
|
||||
}
|
||||
|
||||
@Query("UPDATE google_task_lists SET gtl_remote_order = :order WHERE gtl_id = :id")
|
||||
fun setOrder(id: Long, order: Int)
|
||||
fun setOrder(id: Long, order: Int) = runBlocking {
|
||||
dao.setOrder(id, order)
|
||||
}
|
||||
}
|
@ -1,118 +1,114 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import com.todoroo.astrid.api.FilterListItem.NO_ORDER
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.tasks.filters.LocationFilters
|
||||
import org.tasks.time.DateTimeUtils.currentTimeMillis
|
||||
import javax.inject.Inject
|
||||
|
||||
@Dao
|
||||
interface LocationDaoBlocking {
|
||||
@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")
|
||||
suspend fun geofenceCount(): 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 = currentTimeMillis()): List<LocationFilters>
|
||||
|
||||
@Query("UPDATE places SET place_order = $NO_ORDER")
|
||||
fun resetOrders()
|
||||
@Deprecated("use coroutines")
|
||||
class LocationDaoBlocking @Inject constructor(private val dao: LocationDao) {
|
||||
fun getPlacesWithGeofences(): List<Place> = runBlocking {
|
||||
dao.getPlacesWithGeofences()
|
||||
}
|
||||
|
||||
@Query("UPDATE places SET place_order = :order WHERE place_id = :id")
|
||||
fun setOrder(id: Long, order: Int)
|
||||
fun getGeofencesByPlace(uid: String): MergedGeofence? = runBlocking {
|
||||
dao.getGeofencesByPlace(uid)
|
||||
}
|
||||
|
||||
fun deleteGeofencesByPlace(place: String) = runBlocking {
|
||||
dao.deleteGeofencesByPlace(place)
|
||||
}
|
||||
|
||||
fun getArrivalGeofences(place: String, now: Long): List<Geofence> = runBlocking {
|
||||
dao.getArrivalGeofences(place, now)
|
||||
}
|
||||
|
||||
fun getDepartureGeofences(place: String, now: Long): List<Geofence> = runBlocking {
|
||||
dao.getDepartureGeofences(place, now)
|
||||
}
|
||||
|
||||
fun getGeofences(taskId: Long): Location? = runBlocking {
|
||||
dao.getGeofences(taskId)
|
||||
}
|
||||
|
||||
fun getActiveGeofences(taskId: Long): List<Location> = runBlocking {
|
||||
dao.getActiveGeofences(taskId)
|
||||
}
|
||||
|
||||
fun getPlaceForTask(taskId: Long): Place? = runBlocking {
|
||||
dao.getPlaceForTask(taskId)
|
||||
}
|
||||
|
||||
fun getActiveGeofences(): List<Location> = runBlocking {
|
||||
dao.getActiveGeofences()
|
||||
}
|
||||
|
||||
suspend fun geofenceCount(): Int {
|
||||
return dao.geofenceCount()
|
||||
}
|
||||
|
||||
fun delete(location: Geofence) = runBlocking {
|
||||
dao.delete(location)
|
||||
}
|
||||
|
||||
fun delete(place: Place) = runBlocking {
|
||||
dao.delete(place)
|
||||
}
|
||||
|
||||
fun insert(location: Geofence): Long = runBlocking {
|
||||
dao.insert(location)
|
||||
}
|
||||
|
||||
fun insert(place: Place): Long = runBlocking {
|
||||
dao.insert(place)
|
||||
}
|
||||
|
||||
fun update(place: Place) = runBlocking {
|
||||
dao.update(place)
|
||||
}
|
||||
|
||||
fun update(geofence: Geofence) = runBlocking {
|
||||
dao.update(geofence)
|
||||
}
|
||||
|
||||
fun getByUid(uid: String): Place? = runBlocking {
|
||||
dao.getByUid(uid)
|
||||
}
|
||||
|
||||
fun getGeofencesForTask(taskId: Long): List<Geofence> = runBlocking {
|
||||
dao.getGeofencesForTask(taskId)
|
||||
}
|
||||
|
||||
fun getPlaces(): List<Place> = runBlocking {
|
||||
dao.getPlaces()
|
||||
}
|
||||
|
||||
fun getPlace(id: Long): Place? = runBlocking {
|
||||
dao.getPlace(id)
|
||||
}
|
||||
|
||||
fun getPlace(uid: String): Place? = runBlocking {
|
||||
dao.getPlace(uid)
|
||||
}
|
||||
|
||||
fun getPlaceUsage(): LiveData<List<PlaceUsage>> {
|
||||
return dao.getPlaceUsage()
|
||||
}
|
||||
|
||||
fun findPlace(latitude: String, longitude: String): Place? = runBlocking {
|
||||
dao.findPlace(latitude, longitude)
|
||||
}
|
||||
|
||||
fun getPlaceFilters(now: Long = currentTimeMillis()): List<LocationFilters> = runBlocking {
|
||||
dao.getPlaceFilters(now)
|
||||
}
|
||||
|
||||
fun resetOrders() = runBlocking {
|
||||
dao.resetOrders()
|
||||
}
|
||||
|
||||
fun setOrder(id: Long, order: Int) = runBlocking {
|
||||
dao.setOrder(id, order)
|
||||
}
|
||||
}
|
@ -1,49 +1,48 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.*
|
||||
import com.todoroo.astrid.data.Task
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Dao
|
||||
abstract class TagDaoBlocking {
|
||||
@Query("UPDATE tags SET name = :name WHERE tag_uid = :tagUid")
|
||||
abstract fun rename(tagUid: String, name: String)
|
||||
@Deprecated("use coroutines")
|
||||
class TagDaoBlocking @Inject constructor(private val dao: TagDao) {
|
||||
fun rename(tagUid: String, name: String) = runBlocking {
|
||||
dao.rename(tagUid, name)
|
||||
}
|
||||
|
||||
@Insert
|
||||
abstract fun insert(tag: Tag)
|
||||
fun insert(tag: Tag) = runBlocking {
|
||||
dao.insert(tag)
|
||||
}
|
||||
|
||||
@Insert
|
||||
abstract fun insert(tags: Iterable<Tag>)
|
||||
fun insert(tags: Iterable<Tag>) = runBlocking {
|
||||
dao.insert(tags)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM tags WHERE task = :taskId AND tag_uid in (:tagUids)")
|
||||
abstract fun deleteTags(taskId: Long, tagUids: List<String>)
|
||||
fun deleteTags(taskId: Long, tagUids: List<String>) = runBlocking {
|
||||
dao.deleteTags(taskId, tagUids)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM tags WHERE tag_uid = :tagUid")
|
||||
abstract fun getByTagUid(tagUid: String): List<Tag>
|
||||
fun getByTagUid(tagUid: String): List<Tag> = runBlocking {
|
||||
dao.getByTagUid(tagUid)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM tags WHERE task = :taskId")
|
||||
abstract fun getTagsForTask(taskId: Long): List<Tag>
|
||||
fun getTagsForTask(taskId: Long): List<Tag> = runBlocking {
|
||||
dao.getTagsForTask(taskId)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM tags WHERE task = :taskId AND tag_uid = :tagUid")
|
||||
abstract fun getTagByTaskAndTagUid(taskId: Long, tagUid: String): Tag?
|
||||
fun getTagByTaskAndTagUid(taskId: Long, tagUid: String): Tag? = runBlocking {
|
||||
dao.getTagByTaskAndTagUid(taskId, tagUid)
|
||||
}
|
||||
|
||||
@Delete
|
||||
abstract fun delete(tags: List<Tag>)
|
||||
fun delete(tags: List<Tag>) = runBlocking {
|
||||
dao.delete(tags)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open fun applyTags(task: Task, tagDataDao: TagDataDaoBlocking, current: List<TagData>): Boolean {
|
||||
val taskId = task.id
|
||||
val existing = HashSet(tagDataDao.getTagDataForTask(taskId))
|
||||
val selected = HashSet<TagData>(current)
|
||||
val added = selected subtract existing
|
||||
val removed = existing subtract selected
|
||||
deleteTags(taskId, removed.map { td -> td.remoteId!! })
|
||||
insert(task, added)
|
||||
return removed.isNotEmpty() || added.isNotEmpty()
|
||||
fun applyTags(task: Task, tagDataDao: TagDataDaoBlocking, current: List<TagData>): Boolean = runBlocking {
|
||||
dao.applyTags(task, tagDataDao, current)
|
||||
}
|
||||
|
||||
fun insert(task: Task, tags: Collection<TagData>) {
|
||||
if (!tags.isEmpty()) {
|
||||
insert(tags.map { Tag(task, it) })
|
||||
}
|
||||
fun insert(task: Task, tags: Collection<TagData>) = runBlocking {
|
||||
dao.insert(task, tags)
|
||||
}
|
||||
}
|
@ -1,33 +1,35 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.*
|
||||
import com.todoroo.astrid.data.Task
|
||||
import com.todoroo.astrid.helper.UUIDHelper
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Dao
|
||||
abstract class TaskAttachmentDaoBlocking {
|
||||
@Query("SELECT * FROM task_attachments WHERE task_id = :taskUuid")
|
||||
abstract fun getAttachments(taskUuid: String): List<TaskAttachment>
|
||||
@Deprecated("use coroutines")
|
||||
class TaskAttachmentDaoBlocking @Inject constructor(private val dao: TaskAttachmentDao) {
|
||||
fun getAttachments(taskUuid: String): List<TaskAttachment> = runBlocking {
|
||||
dao.getAttachments(taskUuid)
|
||||
}
|
||||
|
||||
@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>
|
||||
fun getAttachments(task: Long): List<TaskAttachment> = runBlocking {
|
||||
dao.getAttachments(task)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM task_attachments")
|
||||
abstract fun getAttachments(): List<TaskAttachment>
|
||||
fun getAttachments(): List<TaskAttachment> = runBlocking {
|
||||
dao.getAttachments()
|
||||
}
|
||||
|
||||
@Delete
|
||||
abstract fun delete(taskAttachment: TaskAttachment)
|
||||
fun delete(taskAttachment: TaskAttachment) = runBlocking {
|
||||
dao.delete(taskAttachment)
|
||||
}
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract fun insert(attachment: TaskAttachment)
|
||||
fun insert(attachment: TaskAttachment) = runBlocking {
|
||||
dao.insert(attachment)
|
||||
}
|
||||
|
||||
@Update
|
||||
abstract fun update(attachment: TaskAttachment)
|
||||
fun update(attachment: TaskAttachment) = runBlocking {
|
||||
dao.update(attachment)
|
||||
}
|
||||
|
||||
fun createNew(attachment: TaskAttachment) {
|
||||
if (Task.isUuidEmpty(attachment.remoteId)) {
|
||||
attachment.remoteId = UUIDHelper.newUUID()
|
||||
}
|
||||
insert(attachment)
|
||||
fun createNew(attachment: TaskAttachment) = runBlocking {
|
||||
dao.createNew(attachment)
|
||||
}
|
||||
}
|
@ -1,25 +1,27 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Dao
|
||||
abstract class TaskListMetadataDaoBlocking {
|
||||
@Query("SELECT * from task_list_metadata where tag_uuid = :tagUuid OR filter = :tagUuid LIMIT 1")
|
||||
abstract fun fetchByTagOrFilter(tagUuid: String): TaskListMetadata?
|
||||
@Deprecated("use coroutines")
|
||||
class TaskListMetadataDaoBlocking @Inject constructor(private val dao: TaskListMetadataDao) {
|
||||
fun fetchByTagOrFilter(tagUuid: String): TaskListMetadata? = runBlocking {
|
||||
dao.fetchByTagOrFilter(tagUuid)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM task_list_metadata")
|
||||
abstract fun getAll(): List<TaskListMetadata>
|
||||
fun getAll(): List<TaskListMetadata> = runBlocking {
|
||||
dao.getAll()
|
||||
}
|
||||
|
||||
@Update
|
||||
abstract fun update(taskListMetadata: TaskListMetadata)
|
||||
fun update(taskListMetadata: TaskListMetadata) = runBlocking {
|
||||
dao.update(taskListMetadata)
|
||||
}
|
||||
|
||||
@Insert
|
||||
abstract fun insert(taskListMetadata: TaskListMetadata): Long
|
||||
fun insert(taskListMetadata: TaskListMetadata): Long = runBlocking {
|
||||
dao.insert(taskListMetadata)
|
||||
}
|
||||
|
||||
fun createNew(taskListMetadata: TaskListMetadata) {
|
||||
taskListMetadata.id = insert(taskListMetadata)
|
||||
fun createNew(taskListMetadata: TaskListMetadata) = runBlocking {
|
||||
dao.createNew(taskListMetadata)
|
||||
}
|
||||
}
|
@ -1,37 +1,35 @@
|
||||
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 UserActivityDaoBlocking {
|
||||
@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)
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Deprecated("use coroutines")
|
||||
class UserActivityDaoBlocking @Inject constructor(private val dao: UserActivityDao) {
|
||||
fun insert(userActivity: UserActivity) = runBlocking {
|
||||
dao.insert(userActivity)
|
||||
}
|
||||
|
||||
fun update(userActivity: UserActivity) = runBlocking {
|
||||
dao.update(userActivity)
|
||||
}
|
||||
|
||||
fun delete(userActivity: UserActivity) = runBlocking {
|
||||
dao.delete(userActivity)
|
||||
}
|
||||
|
||||
fun getCommentsForTask(taskUuid: String): List<UserActivity> = runBlocking {
|
||||
dao.getCommentsForTask(taskUuid)
|
||||
}
|
||||
|
||||
fun getComments(task: Long): List<UserActivity> = runBlocking {
|
||||
dao.getComments(task)
|
||||
}
|
||||
|
||||
fun getComments(): List<UserActivity> = runBlocking {
|
||||
dao.getComments()
|
||||
}
|
||||
|
||||
fun createNew(item: UserActivity) = runBlocking {
|
||||
dao.createNew(item)
|
||||
}
|
||||
}
|
@ -1,27 +1,31 @@
|
||||
package org.tasks.notifications
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Dao
|
||||
interface NotificationDaoBlocking {
|
||||
@Query("SELECT task FROM notification")
|
||||
fun getAll(): List<Long>
|
||||
@Deprecated("use coroutines")
|
||||
class NotificationDaoBlocking @Inject constructor(private val dao: NotificationDao) {
|
||||
fun getAll(): List<Long> = runBlocking {
|
||||
dao.getAll()
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM notification ORDER BY timestamp DESC")
|
||||
fun getAllOrdered(): List<Notification>
|
||||
fun getAllOrdered(): List<Notification> = runBlocking {
|
||||
dao.getAllOrdered()
|
||||
}
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertAll(notifications: List<Notification>)
|
||||
fun insertAll(notifications: List<Notification>) = runBlocking {
|
||||
dao.insertAll(notifications)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM notification WHERE task = :taskId")
|
||||
fun delete(taskId: Long)
|
||||
fun delete(taskId: Long) = runBlocking {
|
||||
dao.delete(taskId)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM notification WHERE task IN(:taskIds)")
|
||||
fun deleteAll(taskIds: List<Long>)
|
||||
fun deleteAll(taskIds: List<Long>) = runBlocking {
|
||||
dao.deleteAll(taskIds)
|
||||
}
|
||||
|
||||
@Query("SELECT MAX(timestamp) FROM notification")
|
||||
fun latestTimestamp(): Long
|
||||
fun latestTimestamp(): Long = runBlocking {
|
||||
dao.latestTimestamp()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue