Remove unused blocking dao methods

pull/1052/head
Alex Baker 4 years ago
parent 479c26c416
commit 783f1bde69

@ -1,14 +1,15 @@
package com.todoroo.astrid.alarms
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.dao.TaskDao
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.tasks.data.Alarm
import org.tasks.data.AlarmDaoBlocking
import org.tasks.data.AlarmDao
import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule
import org.tasks.jobs.AlarmEntry
@ -21,13 +22,13 @@ import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class AlarmJobServiceTest : InjectingTestCase() {
@Inject lateinit var alarmDao: AlarmDaoBlocking
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var alarmDao: AlarmDao
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var jobs: NotificationQueue
@Inject lateinit var alarmService: AlarmService
@Test
fun scheduleAlarm() {
fun scheduleAlarm() = runBlocking {
val task = newTask()
taskDao.createNew(task)
val alarmTime = DateTime(2017, 9, 24, 19, 57)
@ -39,7 +40,7 @@ class AlarmJobServiceTest : InjectingTestCase() {
}
@Test
fun ignoreStaleAlarm() {
fun ignoreStaleAlarm() = runBlocking {
val alarmTime = DateTime(2017, 9, 24, 19, 57)
val task = newTask(with(REMINDER_LAST, alarmTime.endOfMinute()))
taskDao.createNew(task)

@ -25,12 +25,12 @@ import javax.inject.Inject
@HiltAndroidTest
class TaskDaoTests : InjectingTestCase() {
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var taskDeleter: TaskDeleter
/** Test basic task creation, fetch, and save */
@Test
fun testTaskCreation() {
fun testTaskCreation() = runBlocking {
assertEquals(0, taskDao.getAll().size)
// create task "happy"
@ -40,7 +40,7 @@ class TaskDaoTests : InjectingTestCase() {
assertEquals(1, taskDao.getAll().size)
val happyId = task.id
assertNotSame(Task.NO_ID, happyId)
task = taskDao.fetchBlocking(happyId)!!
task = taskDao.fetch(happyId)!!
assertEquals("happy", task.title)
// create task "sad"
@ -57,15 +57,15 @@ class TaskDaoTests : InjectingTestCase() {
assertEquals(2, taskDao.getAll().size)
// check state
task = taskDao.fetchBlocking(happyId)!!
task = taskDao.fetch(happyId)!!
assertEquals("happy", task.title)
task = taskDao.fetchBlocking(sadId)!!
task = taskDao.fetch(sadId)!!
assertEquals("melancholy", task.title)
}
/** Test various task fetch conditions */
@Test
fun testTaskConditions() {
fun testTaskConditions() = runBlocking {
// create normal task
var task = Task()
task.title = "normal"
@ -123,7 +123,7 @@ class TaskDaoTests : InjectingTestCase() {
/** Test save without prior create doesn't work */
@Test
fun testSaveWithoutCreate() {
fun testSaveWithoutCreate() = runBlocking {
// try to save task "happy"
val task = Task()
task.title = "happy"
@ -136,7 +136,7 @@ class TaskDaoTests : InjectingTestCase() {
@Test
fun testInvalidIndex() = runBlocking {
assertEquals(0, taskDao.getAll().size)
assertNull(taskDao.fetchBlocking(1))
assertNull(taskDao.fetch(1))
taskDeleter.delete(listOf(1L))
// make sure db still works
@ -144,14 +144,14 @@ class TaskDaoTests : InjectingTestCase() {
}
@Test
fun findChildrenInList() {
fun findChildrenInList() = runBlocking {
taskDao.createNew(newTask(with(ID, 1L)))
taskDao.createNew(newTask(with(ID, 2L), with(PARENT, 1L)))
assertEquals(listOf(2L), taskDao.getChildren(listOf(1L, 2L)))
}
@Test
fun findRecursiveChildrenInList() {
fun findRecursiveChildrenInList() = runBlocking {
taskDao.createNew(newTask(with(ID, 1L)))
taskDao.createNew(newTask(with(ID, 2L), with(PARENT, 1L)))
taskDao.createNew(newTask(with(ID, 3L), with(PARENT, 2L)))
@ -159,7 +159,7 @@ class TaskDaoTests : InjectingTestCase() {
}
@Test
fun findRecursiveChildrenInListAfterSkippingParent() {
fun findRecursiveChildrenInListAfterSkippingParent() = runBlocking {
taskDao.createNew(newTask(with(ID, 1L)))
taskDao.createNew(newTask(with(ID, 2L), with(PARENT, 1L)))
taskDao.createNew(newTask(with(ID, 3L), with(PARENT, 2L)))

@ -5,15 +5,16 @@
*/
package com.todoroo.astrid.gtasks
import com.todoroo.astrid.dao.TaskDaoBlocking
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.GoogleTaskDaoBlocking
import org.tasks.data.GoogleTaskDao
import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule
import javax.inject.Inject
@ -21,21 +22,21 @@ import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class GtasksMetadataServiceTest : InjectingTestCase() {
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var googleTaskDao: GoogleTaskDaoBlocking
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var googleTaskDao: GoogleTaskDao
private var task: Task? = null
private var metadata: GoogleTask? = null
@Test
fun testMetadataFound() {
fun testMetadataFound() = runBlocking {
givenTask(taskWithMetadata(null))
whenSearchForMetadata()
thenExpectMetadataFound()
}
@Test
fun testMetadataDoesntExist() {
fun testMetadataDoesntExist() = runBlocking {
givenTask(taskWithoutMetadata())
whenSearchForMetadata()
thenExpectNoMetadataFound()
@ -50,11 +51,11 @@ class GtasksMetadataServiceTest : InjectingTestCase() {
}
// --- helpers
private fun whenSearchForMetadata() {
private suspend fun whenSearchForMetadata() {
metadata = googleTaskDao.getByTaskId(task!!.id)
}
private fun taskWithMetadata(id: String?): Task {
private suspend fun taskWithMetadata(id: String?): Task {
val task = Task()
task.title = "cats"
taskDao.createNew(task)
@ -71,7 +72,7 @@ class GtasksMetadataServiceTest : InjectingTestCase() {
task = taskToTest
}
private fun taskWithoutMetadata(): Task {
private suspend fun taskWithoutMetadata(): Task {
val task = Task()
task.title = "dogs"
taskDao.createNew(task)

@ -3,13 +3,14 @@ package org.tasks.data
import com.natpryce.makeiteasy.MakeItEasy.with
import com.natpryce.makeiteasy.PropertyValue
import com.todoroo.andlib.utility.DateUtilities.now
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.dao.TaskDao
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.tasks.Freeze.Companion.freezeAt
import org.tasks.SuspendFreeze.Companion.freezeAt
import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule
import org.tasks.makers.TaskContainerMaker
@ -20,13 +21,13 @@ import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class CaldavDaoShiftTests : InjectingTestCase() {
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var caldavDao: CaldavDaoBlocking
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var caldavDao: CaldavDao
private val tasks = ArrayList<TaskContainer>()
@Test
fun basicShiftDown() {
fun basicShiftDown() = runBlocking {
val created = DateTime(2020, 5, 17, 9, 53, 17)
addTask(with(CREATED, created))
addTask(with(CREATED, created.plusSeconds(1)))
@ -40,7 +41,7 @@ class CaldavDaoShiftTests : InjectingTestCase() {
}
@Test
fun shiftDownOnlyWhenNecessary() {
fun shiftDownOnlyWhenNecessary() = runBlocking {
val created = DateTime(2020, 5, 17, 9, 53, 17)
addTask(with(CREATED, created))
addTask(with(CREATED, created.plusSeconds(1)))
@ -56,7 +57,7 @@ class CaldavDaoShiftTests : InjectingTestCase() {
}
@Test
fun ignoreUnnecessaryShiftDown() {
fun ignoreUnnecessaryShiftDown() = runBlocking {
val created = DateTime(2020, 5, 17, 9, 53, 17)
addTask(with(CREATED, created))
addTask(with(CREATED, created.plusSeconds(2)))
@ -68,7 +69,7 @@ class CaldavDaoShiftTests : InjectingTestCase() {
}
@Test
fun ignoreOtherCalendarWhenShiftingDown() {
fun ignoreOtherCalendarWhenShiftingDown() = runBlocking {
val created = DateTime(2020, 5, 17, 9, 53, 17)
addTask("calendar1", with(CREATED, created))
addTask("calendar2", with(CREATED, created))
@ -80,7 +81,7 @@ class CaldavDaoShiftTests : InjectingTestCase() {
}
@Test
fun partialShiftDown() {
fun partialShiftDown() = runBlocking {
val created = DateTime(2020, 5, 17, 9, 53, 17)
addTask(with(CREATED, created))
addTask(with(CREATED, created.plusSeconds(1)))
@ -98,7 +99,7 @@ class CaldavDaoShiftTests : InjectingTestCase() {
}
@Test
fun ignoreMovedTasksWhenShiftingDown() {
fun ignoreMovedTasksWhenShiftingDown() = runBlocking {
val created = DateTime(2020, 5, 17, 9, 53, 17)
addTask(with(CREATED, created))
caldavDao.update(caldavDao.getTask(tasks[0].id).apply { this?.deleted = now() }!!)
@ -109,10 +110,10 @@ class CaldavDaoShiftTests : InjectingTestCase() {
}
@Test
fun ignoreDeletedTasksWhenShiftingDown() {
fun ignoreDeletedTasksWhenShiftingDown() = runBlocking {
val created = DateTime(2020, 5, 17, 9, 53, 17)
addTask(with(CREATED, created))
taskDao.update(taskDao.fetchBlocking(tasks[0].id).apply { this?.deletionDate = now() }!!)
taskDao.update(taskDao.fetch(tasks[0].id).apply { this?.deletionDate = now() }!!)
caldavDao.shiftDown("calendar", 0, created.toAppleEpoch())
@ -120,7 +121,7 @@ class CaldavDaoShiftTests : InjectingTestCase() {
}
@Test
fun touchShiftedTasks() {
fun touchShiftedTasks() = runBlocking {
val created = DateTime(2020, 5, 17, 9, 53, 17)
addTask(with(CREATED, created))
addTask(with(CREATED, created.plusSeconds(1)))
@ -129,11 +130,11 @@ class CaldavDaoShiftTests : InjectingTestCase() {
caldavDao.shiftDown("calendar", 0, created.toAppleEpoch())
}
assertEquals(created.plusMinutes(1).millis, taskDao.fetchBlocking(tasks[0].id)!!.modificationDate)
assertEquals(created.plusMinutes(1).millis, taskDao.fetchBlocking(tasks[1].id)!!.modificationDate)
assertEquals(created.plusMinutes(1).millis, taskDao.fetch(tasks[0].id)!!.modificationDate)
assertEquals(created.plusMinutes(1).millis, taskDao.fetch(tasks[1].id)!!.modificationDate)
}
private fun checkOrder(dateTime: DateTime?, task: TaskContainer) {
private suspend fun checkOrder(dateTime: DateTime?, task: TaskContainer) {
if (dateTime == null) {
assertNull(caldavDao.getTask(task.id)!!.order)
} else {
@ -141,9 +142,9 @@ class CaldavDaoShiftTests : InjectingTestCase() {
}
}
private fun addTask(vararg properties: PropertyValue<in TaskContainer?, *>) = addTask("calendar", *properties)
private suspend fun addTask(vararg properties: PropertyValue<in TaskContainer?, *>) = addTask("calendar", *properties)
private fun addTask(calendar: String, vararg properties: PropertyValue<in TaskContainer?, *>) {
private suspend fun addTask(calendar: String, vararg properties: PropertyValue<in TaskContainer?, *>) {
val t = TaskContainerMaker.newTaskContainer(*properties)
tasks.add(t)
val task = t.task

@ -1,10 +1,11 @@
package org.tasks.data
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.helper.UUIDHelper
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.*
import org.junit.Test
import org.tasks.injection.InjectingTestCase
@ -22,13 +23,13 @@ import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class CaldavDaoTests : InjectingTestCase() {
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var tagDao: TagDaoBlocking
@Inject lateinit var tagDataDao: TagDataDaoBlocking
@Inject lateinit var caldavDao: CaldavDaoBlocking
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var tagDao: TagDao
@Inject lateinit var tagDataDao: TagDataDao
@Inject lateinit var caldavDao: CaldavDao
@Test
fun insertNewTaskAtTopOfEmptyList() {
fun insertNewTaskAtTopOfEmptyList() = runBlocking {
val task = newTask()
taskDao.createNew(task)
val caldavTask = CaldavTask(task.id, "calendar")
@ -38,7 +39,7 @@ class CaldavDaoTests : InjectingTestCase() {
}
@Test
fun insertNewTaskAboveExistingTask() {
fun insertNewTaskAboveExistingTask() = runBlocking {
val created = DateTime(2020, 5, 21, 15, 29, 16, 452)
val first = newTask(with(CREATION_TIME, created))
val second = newTask(with(CREATION_TIME, created.plusSeconds(1)))
@ -53,7 +54,7 @@ class CaldavDaoTests : InjectingTestCase() {
}
@Test
fun insertNewTaskBelowExistingTask() {
fun insertNewTaskBelowExistingTask() = runBlocking {
val created = DateTime(2020, 5, 21, 15, 29, 16, 452)
val first = newTask(with(CREATION_TIME, created))
val second = newTask(with(CREATION_TIME, created.plusSeconds(1)))
@ -68,7 +69,7 @@ class CaldavDaoTests : InjectingTestCase() {
}
@Test
fun insertNewTaskBelowExistingTaskWithSameCreationDate() {
fun insertNewTaskBelowExistingTaskWithSameCreationDate() = runBlocking {
val created = DateTime(2020, 5, 21, 15, 29, 16, 452)
val first = newTask(with(CREATION_TIME, created))
val second = newTask(with(CREATION_TIME, created))
@ -83,7 +84,7 @@ class CaldavDaoTests : InjectingTestCase() {
}
@Test
fun insertNewTaskAtBottomOfEmptyList() {
fun insertNewTaskAtBottomOfEmptyList() = runBlocking {
val task = newTask()
taskDao.createNew(task)
val caldavTask = CaldavTask(task.id, "calendar")
@ -93,7 +94,7 @@ class CaldavDaoTests : InjectingTestCase() {
}
@Test
fun getCaldavTasksWithTags() {
fun getCaldavTasksWithTags() = runBlocking {
val task = newTask(with(ID, 1L))
taskDao.createNew(task)
val one = newTagData()
@ -107,7 +108,7 @@ class CaldavDaoTests : InjectingTestCase() {
}
@Test
fun ignoreNonCaldavTaskWithTags() {
fun ignoreNonCaldavTaskWithTags() = runBlocking {
val task = newTask(with(ID, 1L))
taskDao.createNew(task)
val tag = newTagData()
@ -117,7 +118,7 @@ class CaldavDaoTests : InjectingTestCase() {
}
@Test
fun ignoreCaldavTaskWithoutTags() {
fun ignoreCaldavTaskWithoutTags() = runBlocking {
val task = newTask(with(ID, 1L))
taskDao.createNew(task)
tagDataDao.createNew(newTagData())
@ -126,16 +127,16 @@ class CaldavDaoTests : InjectingTestCase() {
}
@Test
fun noResultsForEmptyAccounts() {
fun noResultsForEmptyAccounts() = runBlocking {
val caldavAccount = CaldavAccount()
caldavAccount.uuid = UUIDHelper.newUUID()
caldavDao.insert(caldavAccount)
assertTrue(caldavDao.getCaldavFilters(caldavAccount.uuid!!).isEmpty())
}
private fun checkOrder(dateTime: DateTime, task: Long) = checkOrder(dateTime.toAppleEpoch(), task)
private suspend fun checkOrder(dateTime: DateTime, task: Long) = checkOrder(dateTime.toAppleEpoch(), task)
private fun checkOrder(order: Long?, task: Long) {
private suspend fun checkOrder(order: Long?, task: Long) {
val sortOrder = caldavDao.getTask(task)!!.order
if (order == null) {
assertNull(sortOrder)

@ -1,10 +1,11 @@
package org.tasks.data
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.helper.UUIDHelper
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.*
import org.junit.Test
import org.tasks.data.CaldavDao.Companion.LOCAL
@ -21,42 +22,42 @@ import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class DeletionDaoTests : InjectingTestCase() {
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var deletionDao: DeletionDaoBlocking
@Inject lateinit var caldavDao: CaldavDaoBlocking
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var deletionDao: DeletionDao
@Inject lateinit var caldavDao: CaldavDao
@Test
fun deleting1000DoesntCrash() {
fun deleting1000DoesntCrash() = runBlocking {
deletionDao.delete((1L..1000L).toList())
}
@Test
fun marking998ForDeletionDoesntCrash() {
fun marking998ForDeletionDoesntCrash() = runBlocking {
deletionDao.markDeleted(1L..1000L)
}
@Test
fun markDeletedUpdatesModificationTime() {
fun markDeletedUpdatesModificationTime() = runBlocking {
var task = newTask(with(CREATION_TIME, DateTime().minusMinutes(1)))
taskDao.createNew(task)
deletionDao.markDeleted(listOf(task.id))
task = taskDao.fetchBlocking(task.id)!!
task = taskDao.fetch(task.id)!!
assertTrue(task.modificationDate > task.creationDate)
assertTrue(task.modificationDate < DateTimeUtils.currentTimeMillis())
}
@Test
fun markDeletedUpdatesDeletionTime() {
fun markDeletedUpdatesDeletionTime() = runBlocking {
var task = newTask(with(CREATION_TIME, DateTime().minusMinutes(1)))
taskDao.createNew(task)
deletionDao.markDeleted(listOf(task.id))
task = taskDao.fetchBlocking(task.id)!!
task = taskDao.fetch(task.id)!!
assertTrue(task.deletionDate > task.creationDate)
assertTrue(task.deletionDate < DateTimeUtils.currentTimeMillis())
}
@Test
fun purgeDeletedLocalTask() {
fun purgeDeletedLocalTask() = runBlocking {
val task = newTask(with(DELETION_TIME, newDateTime()))
taskDao.createNew(task)
caldavDao.insert(CaldavCalendar("", "1234").apply { account = LOCAL })
@ -64,11 +65,11 @@ class DeletionDaoTests : InjectingTestCase() {
deletionDao.purgeDeleted()
assertNull(taskDao.fetchBlocking(task.id))
assertNull(taskDao.fetch(task.id))
}
@Test
fun dontPurgeActiveTasks() {
fun dontPurgeActiveTasks() = runBlocking {
val task = newTask()
taskDao.createNew(task)
caldavDao.insert(CaldavCalendar("", "1234").apply { account = LOCAL })
@ -76,11 +77,11 @@ class DeletionDaoTests : InjectingTestCase() {
deletionDao.purgeDeleted()
assertNotNull(taskDao.fetchBlocking(task.id))
assertNotNull(taskDao.fetch(task.id))
}
@Test
fun dontPurgeDeletedCaldavTask() {
fun dontPurgeDeletedCaldavTask() = runBlocking {
val task = newTask(with(DELETION_TIME, newDateTime()))
taskDao.createNew(task)
caldavDao.insert(CaldavCalendar("", "1234").apply { account = UUIDHelper.newUUID() })
@ -88,6 +89,6 @@ class DeletionDaoTests : InjectingTestCase() {
deletionDao.purgeDeleted()
assertNotNull(taskDao.fetchBlocking(task.id))
assertNotNull(taskDao.fetch(task.id))
}
}

@ -3,6 +3,7 @@ package org.tasks.data
import com.natpryce.makeiteasy.MakeItEasy.with
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.*
import org.junit.Test
import org.tasks.injection.InjectingTestCase
@ -15,10 +16,10 @@ import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class GoogleTaskListDaoTest : InjectingTestCase() {
@Inject lateinit var googleTaskListDao: GoogleTaskListDaoBlocking
@Inject lateinit var googleTaskListDao: GoogleTaskListDao
@Test
fun noResultsForEmptyAccount() {
fun noResultsForEmptyAccount() = runBlocking {
val account = GoogleTaskAccount()
account.account = "user@gmail.com"
googleTaskListDao.insert(account)
@ -27,7 +28,7 @@ class GoogleTaskListDaoTest : InjectingTestCase() {
}
@Test
fun findListWithNullAccount() {
fun findListWithNullAccount() = runBlocking {
val list = newGoogleTaskList(with(REMOTE_ID, "1234"), with(ACCOUNT, null as String?))
list.id = googleTaskListDao.insert(list)
@ -35,7 +36,7 @@ class GoogleTaskListDaoTest : InjectingTestCase() {
}
@Test
fun findListWithEmptyAccount() {
fun findListWithEmptyAccount() = runBlocking {
val list = newGoogleTaskList(with(REMOTE_ID, "1234"), with(ACCOUNT, ""))
list.id = googleTaskListDao.insert(list)
@ -43,7 +44,7 @@ class GoogleTaskListDaoTest : InjectingTestCase() {
}
@Test
fun ignoreListWithAccount() {
fun ignoreListWithAccount() = runBlocking {
val list = newGoogleTaskList(with(REMOTE_ID, "1234"), with(ACCOUNT, "user@gmail.com"))
googleTaskListDao.insert(list)

@ -2,13 +2,14 @@ package org.tasks.data
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.andlib.utility.DateUtilities.now
import com.todoroo.astrid.dao.TaskDaoBlocking
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.*
import org.junit.Test
import org.tasks.Freeze
import org.tasks.SuspendFreeze.Companion.freezeAt
import org.tasks.caldav.GeoUtils.toLikeString
import org.tasks.date.DateTimeUtils.newDateTime
import org.tasks.injection.InjectingTestCase
@ -33,11 +34,11 @@ import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class LocationDaoTest : InjectingTestCase() {
@Inject lateinit var locationDao: LocationDaoBlocking
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var locationDao: LocationDao
@Inject lateinit var taskDao: TaskDao
@Test
fun getExistingPlace() {
fun getExistingPlace() = runBlocking {
locationDao.insert(newPlace(with(LATITUDE, 48.067222), with(LONGITUDE, 12.863611)))
val place = locationDao.findPlace(48.067222.toLikeString(), 12.863611.toLikeString())
assertEquals(48.067222, place?.latitude)
@ -45,7 +46,7 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun getPlaceWithLessPrecision() {
fun getPlaceWithLessPrecision() = runBlocking {
locationDao.insert(newPlace(with(LATITUDE, 50.7547), with(LONGITUDE, -2.2279)))
val place = locationDao.findPlace(50.754712.toLikeString(), (-2.227945).toLikeString())
assertEquals(50.7547, place?.latitude)
@ -53,7 +54,7 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun getPlaceWithMorePrecision() {
fun getPlaceWithMorePrecision() = runBlocking {
locationDao.insert(newPlace(with(LATITUDE, 36.246944), with(LONGITUDE, -116.816944)))
locationDao.getPlaces().forEach { println(it) }
val place = locationDao.findPlace(36.2469.toLikeString(), (-116.8169).toLikeString())
@ -62,7 +63,7 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun noActiveGeofences() {
fun noActiveGeofences() = runBlocking {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(with(ID, 1)))
@ -72,7 +73,7 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun activeArrivalGeofence() {
fun activeArrivalGeofence() = runBlocking {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(with(ID, 1)))
@ -85,7 +86,7 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun activeDepartureGeofence() {
fun activeDepartureGeofence() = runBlocking {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(with(ID, 1)))
@ -98,7 +99,7 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun geofenceInactiveForCompletedTask() {
fun geofenceInactiveForCompletedTask() = runBlocking {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(with(ID, 1), with(COMPLETION_TIME, newDateTime())))
@ -108,7 +109,7 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun geofenceInactiveForDeletedTask() {
fun geofenceInactiveForDeletedTask() = runBlocking {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(with(ID, 1), with(DELETION_TIME, newDateTime())))
@ -118,8 +119,8 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun ignoreArrivalForSnoozedTask() {
Freeze.freezeAt(now()).thawAfter {
fun ignoreArrivalForSnoozedTask() = runBlocking {
freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(with(ID, 1), with(SNOOZE_TIME, newDateTime().plusMinutes(15))))
@ -130,8 +131,8 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun ignoreDepartureForSnoozedTask() {
Freeze.freezeAt(now()).thawAfter {
fun ignoreDepartureForSnoozedTask() = runBlocking {
freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(with(ID, 1), with(SNOOZE_TIME, newDateTime().plusMinutes(15))))
@ -142,8 +143,8 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun getArrivalWithElapsedSnooze() {
Freeze.freezeAt(now()).thawAfter {
fun getArrivalWithElapsedSnooze() = runBlocking {
freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(with(ID, 1), with(SNOOZE_TIME, newDateTime().minusMinutes(15))))
@ -155,8 +156,8 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun getDepartureWithElapsedSnooze() {
Freeze.freezeAt(now()).thawAfter {
fun getDepartureWithElapsedSnooze() = runBlocking {
freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(with(ID, 1), with(SNOOZE_TIME, newDateTime().minusMinutes(15))))
@ -168,8 +169,8 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun ignoreArrivalForHiddenTask() {
Freeze.freezeAt(now()).thawAfter {
fun ignoreArrivalForHiddenTask() = runBlocking {
freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(
@ -183,8 +184,8 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun ignoreDepartureForHiddenTask() {
Freeze.freezeAt(now()).thawAfter {
fun ignoreDepartureForHiddenTask() = runBlocking {
freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(
@ -198,8 +199,8 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun getArrivalWithElapsedHideUntil() {
Freeze.freezeAt(now()).thawAfter {
fun getArrivalWithElapsedHideUntil() = runBlocking {
freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(
@ -214,8 +215,8 @@ class LocationDaoTest : InjectingTestCase() {
}
@Test
fun getDepartureWithElapsedHideUntil() {
Freeze.freezeAt(now()).thawAfter {
fun getDepartureWithElapsedHideUntil() = runBlocking {
freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(

@ -2,10 +2,11 @@ package org.tasks.data
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.astrid.api.GtasksFilter
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.helper.UUIDHelper
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
@ -29,8 +30,8 @@ import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class ManualGoogleTaskQueryTest : InjectingTestCase() {
@Inject lateinit var googleTaskDao: GoogleTaskDaoBlocking
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var googleTaskDao: GoogleTaskDao
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var preferences: Preferences
private val filter: GtasksFilter = GtasksFilter(newGoogleTaskList(with(REMOTE_ID, "1234")))
@ -42,7 +43,7 @@ class ManualGoogleTaskQueryTest : InjectingTestCase() {
}
@Test
fun setIndentOnSubtask() {
fun setIndentOnSubtask() = runBlocking {
newTask(1, 0, 0)
newTask(2, 0, 1)
@ -52,7 +53,7 @@ class ManualGoogleTaskQueryTest : InjectingTestCase() {
}
@Test
fun setParentOnSubtask() {
fun setParentOnSubtask() = runBlocking {
newTask(2, 0, 0)
newTask(1, 0, 2)
@ -62,7 +63,7 @@ class ManualGoogleTaskQueryTest : InjectingTestCase() {
}
@Test
fun querySetsPrimarySort() {
fun querySetsPrimarySort() = runBlocking {
newTask(1, 0, 0)
newTask(2, 1, 0)
newTask(3, 0, 2)
@ -75,7 +76,7 @@ class ManualGoogleTaskQueryTest : InjectingTestCase() {
}
@Test
fun querySetsSecondarySortOnSubtasks() {
fun querySetsSecondarySortOnSubtasks() = runBlocking {
newTask(1, 0, 0)
newTask(2, 0, 1)
newTask(3, 1, 1)
@ -88,7 +89,7 @@ class ManualGoogleTaskQueryTest : InjectingTestCase() {
}
@Test
fun ignoreDisableSubtasksPreference() {
fun ignoreDisableSubtasksPreference() = runBlocking {
preferences.setBoolean(R.string.p_use_paged_queries, true)
newTask(1, 0, 0)
newTask(2, 0, 1)
@ -98,12 +99,12 @@ class ManualGoogleTaskQueryTest : InjectingTestCase() {
assertTrue(parent.hasChildren())
}
private fun newTask(id: Long, order: Long, parent: Long = 0) {
private suspend fun newTask(id: Long, order: Long, parent: Long = 0) {
taskDao.insert(TaskMaker.newTask(with(ID, id), with(UUID, UUIDHelper.newUUID())))
googleTaskDao.insert(newGoogleTask(with(LIST, filter.list.remoteId), with(TASK, id), with(PARENT, parent), with(ORDER, order)))
}
private fun query(): List<TaskContainer> = taskDao.fetchTasks {
private suspend fun query(): List<TaskContainer> = taskDao.fetchTasks {
TaskListQuery.getQuery(preferences, filter, it)
}
}

@ -1,9 +1,10 @@
package org.tasks.data
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.dao.TaskDao
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
@ -22,48 +23,48 @@ import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class TagDataDaoTest : InjectingTestCase() {
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var tagDao: TagDaoBlocking
@Inject lateinit var tagDataDao: TagDataDaoBlocking
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var tagDao: TagDao
@Inject lateinit var tagDataDao: TagDataDao
@Test
fun tagDataOrderedByNameIgnoresNullNames() {
fun tagDataOrderedByNameIgnoresNullNames() = runBlocking {
tagDataDao.createNew(newTagData(with(NAME, null as String?)))
assertTrue(tagDataDao.tagDataOrderedByName().isEmpty())
}
@Test
fun tagDataOrderedByNameIgnoresEmptyNames() {
fun tagDataOrderedByNameIgnoresEmptyNames() = runBlocking {
tagDataDao.createNew(newTagData(with(NAME, "")))
assertTrue(tagDataDao.tagDataOrderedByName().isEmpty())
}
@Test
fun getTagWithCaseForMissingTag() {
fun getTagWithCaseForMissingTag() = runBlocking {
assertEquals("derp", tagDataDao.getTagWithCase("derp"))
}
@Test
fun getTagWithCaseFixesCase() {
fun getTagWithCaseFixesCase() = runBlocking {
tagDataDao.createNew(newTagData(with(NAME, "Derp")))
assertEquals("Derp", tagDataDao.getTagWithCase("derp"))
}
@Test
fun getTagsByName() {
fun getTagsByName() = runBlocking {
val tagData = newTagData(with(NAME, "Derp"))
tagDataDao.createNew(tagData)
assertEquals(listOf(tagData), tagDataDao.getTags(listOf("Derp")))
}
@Test
fun getTagsByNameCaseSensitive() {
fun getTagsByNameCaseSensitive() = runBlocking {
tagDataDao.createNew(newTagData(with(NAME, "Derp")))
assertTrue(tagDataDao.getTags(listOf("derp")).isEmpty())
}
@Test
fun getTagDataForTask() {
fun getTagDataForTask() = runBlocking {
val taskOne = newTask()
val taskTwo = newTask()
taskDao.createNew(taskOne)
@ -78,14 +79,14 @@ class TagDataDaoTest : InjectingTestCase() {
}
@Test
fun getEmptyTagSelections() {
fun getEmptyTagSelections() = runBlocking {
val selections = tagDataDao.getTagSelections(listOf(1L))
assertTrue(selections.first!!.isEmpty())
assertTrue(selections.second!!.isEmpty())
}
@Test
fun getPartialTagSelections() {
fun getPartialTagSelections() = runBlocking {
newTag(1, "tag1", "tag2")
newTag(2, "tag2", "tag3")
assertEquals(
@ -93,28 +94,28 @@ class TagDataDaoTest : InjectingTestCase() {
}
@Test
fun getEmptyPartialSelections() {
fun getEmptyPartialSelections() = runBlocking {
newTag(1, "tag1")
newTag(2, "tag1")
assertTrue(tagDataDao.getTagSelections(listOf(1L, 2L)).first!!.isEmpty())
}
@Test
fun getCommonTagSelections() {
fun getCommonTagSelections() = runBlocking {
newTag(1, "tag1", "tag2")
newTag(2, "tag2", "tag3")
assertEquals(setOf("tag2"), tagDataDao.getTagSelections(listOf(1L, 2L)).second)
}
@Test
fun getEmptyCommonSelections() {
fun getEmptyCommonSelections() = runBlocking {
newTag(1, "tag1")
newTag(2, "tag2")
assertTrue(tagDataDao.getTagSelections(listOf(1L, 2L)).second!!.isEmpty())
}
@Test
fun getSelectionsWithNoTags() {
fun getSelectionsWithNoTags() = runBlocking {
newTag(1)
val selections = tagDataDao.getTagSelections(listOf(1L))
assertTrue(selections.first!!.isEmpty())
@ -122,7 +123,7 @@ class TagDataDaoTest : InjectingTestCase() {
}
@Test
fun noCommonSelectionsWhenOneTaskHasNoTags() {
fun noCommonSelectionsWhenOneTaskHasNoTags() = runBlocking {
newTag(1, "tag1")
newTag(2)
val selections = tagDataDao.getTagSelections(listOf(1L, 2L))
@ -130,7 +131,7 @@ class TagDataDaoTest : InjectingTestCase() {
assertTrue(selections.second!!.isEmpty())
}
private fun newTag(taskId: Long, vararg tags: String) {
private suspend fun newTag(taskId: Long, vararg tags: String) {
val task = newTask(with(ID, taskId))
taskDao.createNew(task)
for (tag in tags) {

@ -0,0 +1,43 @@
package org.tasks
import org.tasks.time.DateTime
import org.tasks.time.DateTimeUtils
class SuspendFreeze {
suspend fun thawAfter(run: suspend () -> Unit) {
try {
run.invoke()
} finally {
thaw()
}
}
companion object {
suspend fun freezeClock(run: suspend () -> Unit) {
freezeAt(DateTimeUtils.currentTimeMillis()).thawAfter(run)
}
suspend fun freezeAt(dateTime: DateTime, run: suspend () -> Unit) {
freezeAt(dateTime.millis, run)
}
suspend fun freezeAt(timestamp: Long, run: suspend () -> Unit) {
freezeAt(timestamp).thawAfter(run)
}
fun freezeAt(dateTime: DateTime): SuspendFreeze {
return freezeAt(dateTime.millis)
}
fun freezeAt(millis: Long): SuspendFreeze {
DateTimeUtils.setCurrentMillisFixed(millis)
return SuspendFreeze()
}
fun thaw() {
DateTimeUtils.setCurrentMillisSystem()
}
}
}

@ -7,7 +7,7 @@ import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import dagger.hilt.android.qualifiers.ApplicationContext
import org.tasks.R
import org.tasks.data.LocationDaoBlocking
import org.tasks.data.LocationDao
import org.tasks.preferences.Preferences
import timber.log.Timber
import javax.inject.Inject
@ -15,7 +15,7 @@ import javax.inject.Inject
class PlayServices @Inject constructor(
@param:ApplicationContext private val context: Context,
private val preferences: Preferences,
private val locationDao: LocationDaoBlocking) {
private val locationDao: LocationDao) {
suspend fun check(activity: Activity?) {
val playServicesAvailable = locationDao.geofenceCount() == 0 || refreshAndCheck()

@ -7,10 +7,7 @@ package com.todoroo.astrid.dao
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.data.Task
import org.tasks.data.SubtaskInfo
import org.tasks.data.TaskContainer
import org.tasks.data.runBlocking
import org.tasks.preferences.Preferences
import javax.inject.Inject
@Deprecated("use coroutines")
@ -35,68 +32,14 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) {
dao.activeNotifications()
}
fun fetch(remoteId: String): Task? = runBlocking {
dao.fetch(remoteId)
}
fun getActiveTasks(): List<Task> = runBlocking {
dao.getActiveTasks()
}
fun snooze(taskIds: List<Long>, millis: Long) = runBlocking {
dao.snooze(taskIds, millis)
}
fun getGoogleTasksToPush(account: String): List<Task> = runBlocking {
dao.getGoogleTasksToPush(account)
}
fun getCaldavTasksToPush(calendar: String): List<Task> = runBlocking {
dao.getCaldavTasksToPush(calendar)
}
fun getTasksWithReminders(): List<Task> = runBlocking {
dao.getTasksWithReminders()
}
fun getAll(): List<Task> = runBlocking {
dao.getAll()
}
fun getAllCalendarEvents(): List<String> = runBlocking {
dao.getAllCalendarEvents()
}
fun clearAllCalendarEvents(): Int = runBlocking {
dao.clearAllCalendarEvents()
}
fun getCompletedCalendarEvents(): List<String> = runBlocking {
dao.getCompletedCalendarEvents()
}
fun clearCompletedCalendarEvents(): Int = runBlocking {
dao.clearCompletedCalendarEvents()
}
fun fetchTasks(callback: (SubtaskInfo) -> List<String>): List<TaskContainer> = runBlocking {
dao.fetchTasks {
callback.invoke(it)
}
}
fun fetchTasks(preferences: Preferences, filter: Filter): List<TaskContainer> = runBlocking {
dao.fetchTasks(preferences, filter)
}
fun touch(ids: List<Long>) = runBlocking {
dao.touch(ids)
}
fun getChildren(ids: List<Long>): List<Long> = runBlocking {
dao.getChildren(ids)
}
fun save(task: Task) = runBlocking {
dao.save(task)
}
@ -105,14 +48,6 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) {
dao.save(task, original)
}
fun insert(task: Task): Long = runBlocking {
dao.insert(task)
}
fun update(task: Task): Int = runBlocking {
dao.update(task)
}
fun createNew(task: Task) = runBlocking {
dao.createNew(task)
}

@ -38,7 +38,6 @@ import org.tasks.R
import org.tasks.Strings
import org.tasks.data.Filter
import org.tasks.data.FilterDao
import org.tasks.data.FilterDaoBlocking
import org.tasks.filters.FilterCriteriaProvider
import org.tasks.locale.Locale
import java.util.*

@ -8,10 +8,6 @@ class AlarmDaoBlocking @Inject constructor(private val dao: AlarmDao) {
dao.getAlarms(taskId)
}
fun insert(alarm: Alarm): Long = runBlocking {
dao.insert(alarm)
}
fun insert(alarms: Iterable<Alarm>) = runBlocking {
dao.insert(alarms)
}

@ -2,8 +2,6 @@ package org.tasks.data
import androidx.lifecycle.LiveData
import com.todoroo.astrid.data.Task
import org.tasks.filters.CaldavFilters
import org.tasks.time.DateTimeUtils.currentTimeMillis
import javax.inject.Inject
@Deprecated("use coroutines")
@ -12,147 +10,23 @@ class CaldavDaoBlocking @Inject constructor(private val dao: CaldavDao) {
return dao.subscribeToCalendars()
}
fun getCalendarByUuid(uuid: String): CaldavCalendar? = runBlocking {
dao.getCalendarByUuid(uuid)
}
fun getCalendarsByAccount(uuid: String): List<CaldavCalendar> = runBlocking {
dao.getCalendarsByAccount(uuid)
}
fun getAccountByUuid(uuid: String): CaldavAccount? = runBlocking {
dao.getAccountByUuid(uuid)
}
fun accountCount(): Int = runBlocking {
dao.accountCount()
}
fun getAccounts(): List<CaldavAccount> = runBlocking {
dao.getAccounts()
}
fun setCollapsed(id: Long, collapsed: Boolean) = runBlocking {
dao.setCollapsed(id, collapsed)
}
fun insert(caldavAccount: CaldavAccount): Long = runBlocking {
dao.insert(caldavAccount)
}
fun update(caldavAccount: CaldavAccount) = runBlocking {
dao.update(caldavAccount)
}
fun insert(caldavCalendar: CaldavCalendar) = runBlocking {
dao.insert(caldavCalendar)
}
fun update(caldavCalendar: CaldavCalendar) = runBlocking {
dao.update(caldavCalendar)
}
fun insert(task: Task, caldavTask: CaldavTask, addToTop: Boolean): Long = runBlocking {
dao.insert(task, caldavTask, addToTop)
}
fun insert(caldavTask: CaldavTask): Long = runBlocking {
dao.insert(caldavTask)
}
fun update(caldavTask: CaldavTask) = runBlocking {
dao.update(caldavTask)
}
fun update(tasks: Iterable<CaldavTask>) = runBlocking {
dao.update(tasks)
}
fun delete(caldavTask: CaldavTask) = runBlocking {
dao.delete(caldavTask)
}
fun getDeleted(calendar: String): List<CaldavTask> = runBlocking {
dao.getDeleted(calendar)
}
fun getTask(taskId: Long): CaldavTask? = runBlocking {
dao.getTask(taskId)
}
fun getRemoteIdForTask(taskId: Long): String? = runBlocking {
dao.getRemoteIdForTask(taskId)
}
fun getTask(calendar: String, obj: String): CaldavTask? = runBlocking {
dao.getTask(calendar, obj)
}
fun getTaskByRemoteId(calendar: String, remoteId: String): CaldavTask? = runBlocking {
dao.getTaskByRemoteId(calendar, remoteId)
}
fun getTasks(taskId: Long): List<CaldavTask> = runBlocking {
dao.getTasks(taskId)
}
fun getTasks(): List<CaldavTaskContainer> = runBlocking {
dao.getTasks()
}
fun getCaldavTasksToPush(calendar: String): List<CaldavTaskContainer> = runBlocking {
dao.getCaldavTasksToPush(calendar)
}
fun getCalendars(): List<CaldavCalendar> = runBlocking {
dao.getCalendars()
}
fun getObjects(calendar: String): List<String> = runBlocking {
dao.getObjects(calendar)
}
fun getTasks(calendar: String, objects: List<String>): List<Long> = runBlocking {
dao.getTasks(calendar, objects)
}
fun findDeletedCalendars(account: String, urls: List<String>): List<CaldavCalendar> = runBlocking {
dao.findDeletedCalendars(account, urls)
}
fun getCalendarByUrl(account: String, url: String): CaldavCalendar? = runBlocking {
dao.getCalendarByUrl(account, url)
}
fun getAccountForTask(task: Long): CaldavAccount? = runBlocking {
dao.getAccountForTask(task)
}
fun getCaldavFilters(uuid: String, now: Long = currentTimeMillis()): List<CaldavFilters> = runBlocking {
dao.getCaldavFilters(uuid, now)
}
fun getTasksWithTags(): List<Long> = runBlocking {
dao.getTasksWithTags()
}
fun updateParents() = runBlocking {
dao.updateParents()
}
fun updateParents(calendar: String) = runBlocking {
dao.updateParents(calendar)
}
fun shiftDown(calendar: String, parent: Long, from: Long, to: Long? = null) = runBlocking {
dao.shiftDown(calendar, parent, from, to)
}
fun resetOrders() = runBlocking {
dao.resetOrders()
}
fun setOrder(id: Long, order: Int) = runBlocking {
dao.setOrder(id, order)
}
}

@ -1,34 +0,0 @@
package org.tasks.data
import javax.inject.Inject
@Deprecated("use coroutines")
class DeletionDaoBlocking @Inject constructor(private val dao: DeletionDao) {
fun delete(ids: List<Long>) = runBlocking {
dao.delete(ids)
}
fun markDeleted(ids: Iterable<Long>) = runBlocking {
dao.markDeleted(ids)
}
fun delete(googleTaskList: GoogleTaskList): List<Long> = runBlocking {
dao.delete(googleTaskList)
}
fun delete(googleTaskAccount: GoogleTaskAccount): List<Long> = runBlocking {
dao.delete(googleTaskAccount)
}
fun delete(caldavCalendar: CaldavCalendar): List<Long> = runBlocking {
dao.delete(caldavCalendar)
}
fun purgeDeleted() = runBlocking {
dao.purgeDeleted()
}
fun delete(caldavAccount: CaldavAccount): List<Long> = runBlocking {
dao.delete(caldavAccount)
}
}

@ -1,38 +0,0 @@
package org.tasks.data
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 getAll(): List<Filter> = runBlocking {
dao.getAll()
}
fun resetOrders() = runBlocking {
dao.resetOrders()
}
fun setOrder(id: Long, order: Int) = runBlocking {
dao.setOrder(id, order)
}
}

@ -4,10 +4,6 @@ import javax.inject.Inject
@Deprecated("use coroutines")
class GoogleTaskDaoBlocking @Inject constructor(private val dao: GoogleTaskDao) {
fun insert(task: GoogleTask): Long = runBlocking {
dao.insert(task)
}
fun insertAndShift(task: GoogleTask, top: Boolean) = runBlocking {
dao.insertAndShift(task, top)
}
@ -19,52 +15,4 @@ class GoogleTaskDaoBlocking @Inject constructor(private val dao: GoogleTaskDao)
fun getByTaskId(taskId: Long): GoogleTask? = runBlocking {
dao.getByTaskId(taskId)
}
fun update(googleTask: GoogleTask) = runBlocking {
dao.update(googleTask)
}
fun delete(deleted: GoogleTask) = runBlocking {
dao.delete(deleted)
}
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 getChildren(ids: List<Long>): List<Long> = runBlocking {
dao.getChildren(ids)
}
fun getPrevious(listId: String, parent: Long, order: Long): String? = runBlocking {
dao.getPrevious(listId, parent, order)
}
fun getRemoteId(task: Long): String? = runBlocking {
dao.getRemoteId(task)
}
fun getTask(remoteId: String): Long = runBlocking {
dao.getTask(remoteId)
}
fun updateParents() = runBlocking {
dao.updateParents()
}
fun updatePosition(id: String, parent: String?, position: String) = runBlocking {
dao.updatePosition(id, parent, position)
}
fun reposition(listId: String) = runBlocking {
dao.reposition(listId)
}
}

@ -1,8 +1,6 @@
package org.tasks.data
import androidx.lifecycle.LiveData
import org.tasks.filters.GoogleTaskFilters
import org.tasks.time.DateTimeUtils.currentTimeMillis
import javax.inject.Inject
@Deprecated("use coroutines")
@ -27,10 +25,6 @@ class GoogleTaskListDaoBlocking @Inject constructor(private val dao: GoogleTaskL
dao.getByRemoteId(remoteId)
}
fun getByRemoteId(remoteIds: List<String>): List<GoogleTaskList> = runBlocking {
dao.getByRemoteId(remoteIds)
}
fun subscribeToLists(): LiveData<List<GoogleTaskList>> {
return dao.subscribeToLists()
}
@ -51,10 +45,6 @@ class GoogleTaskListDaoBlocking @Inject constructor(private val dao: GoogleTaskL
dao.insertOrReplace(googleTaskList)
}
fun insert(googleTaskList: GoogleTaskList): Long = runBlocking {
dao.insert(googleTaskList)
}
fun insert(googleTaskAccount: GoogleTaskAccount) = runBlocking {
dao.insert(googleTaskAccount)
}
@ -62,20 +52,4 @@ class GoogleTaskListDaoBlocking @Inject constructor(private val dao: GoogleTaskL
fun update(account: GoogleTaskAccount) = runBlocking {
dao.update(account)
}
fun update(list: GoogleTaskList) = runBlocking {
dao.update(list)
}
fun getGoogleTaskFilters(account: String, now: Long = currentTimeMillis()): List<GoogleTaskFilters> = runBlocking {
dao.getGoogleTaskFilters(account, now)
}
fun resetOrders() = runBlocking {
dao.resetOrders()
}
fun setOrder(id: Long, order: Int) = runBlocking {
dao.setOrder(id, order)
}
}

@ -13,10 +13,6 @@ class LocationDaoBlocking @Inject constructor(private val dao: LocationDao) {
dao.getGeofencesByPlace(uid)
}
fun deleteGeofencesByPlace(place: String) = runBlocking {
dao.deleteGeofencesByPlace(place)
}
fun getArrivalGeofences(place: String, now: Long): List<Geofence> = runBlocking {
dao.getArrivalGeofences(place, now)
}
@ -25,34 +21,10 @@ class LocationDaoBlocking @Inject constructor(private val dao: LocationDao) {
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)
}
@ -61,26 +33,10 @@ class LocationDaoBlocking @Inject constructor(private val dao: LocationDao) {
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)
}
@ -96,12 +52,4 @@ class LocationDaoBlocking @Inject constructor(private val dao: LocationDao) {
fun findPlace(latitude: String, longitude: String): Place? = runBlocking {
dao.findPlace(latitude, longitude)
}
fun resetOrders() = runBlocking {
dao.resetOrders()
}
fun setOrder(id: Long, order: Int) = runBlocking {
dao.setOrder(id, order)
}
}

@ -1,14 +1,9 @@
package org.tasks.data
import com.todoroo.astrid.data.Task
import javax.inject.Inject
@Deprecated("use coroutines")
class TagDaoBlocking @Inject constructor(private val dao: TagDao) {
fun rename(tagUid: String, name: String) = runBlocking {
dao.rename(tagUid, name)
}
fun insert(tag: Tag) = runBlocking {
dao.insert(tag)
}
@ -16,28 +11,4 @@ class TagDaoBlocking @Inject constructor(private val dao: TagDao) {
fun insert(tags: Iterable<Tag>) = runBlocking {
dao.insert(tags)
}
fun getByTagUid(tagUid: String): List<Tag> = runBlocking {
dao.getByTagUid(tagUid)
}
fun getTagsForTask(taskId: Long): List<Tag> = runBlocking {
dao.getTagsForTask(taskId)
}
fun getTagByTaskAndTagUid(taskId: Long, tagUid: String): Tag? = runBlocking {
dao.getTagByTaskAndTagUid(taskId, tagUid)
}
fun delete(tags: List<Tag>) = runBlocking {
dao.delete(tags)
}
fun applyTags(task: Task, tagDataDao: TagDataDaoBlocking, current: List<TagData>): Boolean = runBlocking {
dao.applyTags(task, tagDataDao.dao, current)
}
fun insert(task: Task, tags: Collection<TagData>) = runBlocking {
dao.insert(task, tags)
}
}

@ -1,11 +1,10 @@
package org.tasks.data
import androidx.core.util.Pair
import androidx.lifecycle.LiveData
import javax.inject.Inject
@Deprecated("use coroutines")
class TagDataDaoBlocking @Inject constructor(val dao: TagDataDao) {
class TagDataDaoBlocking @Inject constructor(private val dao: TagDataDao) {
fun subscribeToTags(): LiveData<List<TagData>> {
return dao.subscribeToTags()
}
@ -22,51 +21,15 @@ class TagDataDaoBlocking @Inject constructor(val dao: TagDataDao) {
dao.searchTags(query)
}
fun getAll(): List<TagData> = runBlocking {
dao.getAll()
}
fun getByUuid(uuid: String): TagData? = runBlocking {
dao.getByUuid(uuid)
}
fun tagDataOrderedByName(): List<TagData> = runBlocking {
dao.tagDataOrderedByName()
}
fun getTagSelections(tasks: List<Long>): Pair<Set<String>, Set<String>> = runBlocking {
dao.getTagSelections(tasks)
}
fun delete(tagData: TagData) = runBlocking {
dao.delete(tagData)
}
fun delete(tagData: List<TagData>) = runBlocking {
dao.delete(tagData)
}
fun getTagDataForTask(id: Long): List<TagData> = runBlocking {
dao.getTagDataForTask(id)
}
fun getTags(names: List<String>): List<TagData> = runBlocking {
dao.getTags(names)
}
fun update(tagData: TagData) = runBlocking {
dao.update(tagData)
}
fun createNew(tag: TagData) = runBlocking {
dao.createNew(tag)
}
fun resetOrders() = runBlocking {
dao.resetOrders()
}
fun setOrder(id: Long, order: Int) = runBlocking {
dao.setOrder(id, order)
}
}

@ -1,30 +0,0 @@
package org.tasks.data
import javax.inject.Inject
@Deprecated("use coroutines")
class TaskAttachmentDaoBlocking @Inject constructor(private val dao: TaskAttachmentDao) {
fun getAttachments(taskUuid: String): List<TaskAttachment> = runBlocking {
dao.getAttachments(taskUuid)
}
fun getAttachments(task: Long): List<TaskAttachment> = runBlocking {
dao.getAttachments(task)
}
fun getAttachments(): List<TaskAttachment> = runBlocking {
dao.getAttachments()
}
fun delete(taskAttachment: TaskAttachment) = runBlocking {
dao.delete(taskAttachment)
}
fun insert(attachment: TaskAttachment) = runBlocking {
dao.insert(attachment)
}
fun update(attachment: TaskAttachment) = runBlocking {
dao.update(attachment)
}
}

@ -1,18 +0,0 @@
package org.tasks.data
import javax.inject.Inject
@Deprecated("use coroutines")
class TaskListMetadataDaoBlocking @Inject constructor(private val dao: TaskListMetadataDao) {
fun fetchByTagOrFilter(tagUuid: String): TaskListMetadata? = runBlocking {
dao.fetchByTagOrFilter(tagUuid)
}
fun getAll(): List<TaskListMetadata> = runBlocking {
dao.getAll()
}
fun insert(taskListMetadata: TaskListMetadata): Long = runBlocking {
dao.insert(taskListMetadata)
}
}

@ -4,31 +4,7 @@ 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)
}
}
Loading…
Cancel
Save