mirror of https://github.com/tasks/tasks
Merge branch 'consolidate_lists'
commit
417f5ac224
File diff suppressed because it is too large
Load Diff
@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2012 Todoroo Inc
|
|
||||||
*
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.gtasks
|
|
||||||
|
|
||||||
import com.todoroo.astrid.dao.TaskDao
|
|
||||||
import com.todoroo.astrid.data.Task
|
|
||||||
import dagger.hilt.android.testing.HiltAndroidTest
|
|
||||||
import dagger.hilt.android.testing.UninstallModules
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.junit.Assert.assertNotNull
|
|
||||||
import org.junit.Assert.assertNull
|
|
||||||
import org.junit.Test
|
|
||||||
import org.tasks.data.GoogleTask
|
|
||||||
import org.tasks.data.GoogleTaskDao
|
|
||||||
import org.tasks.injection.InjectingTestCase
|
|
||||||
import org.tasks.injection.ProductionModule
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@UninstallModules(ProductionModule::class)
|
|
||||||
@HiltAndroidTest
|
|
||||||
class GtasksMetadataServiceTest : InjectingTestCase() {
|
|
||||||
@Inject lateinit var taskDao: TaskDao
|
|
||||||
@Inject lateinit var googleTaskDao: GoogleTaskDao
|
|
||||||
|
|
||||||
private var task: Task? = null
|
|
||||||
private var metadata: GoogleTask? = null
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testMetadataFound() = runBlocking {
|
|
||||||
givenTask(taskWithMetadata(null))
|
|
||||||
whenSearchForMetadata()
|
|
||||||
thenExpectMetadataFound()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testMetadataDoesntExist() = runBlocking {
|
|
||||||
givenTask(taskWithoutMetadata())
|
|
||||||
whenSearchForMetadata()
|
|
||||||
thenExpectNoMetadataFound()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun thenExpectNoMetadataFound() {
|
|
||||||
assertNull(metadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun thenExpectMetadataFound() {
|
|
||||||
assertNotNull(metadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- helpers
|
|
||||||
private suspend fun whenSearchForMetadata() {
|
|
||||||
metadata = googleTaskDao.getByTaskId(task!!.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun taskWithMetadata(id: String?): Task {
|
|
||||||
val task = Task()
|
|
||||||
task.title = "cats"
|
|
||||||
taskDao.createNew(task)
|
|
||||||
val metadata = GoogleTask(task.id, "")
|
|
||||||
if (id != null) {
|
|
||||||
metadata.remoteId = id
|
|
||||||
}
|
|
||||||
metadata.task = task.id
|
|
||||||
googleTaskDao.insert(metadata)
|
|
||||||
return task
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun givenTask(taskToTest: Task) {
|
|
||||||
task = taskToTest
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun taskWithoutMetadata(): Task {
|
|
||||||
val task = Task()
|
|
||||||
task.title = "dogs"
|
|
||||||
taskDao.createNew(task)
|
|
||||||
return task
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,126 +1,15 @@
|
|||||||
package org.tasks.data
|
package org.tasks.data
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
@Deprecated("For backup use only")
|
||||||
import androidx.room.Entity
|
data class GoogleTask(
|
||||||
import androidx.room.ForeignKey
|
var remoteId: String? = "",
|
||||||
import androidx.room.Ignore
|
var listId: String? = "",
|
||||||
import androidx.room.Index
|
var remoteParent: String? = null,
|
||||||
import androidx.room.PrimaryKey
|
var remoteOrder: Long = 0,
|
||||||
import com.todoroo.andlib.data.Table
|
var lastSync: Long = 0,
|
||||||
import com.todoroo.astrid.data.Task
|
var deleted: Long = 0,
|
||||||
|
) {
|
||||||
@Entity(
|
|
||||||
tableName = "google_tasks",
|
|
||||||
indices = [
|
|
||||||
Index(name = "gt_list_parent", value = ["gt_list_id", "gt_parent"])
|
|
||||||
],
|
|
||||||
foreignKeys = [
|
|
||||||
ForeignKey(
|
|
||||||
entity = Task::class,
|
|
||||||
parentColumns = ["_id"],
|
|
||||||
childColumns = ["gt_task"],
|
|
||||||
onDelete = ForeignKey.CASCADE,
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
class GoogleTask {
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
@ColumnInfo(name = "gt_id")
|
|
||||||
@Transient
|
|
||||||
var id: Long = 0
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gt_task", index = true)
|
|
||||||
@Transient
|
|
||||||
var task: Long = 0
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gt_remote_id")
|
|
||||||
var remoteId: String? = ""
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gt_list_id")
|
|
||||||
var listId: String? = ""
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gt_parent")
|
|
||||||
@Transient
|
|
||||||
var parent: Long = 0
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gt_remote_parent")
|
|
||||||
var remoteParent: String? = null
|
|
||||||
set(value) {
|
|
||||||
field = if (value?.isNotBlank() == true) value else null
|
|
||||||
}
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gt_moved")
|
|
||||||
@Transient
|
|
||||||
var isMoved = false
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gt_order")
|
|
||||||
@Transient
|
|
||||||
var order: Long = 0
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gt_remote_order")
|
|
||||||
var remoteOrder: Long = 0
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gt_last_sync")
|
|
||||||
var lastSync: Long = 0
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gt_deleted")
|
|
||||||
var deleted: Long = 0
|
|
||||||
|
|
||||||
constructor()
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
constructor(task: Long, listId: String) {
|
|
||||||
this.task = task
|
|
||||||
this.listId = listId
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (other !is GoogleTask) return false
|
|
||||||
|
|
||||||
if (id != other.id) return false
|
|
||||||
if (task != other.task) return false
|
|
||||||
if (remoteId != other.remoteId) return false
|
|
||||||
if (listId != other.listId) return false
|
|
||||||
if (parent != other.parent) return false
|
|
||||||
if (remoteParent != other.remoteParent) return false
|
|
||||||
if (isMoved != other.isMoved) return false
|
|
||||||
if (order != other.order) return false
|
|
||||||
if (remoteOrder != other.remoteOrder) return false
|
|
||||||
if (lastSync != other.lastSync) return false
|
|
||||||
if (deleted != other.deleted) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = id.hashCode()
|
|
||||||
result = 31 * result + task.hashCode()
|
|
||||||
result = 31 * result + remoteId.hashCode()
|
|
||||||
result = 31 * result + listId.hashCode()
|
|
||||||
result = 31 * result + parent.hashCode()
|
|
||||||
result = 31 * result + (remoteParent?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + isMoved.hashCode()
|
|
||||||
result = 31 * result + order.hashCode()
|
|
||||||
result = 31 * result + remoteOrder.hashCode()
|
|
||||||
result = 31 * result + lastSync.hashCode()
|
|
||||||
result = 31 * result + deleted.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String =
|
|
||||||
"GoogleTask(id=$id, task=$task, remoteId='$remoteId', listId='$listId', parent=$parent, remoteParent=$remoteParent, isMoved=$isMoved, order=$order, remoteOrder=$remoteOrder, lastSync=$lastSync, deleted=$deleted)"
|
|
||||||
|
|
||||||
val isNew: Boolean
|
|
||||||
get() = id == 0L
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val KEY = "gtasks"
|
const val KEY = "gtasks"
|
||||||
@JvmField val TABLE = Table("google_tasks")
|
|
||||||
val ID = TABLE.column("gt_id")
|
|
||||||
@JvmField val PARENT = TABLE.column("gt_parent")
|
|
||||||
@JvmField val TASK = TABLE.column("gt_task")
|
|
||||||
@JvmField val DELETED = TABLE.column("gt_deleted")
|
|
||||||
@JvmField val LIST = TABLE.column("gt_list_id")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,98 +1,8 @@
|
|||||||
package org.tasks.data
|
package org.tasks.data
|
||||||
|
|
||||||
import android.os.Parcel
|
@Deprecated("Only used for backup migration")
|
||||||
import android.os.Parcelable
|
data class GoogleTaskAccount(
|
||||||
import androidx.core.os.ParcelCompat
|
var account: String? = null,
|
||||||
import androidx.room.ColumnInfo
|
var etag: String? = null,
|
||||||
import androidx.room.Entity
|
var isCollapsed: Boolean = false,
|
||||||
import androidx.room.Ignore
|
)
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import com.todoroo.andlib.data.Table
|
|
||||||
|
|
||||||
@Entity(tableName = "google_task_accounts")
|
|
||||||
class GoogleTaskAccount : Parcelable {
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
@ColumnInfo(name = "gta_id")
|
|
||||||
@Transient
|
|
||||||
var id: Long = 0
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gta_account")
|
|
||||||
var account: String? = null
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gta_error")
|
|
||||||
@Transient
|
|
||||||
var error: String? = ""
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gta_etag")
|
|
||||||
var etag: String? = null
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gta_collapsed")
|
|
||||||
var isCollapsed = false
|
|
||||||
|
|
||||||
constructor()
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
constructor(source: Parcel) {
|
|
||||||
id = source.readLong()
|
|
||||||
account = source.readString()
|
|
||||||
error = source.readString()
|
|
||||||
etag = source.readString()
|
|
||||||
isCollapsed = ParcelCompat.readBoolean(source)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
constructor(account: String?) {
|
|
||||||
this.account = account
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun describeContents() = 0
|
|
||||||
|
|
||||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
|
||||||
with(dest) {
|
|
||||||
writeLong(id)
|
|
||||||
writeString(account)
|
|
||||||
writeString(error)
|
|
||||||
writeString(etag)
|
|
||||||
ParcelCompat.writeBoolean(this, isCollapsed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (other !is GoogleTaskAccount) return false
|
|
||||||
|
|
||||||
if (id != other.id) return false
|
|
||||||
if (account != other.account) return false
|
|
||||||
if (error != other.error) return false
|
|
||||||
if (etag != other.etag) return false
|
|
||||||
if (isCollapsed != other.isCollapsed) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = id.hashCode()
|
|
||||||
result = 31 * result + (account?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + (error?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + (etag?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + isCollapsed.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String =
|
|
||||||
"GoogleTaskAccount(id=$id, account=$account, error=$error, etag=$etag, isCollapsed=$isCollapsed)"
|
|
||||||
|
|
||||||
val hasError: Boolean
|
|
||||||
get() = !error.isNullOrBlank()
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val TABLE = Table("google_task_accounts")
|
|
||||||
val ACCOUNT = TABLE.column("gta_account")
|
|
||||||
|
|
||||||
@JvmField val CREATOR: Parcelable.Creator<GoogleTaskAccount> = object : Parcelable.Creator<GoogleTaskAccount> {
|
|
||||||
override fun createFromParcel(source: Parcel): GoogleTaskAccount = GoogleTaskAccount(source)
|
|
||||||
|
|
||||||
override fun newArray(size: Int): Array<GoogleTaskAccount?> = arrayOfNulls(size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,126 +1,14 @@
|
|||||||
package org.tasks.data
|
package org.tasks.data
|
||||||
|
|
||||||
import android.os.Parcel
|
|
||||||
import android.os.Parcelable
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.Ignore
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import com.todoroo.andlib.data.Table
|
|
||||||
import com.todoroo.astrid.api.FilterListItem.NO_ORDER
|
import com.todoroo.astrid.api.FilterListItem.NO_ORDER
|
||||||
import org.tasks.themes.CustomIcons.LIST
|
|
||||||
|
|
||||||
@Entity(tableName = "google_task_lists")
|
@Deprecated("Only used for backup migration")
|
||||||
class GoogleTaskList : Parcelable {
|
data class GoogleTaskList(
|
||||||
@PrimaryKey(autoGenerate = true)
|
var account: String? = null,
|
||||||
@ColumnInfo(name = "gtl_id")
|
var remoteId: String? = null,
|
||||||
@Transient
|
var title: String? = null,
|
||||||
var id: Long = 0
|
var order: Int = NO_ORDER,
|
||||||
|
var lastSync: Long = 0,
|
||||||
@ColumnInfo(name = "gtl_account")
|
var color: Int? = null,
|
||||||
var account: String? = null
|
var icon: Int? = -1,
|
||||||
|
)
|
||||||
@ColumnInfo(name = "gtl_remote_id")
|
|
||||||
var remoteId: String? = null
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gtl_title")
|
|
||||||
var title: String? = null
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gtl_remote_order")
|
|
||||||
var order = NO_ORDER
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gtl_last_sync")
|
|
||||||
var lastSync: Long = 0
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gtl_color")
|
|
||||||
private var color: Int? = null
|
|
||||||
|
|
||||||
@ColumnInfo(name = "gtl_icon")
|
|
||||||
private var icon: Int? = -1
|
|
||||||
|
|
||||||
constructor()
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
constructor(parcel: Parcel) {
|
|
||||||
id = parcel.readLong()
|
|
||||||
account = parcel.readString()
|
|
||||||
remoteId = parcel.readString()
|
|
||||||
title = parcel.readString()
|
|
||||||
order = parcel.readInt()
|
|
||||||
lastSync = parcel.readLong()
|
|
||||||
color = parcel.readInt()
|
|
||||||
icon = parcel.readInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("RedundantNullableReturnType")
|
|
||||||
fun getColor(): Int? = color ?: 0
|
|
||||||
|
|
||||||
fun setColor(color: Int?) {
|
|
||||||
this.color = color
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("RedundantNullableReturnType")
|
|
||||||
fun getIcon(): Int? = icon ?: LIST
|
|
||||||
|
|
||||||
fun setIcon(icon: Int?) {
|
|
||||||
this.icon = icon
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun describeContents() = 0
|
|
||||||
|
|
||||||
override fun writeToParcel(parcel: Parcel, i: Int) {
|
|
||||||
with(parcel) {
|
|
||||||
writeLong(id)
|
|
||||||
writeString(account)
|
|
||||||
writeString(remoteId)
|
|
||||||
writeString(title)
|
|
||||||
writeInt(order)
|
|
||||||
writeLong(lastSync)
|
|
||||||
writeInt(getColor()!!)
|
|
||||||
writeInt(getIcon()!!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (other !is GoogleTaskList) return false
|
|
||||||
|
|
||||||
if (id != other.id) return false
|
|
||||||
if (account != other.account) return false
|
|
||||||
if (remoteId != other.remoteId) return false
|
|
||||||
if (title != other.title) return false
|
|
||||||
if (order != other.order) return false
|
|
||||||
if (lastSync != other.lastSync) return false
|
|
||||||
if (color != other.color) return false
|
|
||||||
if (icon != other.icon) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = id.hashCode()
|
|
||||||
result = 31 * result + (account?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + (remoteId?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + (title?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + order
|
|
||||||
result = 31 * result + lastSync.hashCode()
|
|
||||||
result = 31 * result + (color ?: 0)
|
|
||||||
result = 31 * result + (icon ?: 0)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String =
|
|
||||||
"GoogleTaskList(id=$id, account=$account, remoteId=$remoteId, title=$title, remoteOrder=$order, lastSync=$lastSync, color=$color, icon=$icon)"
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
@JvmField val TABLE = Table("google_task_lists")
|
|
||||||
val ACCOUNT = TABLE.column("gtl_account")
|
|
||||||
@JvmField val REMOTE_ID = TABLE.column("gtl_remote_id")
|
|
||||||
@JvmField val NAME = TABLE.column("gtl_title")
|
|
||||||
@JvmField val CREATOR: Parcelable.Creator<GoogleTaskList> = object : Parcelable.Creator<GoogleTaskList> {
|
|
||||||
override fun createFromParcel(parcel: Parcel): GoogleTaskList = GoogleTaskList(parcel)
|
|
||||||
|
|
||||||
override fun newArray(size: Int): Array<GoogleTaskList?> = arrayOfNulls(size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +1,38 @@
|
|||||||
package org.tasks.data
|
package org.tasks.data
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import com.todoroo.astrid.api.FilterListItem.NO_ORDER
|
import org.tasks.data.CaldavAccount.Companion.TYPE_GOOGLE_TASKS
|
||||||
import org.tasks.filters.GoogleTaskFilters
|
import org.tasks.filters.GoogleTaskFilters
|
||||||
import org.tasks.time.DateTimeUtils.currentTimeMillis
|
import org.tasks.time.DateTimeUtils.currentTimeMillis
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface GoogleTaskListDao {
|
interface GoogleTaskListDao {
|
||||||
@Query("SELECT * FROM google_task_accounts WHERE gta_id = :id")
|
@Query("SELECT * FROM caldav_accounts WHERE cda_account_type = $TYPE_GOOGLE_TASKS")
|
||||||
fun watchAccount(id: Long): LiveData<GoogleTaskAccount>
|
suspend fun getAccounts(): List<CaldavAccount>
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM google_task_accounts")
|
@Query("SELECT * FROM caldav_lists WHERE cdl_id = :id")
|
||||||
suspend fun accountCount(): Int
|
suspend fun getById(id: Long): CaldavCalendar?
|
||||||
|
|
||||||
@Query("SELECT * FROM google_task_accounts")
|
@Query("SELECT * FROM caldav_lists WHERE cdl_account = :account ORDER BY cdl_name ASC")
|
||||||
suspend fun getAccounts(): List<GoogleTaskAccount>
|
suspend fun getLists(account: String): List<CaldavCalendar>
|
||||||
|
|
||||||
@Query("SELECT * FROM google_task_accounts")
|
@Query("SELECT * FROM caldav_lists WHERE cdl_uuid = :remoteId LIMIT 1")
|
||||||
fun watchAccounts(): LiveData<List<GoogleTaskAccount>>
|
suspend fun getByRemoteId(remoteId: String): CaldavCalendar?
|
||||||
|
|
||||||
@Query("SELECT * FROM google_task_accounts WHERE gta_account = :account COLLATE NOCASE LIMIT 1")
|
@Query("SELECT * FROM caldav_lists WHERE cdl_uuid IN (:remoteIds)")
|
||||||
suspend fun getAccount(account: String): GoogleTaskAccount?
|
suspend fun getByRemoteId(remoteIds: List<String>): List<CaldavCalendar>
|
||||||
|
|
||||||
@Query("SELECT * FROM google_task_lists WHERE gtl_id = :id")
|
@Query("UPDATE caldav_lists SET cdl_last_sync = 0 WHERE cdl_account = :account")
|
||||||
suspend fun getById(id: Long): GoogleTaskList?
|
|
||||||
|
|
||||||
@Query("SELECT * FROM google_task_lists WHERE gtl_account = :account ORDER BY gtl_title ASC")
|
|
||||||
suspend fun getLists(account: String): List<GoogleTaskList>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM google_task_lists WHERE gtl_remote_id = :remoteId LIMIT 1")
|
|
||||||
suspend fun getByRemoteId(remoteId: String): GoogleTaskList?
|
|
||||||
|
|
||||||
@Query("SELECT * FROM google_task_lists WHERE gtl_remote_id IN (:remoteIds)")
|
|
||||||
suspend 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, '') = ''")
|
|
||||||
suspend fun findExistingList(remoteId: String): GoogleTaskList?
|
|
||||||
|
|
||||||
@Query("SELECT * FROM google_task_lists")
|
|
||||||
suspend fun getAllLists(): List<GoogleTaskList>
|
|
||||||
|
|
||||||
@Query("UPDATE google_task_lists SET gtl_last_sync = 0 WHERE gtl_account = :account")
|
|
||||||
suspend fun resetLastSync(account: String)
|
suspend fun resetLastSync(account: String)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertOrReplace(googleTaskList: GoogleTaskList): Long
|
suspend fun insertOrReplace(googleTaskList: CaldavCalendar): Long
|
||||||
|
|
||||||
@Insert
|
@Query("SELECT caldav_lists.*, COUNT(tasks._id) AS count"
|
||||||
suspend fun insert(googleTaskList: GoogleTaskList): Long
|
+ " FROM caldav_lists "
|
||||||
|
+ " LEFT JOIN caldav_tasks ON caldav_tasks.cd_calendar = caldav_lists.cdl_uuid"
|
||||||
@Insert
|
+ " 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"
|
||||||
suspend fun insert(googleTaskAccount: GoogleTaskAccount)
|
+ " WHERE caldav_lists.cdl_account = :account"
|
||||||
|
+ " GROUP BY caldav_lists.cdl_uuid")
|
||||||
@Update
|
|
||||||
suspend fun update(account: GoogleTaskAccount)
|
|
||||||
|
|
||||||
@Update
|
|
||||||
suspend 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")
|
|
||||||
suspend fun getGoogleTaskFilters(account: String, now: Long = currentTimeMillis()): List<GoogleTaskFilters>
|
suspend fun getGoogleTaskFilters(account: String, now: Long = currentTimeMillis()): List<GoogleTaskFilters>
|
||||||
|
|
||||||
@Query("UPDATE google_task_lists SET gtl_remote_order = $NO_ORDER")
|
|
||||||
suspend fun resetOrders()
|
|
||||||
|
|
||||||
@Query("UPDATE google_task_lists SET gtl_remote_order = :order WHERE gtl_id = :id")
|
|
||||||
suspend fun setOrder(id: Long, order: Int)
|
|
||||||
}
|
}
|
@ -1,31 +0,0 @@
|
|||||||
package org.tasks.data
|
|
||||||
|
|
||||||
class SubsetCaldav {
|
|
||||||
var cd_id: Long = 0
|
|
||||||
var cd_calendar: String? = null
|
|
||||||
var cd_remote_parent: String? = null
|
|
||||||
var cd_order: Long? = null
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (other !is SubsetCaldav) return false
|
|
||||||
|
|
||||||
if (cd_id != other.cd_id) return false
|
|
||||||
if (cd_calendar != other.cd_calendar) return false
|
|
||||||
if (cd_remote_parent != other.cd_remote_parent) return false
|
|
||||||
if (cd_order != other.cd_order) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = cd_id.hashCode()
|
|
||||||
result = 31 * result + (cd_calendar?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + (cd_remote_parent?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + cd_order.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String =
|
|
||||||
"SubsetCaldav(cd_id=$cd_id, cd_calendar=$cd_calendar, cd_remote_parent=$cd_remote_parent, cd_order=$cd_order)"
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
package org.tasks.data;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class SubsetGoogleTask {
|
|
||||||
|
|
||||||
public long gt_id;
|
|
||||||
public long gt_parent;
|
|
||||||
public String gt_list_id;
|
|
||||||
public long gt_order;
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return gt_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getListId() {
|
|
||||||
return gt_list_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getParent() {
|
|
||||||
return gt_parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParent(long parent) {
|
|
||||||
gt_parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getOrder() {
|
|
||||||
return gt_order;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrder(long order) {
|
|
||||||
gt_order = order;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!(o instanceof SubsetGoogleTask)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
SubsetGoogleTask that = (SubsetGoogleTask) o;
|
|
||||||
return gt_id == that.gt_id
|
|
||||||
&& gt_parent == that.gt_parent
|
|
||||||
&& gt_order == that.gt_order
|
|
||||||
&& Objects.equals(gt_list_id, that.gt_list_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(gt_id, gt_parent, gt_list_id, gt_order);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SubsetGoogleTask{"
|
|
||||||
+ "gt_id="
|
|
||||||
+ gt_id
|
|
||||||
+ ", gt_parent="
|
|
||||||
+ gt_parent
|
|
||||||
+ ", gt_list_id='"
|
|
||||||
+ gt_list_id
|
|
||||||
+ '\''
|
|
||||||
+ ", gt_order="
|
|
||||||
+ gt_order
|
|
||||||
+ '}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,29 @@
|
|||||||
|
package org.tasks.makers
|
||||||
|
|
||||||
|
import com.natpryce.makeiteasy.Instantiator
|
||||||
|
import com.natpryce.makeiteasy.Property
|
||||||
|
import com.natpryce.makeiteasy.Property.newProperty
|
||||||
|
import com.natpryce.makeiteasy.PropertyValue
|
||||||
|
import org.tasks.data.CaldavAccount
|
||||||
|
import org.tasks.data.CaldavAccount.Companion.TYPE_CALDAV
|
||||||
|
import org.tasks.makers.Maker.make
|
||||||
|
|
||||||
|
object CaldavAccountMaker {
|
||||||
|
val ID: Property<CaldavAccount, Long> = newProperty()
|
||||||
|
val NAME: Property<CaldavAccount, String> = newProperty()
|
||||||
|
val UUID: Property<CaldavAccount, String> = newProperty()
|
||||||
|
val ACCOUNT_TYPE: Property<CaldavAccount, Int> = newProperty()
|
||||||
|
|
||||||
|
private val instantiator = Instantiator { lookup ->
|
||||||
|
CaldavAccount().apply {
|
||||||
|
id = lookup.valueOf(ID, 0L)
|
||||||
|
name = lookup.valueOf(NAME, null as String?)
|
||||||
|
uuid = lookup.valueOf(UUID, "account")
|
||||||
|
accountType = lookup.valueOf(ACCOUNT_TYPE, TYPE_CALDAV)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun newCaldavAccount(vararg properties: PropertyValue<in CaldavAccount?, *>): CaldavAccount {
|
||||||
|
return make(instantiator, *properties)
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
package org.tasks.makers
|
|
||||||
|
|
||||||
import com.natpryce.makeiteasy.Instantiator
|
|
||||||
import com.natpryce.makeiteasy.Property
|
|
||||||
import com.natpryce.makeiteasy.PropertyLookup
|
|
||||||
import com.natpryce.makeiteasy.PropertyValue
|
|
||||||
import org.tasks.data.GoogleTaskList
|
|
||||||
|
|
||||||
object GoogleTaskListMaker {
|
|
||||||
val REMOTE_ID: Property<GoogleTaskList, String> = Property.newProperty()
|
|
||||||
val ACCOUNT: Property<GoogleTaskList, String?> = Property.newProperty()
|
|
||||||
|
|
||||||
private val instantiator = Instantiator { lookup: PropertyLookup<GoogleTaskList> ->
|
|
||||||
val list = GoogleTaskList()
|
|
||||||
list.remoteId = lookup.valueOf(REMOTE_ID, "1234")
|
|
||||||
list.account = lookup.valueOf(ACCOUNT, null as String?)
|
|
||||||
list.setColor(0)
|
|
||||||
list
|
|
||||||
}
|
|
||||||
|
|
||||||
fun newGoogleTaskList(vararg properties: PropertyValue<in GoogleTaskList?, *>): GoogleTaskList {
|
|
||||||
return Maker.make(instantiator, *properties)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package org.tasks.makers
|
|
||||||
|
|
||||||
import com.natpryce.makeiteasy.Instantiator
|
|
||||||
import com.natpryce.makeiteasy.Property
|
|
||||||
import com.natpryce.makeiteasy.Property.newProperty
|
|
||||||
import com.natpryce.makeiteasy.PropertyValue
|
|
||||||
import com.todoroo.astrid.helper.UUIDHelper
|
|
||||||
import org.tasks.data.GoogleTask
|
|
||||||
import org.tasks.makers.Maker.make
|
|
||||||
|
|
||||||
object GoogleTaskMaker {
|
|
||||||
val LIST: Property<GoogleTask, String> = newProperty()
|
|
||||||
val ORDER: Property<GoogleTask, Long> = newProperty()
|
|
||||||
val REMOTE_ID: Property<GoogleTask, String> = newProperty()
|
|
||||||
val TASK: Property<GoogleTask, Long> = newProperty()
|
|
||||||
val PARENT: Property<GoogleTask, Long> = newProperty()
|
|
||||||
val REMOTE_PARENT: Property<GoogleTask, String?> = newProperty()
|
|
||||||
|
|
||||||
private val instantiator = Instantiator<GoogleTask> {
|
|
||||||
val task = GoogleTask()
|
|
||||||
task.listId = it.valueOf(LIST, "1")
|
|
||||||
task.order = it.valueOf(ORDER, 0)
|
|
||||||
task.remoteId = it.valueOf(REMOTE_ID, UUIDHelper.newUUID())
|
|
||||||
task.task = it.valueOf(TASK, 1)
|
|
||||||
task.parent = it.valueOf(PARENT, 0L)
|
|
||||||
task.remoteParent = it.valueOf(REMOTE_PARENT, null as String?)
|
|
||||||
task
|
|
||||||
}
|
|
||||||
|
|
||||||
fun newGoogleTask(vararg properties: PropertyValue<in GoogleTask?, *>): GoogleTask {
|
|
||||||
return make(instantiator, *properties)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package org.tasks.makers
|
|
||||||
|
|
||||||
import com.natpryce.makeiteasy.Instantiator
|
|
||||||
import com.natpryce.makeiteasy.Property
|
|
||||||
import com.natpryce.makeiteasy.Property.newProperty
|
|
||||||
import com.natpryce.makeiteasy.PropertyLookup
|
|
||||||
import com.natpryce.makeiteasy.PropertyValue
|
|
||||||
import com.todoroo.astrid.api.FilterListItem.NO_ORDER
|
|
||||||
import org.tasks.data.GoogleTaskList
|
|
||||||
import org.tasks.makers.Maker.make
|
|
||||||
|
|
||||||
object GtaskListMaker {
|
|
||||||
val ID: Property<GoogleTaskList, Long> = newProperty()
|
|
||||||
val ACCOUNT: Property<GoogleTaskList, String> = newProperty()
|
|
||||||
val REMOTE_ID: Property<GoogleTaskList, String> = newProperty()
|
|
||||||
val LAST_SYNC: Property<GoogleTaskList, Long> = newProperty()
|
|
||||||
val NAME: Property<GoogleTaskList, String> = newProperty()
|
|
||||||
private val ORDER: Property<GoogleTaskList, Int> = newProperty()
|
|
||||||
private val COLOR: Property<GoogleTaskList, Int> = newProperty()
|
|
||||||
|
|
||||||
private val instantiator = Instantiator { lookup: PropertyLookup<GoogleTaskList> ->
|
|
||||||
val list = GoogleTaskList()
|
|
||||||
list.id = lookup.valueOf(ID, 0L)
|
|
||||||
list.account = lookup.valueOf(ACCOUNT, "account")
|
|
||||||
list.remoteId = lookup.valueOf(REMOTE_ID, "1")
|
|
||||||
list.title = lookup.valueOf(NAME, "Default")
|
|
||||||
list.order = lookup.valueOf(ORDER, NO_ORDER)
|
|
||||||
list.lastSync = lookup.valueOf(LAST_SYNC, 0L)
|
|
||||||
list.setColor(lookup.valueOf(COLOR, 0))
|
|
||||||
list
|
|
||||||
}
|
|
||||||
|
|
||||||
fun newGtaskList(vararg properties: PropertyValue<in GoogleTaskList?, *>): GoogleTaskList {
|
|
||||||
return make(instantiator, *properties)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue