Convert Task to Kotlin

pull/996/head
Alex Baker 5 years ago
parent d4d4053ec1
commit 3b6d355890

@ -43,7 +43,7 @@ class AlarmJobServiceTest : InjectingTestCase() {
val task = newTask()
taskDao.createNew(task)
val alarmTime = DateTime(2017, 9, 24, 19, 57)
val alarm = Alarm(task.getId(), alarmTime.millis)
val alarm = Alarm(task.id!!, alarmTime.millis)
alarm.id = alarmDao.insert(alarm)
alarmService.scheduleAllAlarms()
Mockito.verify(jobs).add(AlarmEntry(alarm))
@ -54,7 +54,7 @@ class AlarmJobServiceTest : InjectingTestCase() {
val alarmTime = DateTime(2017, 9, 24, 19, 57)
val task = newTask(with(REMINDER_LAST, alarmTime.endOfMinute()))
taskDao.createNew(task)
alarmDao.insert(Alarm(task.getId(), alarmTime.millis))
alarmDao.insert(Alarm(task.id!!, alarmTime.millis))
alarmService.scheduleAllAlarms()
}

@ -32,32 +32,32 @@ class TaskDaoTests : InjectingTestCase() {
// create task "happy"
var task = Task()
task.setTitle("happy")
task.title = "happy"
taskDao.createNew(task)
assertEquals(1, taskDao.getAll().size)
val happyId = task.getId()
val happyId = task.id!!
assertNotSame(Task.NO_ID, happyId)
task = taskDao.fetch(happyId)!!
assertEquals("happy", task.getTitle())
assertEquals("happy", task.title)
// create task "sad"
task = Task()
task.setTitle("sad")
task.title = "sad"
taskDao.createNew(task)
assertEquals(2, taskDao.getAll().size)
// rename sad to melancholy
val sadId = task.getId()
val sadId = task.id!!
assertNotSame(Task.NO_ID, sadId)
task.setTitle("melancholy")
task.title = "melancholy"
taskDao.save(task)
assertEquals(2, taskDao.getAll().size)
// check state
task = taskDao.fetch(happyId)!!
assertEquals("happy", task.getTitle())
assertEquals("happy", task.title)
task = taskDao.fetch(sadId)!!
assertEquals("melancholy", task.getTitle())
assertEquals("melancholy", task.title)
}
/** Test various task fetch conditions */
@ -65,33 +65,33 @@ class TaskDaoTests : InjectingTestCase() {
fun testTaskConditions() {
// create normal task
var task = Task()
task.setTitle("normal")
task.title = "normal"
taskDao.createNew(task)
// create blank task
task = Task()
task.setTitle("")
task.title = ""
taskDao.createNew(task)
// create hidden task
task = Task()
task.setTitle("hidden")
task.setHideUntil(DateUtilities.now() + 10000)
task.title = "hidden"
task.hideUntil = DateUtilities.now() + 10000
taskDao.createNew(task)
// create task with deadlines
task = Task()
task.setTitle("deadlineInFuture")
task.setDueDate(DateUtilities.now() + 10000)
task.title = "deadlineInFuture"
task.dueDate = DateUtilities.now() + 10000
taskDao.createNew(task)
task = Task()
task.setTitle("deadlineInPast")
task.setDueDate(DateUtilities.now() - 10000)
task.title = "deadlineInPast"
task.dueDate = DateUtilities.now() - 10000
taskDao.createNew(task)
// create completed task
task = Task()
task.setTitle("completed")
task.title = "completed"
task.completionDate = DateUtilities.now() - 10000
taskDao.createNew(task)
@ -109,7 +109,7 @@ class TaskDaoTests : InjectingTestCase() {
// create task "happy"
val task = Task()
task.setTitle("happy")
task.title = "happy"
taskDao.createNew(task)
assertEquals(1, taskDao.getAll().size)
@ -123,8 +123,8 @@ class TaskDaoTests : InjectingTestCase() {
fun testSaveWithoutCreate() {
// try to save task "happy"
val task = Task()
task.setTitle("happy")
task.setId(1L)
task.title = "happy"
task.id = 1L
taskDao.save(task)
assertEquals(0, taskDao.getAll().size)
}

@ -79,7 +79,7 @@ class TaskTest {
@Test
fun testTaskHasDueTime() {
val task = Task()
task.setDueDate(1388516076000L)
task.dueDate = 1388516076000L
assertTrue(task.hasDueTime())
assertTrue(task.hasDueDate())
}
@ -87,7 +87,7 @@ class TaskTest {
@Test
fun testTaskHasDueDate() {
val task = Task()
task.setDueDate(1388469600000L)
task.dueDate = 1388469600000L
assertFalse(task.hasDueTime())
assertTrue(task.hasDueDate())
}
@ -148,7 +148,7 @@ class TaskTest {
val now = org.tasks.time.DateTimeUtils.currentTimeMillis()
freezeAt(now) {
val task = Task()
task.setHideUntil(now)
task.hideUntil = now
assertFalse(task.isHidden)
}
}
@ -158,7 +158,7 @@ class TaskTest {
val now = org.tasks.time.DateTimeUtils.currentTimeMillis()
freezeAt(now) {
val task = Task()
task.setHideUntil(now + 1)
task.hideUntil = now + 1
assertTrue(task.isHidden)
}
}
@ -180,7 +180,7 @@ class TaskTest {
val now = org.tasks.time.DateTimeUtils.currentTimeMillis()
freezeAt(now) {
val task = Task()
task.setDueDate(now)
task.dueDate = now
assertFalse(task.isOverdue)
}
}
@ -190,7 +190,7 @@ class TaskTest {
val dueDate = org.tasks.time.DateTimeUtils.currentTimeMillis()
freezeAt(dueDate + 1) {
val task = Task()
task.setDueDate(dueDate)
task.dueDate = dueDate
assertTrue(task.isOverdue)
}
}
@ -200,7 +200,7 @@ class TaskTest {
val dueDate = DateTime().startOfDay()
freezeAt(dueDate.plusHours(12).minusMillis(1)) {
val task = Task()
task.setDueDate(dueDate.millis)
task.dueDate = dueDate.millis
assertFalse(task.hasDueTime())
assertFalse(task.isOverdue)
}
@ -211,7 +211,7 @@ class TaskTest {
val dueDate = DateTime().startOfDay()
freezeAt(dueDate.plusHours(12)) {
val task = Task()
task.setDueDate(dueDate.millis)
task.dueDate = dueDate.millis
assertFalse(task.hasDueTime())
assertFalse(task.isOverdue)
}
@ -222,7 +222,7 @@ class TaskTest {
val dueDate = DateTime().startOfDay()
freezeAt(dueDate.plusDays(1)) {
val task = Task()
task.setDueDate(dueDate.millis)
task.dueDate = dueDate.millis
assertFalse(task.hasDueTime())
assertTrue(task.isOverdue)
}

@ -52,18 +52,18 @@ class GtasksMetadataServiceTest : InjectingTestCase() {
// --- helpers
private fun whenSearchForMetadata() {
metadata = googleTaskDao.getByTaskId(task!!.getId())
metadata = googleTaskDao.getByTaskId(task!!.id!!)
}
private fun taskWithMetadata(id: String?): Task {
val task = Task()
task.setTitle("cats")
task.title = "cats"
taskDao.createNew(task)
val metadata = GoogleTask(task.getId(), "")
val metadata = GoogleTask(task.id!!, "")
if (id != null) {
metadata.remoteId = id
}
metadata.task = task.getId()
metadata.task = task.id!!
googleTaskDao.insert(metadata)
return task
}
@ -74,7 +74,7 @@ class GtasksMetadataServiceTest : InjectingTestCase() {
private fun taskWithoutMetadata(): Task {
val task = Task()
task.setTitle("dogs")
task.title = "dogs"
taskDao.createNew(task)
return task
}

@ -29,7 +29,7 @@ class TaskTest : InjectingTestCase() {
fun testReadTaskFromDb() {
val task = Task()
taskDao.createNew(task)
val fromDb = taskDao.fetch(task.getId())
val fromDb = taskDao.fetch(task.id!!)
assertEquals(task, fromDb)
}

@ -80,7 +80,7 @@ class ReminderServiceTest : InjectingTestCase() {
service.scheduleAlarm(task)
val order = Mockito.inOrder(jobs)
order.verify(jobs).cancelReminder(1)
order.verify(jobs).add(ReminderEntry(1, task.getDueDate(), ReminderService.TYPE_DUE))
order.verify(jobs).add(ReminderEntry(1, task.dueDate!!, ReminderService.TYPE_DUE))
}
@Test
@ -92,7 +92,7 @@ class ReminderServiceTest : InjectingTestCase() {
service.scheduleAlarm(task)
val order = Mockito.inOrder(jobs)
order.verify(jobs).cancelReminder(1)
order.verify(jobs).add(ReminderEntry(1, task.getDueDate(), ReminderService.TYPE_DUE))
order.verify(jobs).add(ReminderEntry(1, task.dueDate!!, ReminderService.TYPE_DUE))
}
@Test
@ -154,7 +154,7 @@ class ReminderServiceTest : InjectingTestCase() {
service.scheduleAlarm(task)
val order = Mockito.inOrder(jobs)
order.verify(jobs).cancelReminder(1)
order.verify(jobs).add(ReminderEntry(1, task.getDueDate(), ReminderService.TYPE_DUE))
order.verify(jobs).add(ReminderEntry(1, task.dueDate!!, ReminderService.TYPE_DUE))
}
@Test
@ -171,7 +171,7 @@ class ReminderServiceTest : InjectingTestCase() {
order.verify(jobs).cancelReminder(1)
order
.verify(jobs)
.add(ReminderEntry(1, task.reminderSnooze, ReminderService.TYPE_SNOOZE))
.add(ReminderEntry(1, task.reminderSnooze!!, ReminderService.TYPE_SNOOZE))
}
@Test

@ -45,7 +45,7 @@ class AdvancedRepeatTest {
// test specific day & time
val dayWithTime = Task.createDueDate(
Task.URGENCY_SPECIFIC_DAY_TIME, DateTime(2010, 8, 1, 10, 4, 0).millis)
task!!.setDueDate(dayWithTime)
task!!.dueDate = dayWithTime
val nextDayWithTime = dayWithTime + DateUtilities.ONE_DAY
nextDueDate = RepeatTaskHelper.computeNextDueDate(task, rrule!!.toIcal(), false)
assertDateTimeEquals(nextDayWithTime, nextDueDate)
@ -60,7 +60,7 @@ class AdvancedRepeatTest {
// test specific day & time
val dayWithTime = Task.createDueDate(
Task.URGENCY_SPECIFIC_DAY_TIME, DateTime(2010, 8, 1, 10, 4, 0).millis)
task!!.setDueDate(dayWithTime)
task!!.dueDate = dayWithTime
val todayWithTime = DateTimeUtils.newDateTime().withHourOfDay(10).withMinuteOfHour(4).withSecondOfMinute(1)
var nextDayWithTimeLong = todayWithTime.millis
nextDayWithTimeLong += DateUtilities.ONE_DAY
@ -206,7 +206,7 @@ class AdvancedRepeatTest {
}
private fun assertDueDate(actual: Long, expectedWhich: Int, expectedDayOfWeek: Int) {
val expected = getDate(task!!.getDueDate(), expectedWhich, expectedDayOfWeek)
val expected = getDate(task!!.dueDate!!, expectedWhich, expectedDayOfWeek)
assertEquals(expected, actual)
}
@ -220,7 +220,7 @@ class AdvancedRepeatTest {
private fun setTaskDueDate(which: Int, day: Int) {
val time = getDate(DateUtilities.now(), which, day)
task!!.setDueDate(time)
task!!.dueDate = time
}
private fun getDate(start: Long, which: Int, dayOfWeek: Int): Long {

@ -224,8 +224,8 @@ class NewRepeatTests {
private fun newFromDue(frequency: Frequency, interval: Int, dueDateTime: DateTime): Task {
return object : Task() {
init {
setRecurrence(getRecurrenceRule(frequency, interval, false))
setDueDate(dueDateTime.millis)
recurrence = getRecurrenceRule(frequency, interval, false)
dueDate = dueDateTime.millis
}
}
}
@ -233,8 +233,8 @@ class NewRepeatTests {
private fun newWeeklyFromDue(interval: Int, dueDateTime: DateTime, vararg weekdays: WeekdayNum): Task {
return object : Task() {
init {
setRecurrence(getRecurrenceRule(Frequency.WEEKLY, interval, false, *weekdays))
setDueDate(dueDateTime.millis)
recurrence = getRecurrenceRule(Frequency.WEEKLY, interval, false, *weekdays)
dueDate = dueDateTime.millis
}
}
}
@ -243,9 +243,9 @@ class NewRepeatTests {
frequency: Frequency, interval: Int, dueDateTime: DateTime, completionDate: DateTime): Task {
return object : Task() {
init {
setRecurrence(getRecurrenceRule(frequency, interval, true))
setDueDate(dueDateTime.millis)
setCompletionDate(completionDate.millis)
recurrence = getRecurrenceRule(frequency, interval, true)
dueDate = dueDateTime.millis
this.completionDate = completionDate.millis
}
}
}
@ -254,9 +254,9 @@ class NewRepeatTests {
interval: Int, dueDateTime: DateTime, completionDate: DateTime, vararg weekdays: WeekdayNum): Task {
return object : Task() {
init {
setRecurrence(getRecurrenceRule(Frequency.WEEKLY, interval, true, *weekdays))
setDueDate(dueDateTime.millis)
setCompletionDate(completionDate.millis)
recurrence = getRecurrenceRule(Frequency.WEEKLY, interval, true, *weekdays)
dueDate = dueDateTime.millis
this.completionDate = completionDate.millis
}
}
}

@ -90,7 +90,7 @@ class RepeatTaskHelperTest : InjectingTestCase() {
with(RRULE, RRule("RRULE:FREQ=MINUTELY;COUNT=2;INTERVAL=30")))
repeatAndVerify(
task, DateTime(2017, 10, 4, 13, 30, 1), DateTime(2017, 10, 4, 14, 0, 1))
assertEquals(1, RRule(task.recurrenceWithoutFrom).count)
assertEquals(1, RRule(task.getRecurrenceWithoutFrom()).count)
}
@Test

@ -79,17 +79,17 @@ class QuickAddMarkupTest : InjectingTestCase() {
}
private fun assertTitleBecomes(title: String) {
assertEquals(title, task!!.getTitle())
assertEquals(title, task!!.title)
}
private fun whenTitleIs(title: String) {
task = Task()
task!!.setTitle(title)
task!!.title = title
tags.clear()
TitleParser.parse(tagDataDao, task, tags)
}
private fun assertPriority(priority: Int) {
assertEquals(priority, task!!.getPriority() as Int)
assertEquals(priority, task!!.priority)
}
}

@ -121,7 +121,7 @@ class TaskMoverTest : InjectingTestCase() {
assertEquals(3, deleted.size.toLong())
val task = caldavDao.getTask(3)
assertEquals("2", task!!.calendar)
assertEquals(2, taskDao.fetch(3)!!.getParent())
assertEquals(2, taskDao.fetch(3)!!.parent)
}
@Test
@ -132,7 +132,7 @@ class TaskMoverTest : InjectingTestCase() {
moveToCaldavList("1", 1)
val task = caldavDao.getTask(2)
assertEquals("1", task!!.calendar)
assertEquals(1, taskDao.fetch(2)!!.getParent())
assertEquals(1, taskDao.fetch(2)!!.parent)
}
@Test
@ -142,7 +142,7 @@ class TaskMoverTest : InjectingTestCase() {
createSubtask(3, 2)
moveToGoogleTasks("1", 1)
assertEquals(1, googleTaskDao.getByTaskId(3)!!.parent)
assertEquals(0, taskDao.fetch(3)!!.getParent())
assertEquals(0, taskDao.fetch(3)!!.parent)
}
@Test
@ -150,7 +150,7 @@ class TaskMoverTest : InjectingTestCase() {
createTasks(1)
createSubtask(2, 1)
moveToGoogleTasks("1", 2)
assertEquals(0, taskDao.fetch(2)!!.getParent())
assertEquals(0, taskDao.fetch(2)!!.parent)
}
@Test
@ -158,7 +158,7 @@ class TaskMoverTest : InjectingTestCase() {
createTasks(1)
createSubtask(2, 1)
moveToCaldavList("1", 2)
assertEquals(0, taskDao.fetch(2)!!.getParent())
assertEquals(0, taskDao.fetch(2)!!.parent)
}
@Test
@ -209,7 +209,7 @@ class TaskMoverTest : InjectingTestCase() {
with(REMOTE_PARENT, "a"))))
moveToCaldavList("2", 2)
assertEquals("2", caldavDao.getTask(2)!!.calendar)
assertEquals(0, taskDao.fetch(2)!!.getParent())
assertEquals(0, taskDao.fetch(2)!!.parent)
}
@Test
@ -235,7 +235,7 @@ class TaskMoverTest : InjectingTestCase() {
createSubtask(3, 2)
moveToCaldavList("1", 1)
assertEquals("1", caldavDao.getTask(3)!!.calendar)
assertEquals(2, taskDao.fetch(3)!!.getParent())
assertEquals(2, taskDao.fetch(3)!!.parent)
}
@Test
@ -265,8 +265,8 @@ class TaskMoverTest : InjectingTestCase() {
assertNull(googleTaskDao.getByTaskId(2))
val task = taskDao.fetch(2)!!
assertFalse(task.isDeleted)
assertEquals(1, task.getParent())
assertEquals(taskDao.fetch(1)!!.uuid, task.getParentUuid())
assertEquals(1, task.parent)
assertEquals(taskDao.fetch(1)!!.uuid, task.parentUuid)
}
@Test
@ -291,8 +291,8 @@ class TaskMoverTest : InjectingTestCase() {
assertNull(caldavDao.getTask(3))
val task = taskDao.fetch(3)!!
assertFalse(task.isDeleted)
assertEquals(2, task.getParent())
assertEquals(taskDao.fetch(2)!!.uuid, task.getParentUuid())
assertEquals(2, task.parent)
assertEquals(taskDao.fetch(2)!!.uuid, task.parentUuid)
}
@Test

@ -45,7 +45,7 @@ class TitleParserTest : InjectingTestCase() {
val nothing = Task()
assertFalse(task.hasDueTime())
assertFalse(task.hasDueDate())
assertEquals(task.getRecurrence(), nothing.getRecurrence())
assertEquals(task.recurrence, nothing.recurrence)
}
/** Tests correct date is parsed */
@ -68,7 +68,7 @@ class TitleParserTest : InjectingTestCase() {
for (i in 0..22) {
val testTitle = "Jog on " + titleMonthStrings[i] + " 12."
val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.getDueDate())
val date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.monthOfYear, i / 2 + 1)
assertEquals(date.dayOfMonth, 12)
}
@ -79,7 +79,7 @@ class TitleParserTest : InjectingTestCase() {
for (i in 1..12) {
val testTitle = "Jog on $i/12/13"
val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.getDueDate())
val date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.monthOfYear, i)
assertEquals(date.dayOfMonth, 12)
assertEquals(date.year, 2013)
@ -90,7 +90,7 @@ class TitleParserTest : InjectingTestCase() {
fun testArmyTime() {
val testTitle = "Jog on 23:21."
val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.getDueDate())
val date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.hourOfDay, 23)
assertEquals(date.minuteOfHour, 21)
}
@ -99,7 +99,7 @@ class TitleParserTest : InjectingTestCase() {
fun test_AM_PM() {
val testTitle = "Jog at 8:33 PM."
val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.getDueDate())
val date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.hourOfDay, 20)
assertEquals(date.minuteOfHour, 33)
}
@ -108,7 +108,7 @@ class TitleParserTest : InjectingTestCase() {
fun test_at_hour() {
val testTitle = "Jog at 8 PM."
val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.getDueDate())
val date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.hourOfDay, 20)
assertEquals(date.minuteOfHour, 0)
}
@ -117,7 +117,7 @@ class TitleParserTest : InjectingTestCase() {
fun test_oclock_AM() {
val testTitle = "Jog at 8 o'clock AM."
val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.getDueDate())
val date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.hourOfDay, 8)
assertEquals(date.minuteOfHour, 0)
}
@ -127,7 +127,7 @@ class TitleParserTest : InjectingTestCase() {
val testTitles = arrayOf("Jog 8 AM", "Jog 8 o'clock AM", "at 8:00 AM")
for (testTitle in testTitles) {
val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.getDueDate())
val date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.hourOfDay, 8)
assertEquals(date.minuteOfHour, 0)
}
@ -140,7 +140,7 @@ class TitleParserTest : InjectingTestCase() {
)
for (testTitle in testTitles) {
val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.getDueDate())
val date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.hourOfDay, 12)
assertEquals(date.minuteOfHour, 30)
}
@ -156,12 +156,12 @@ class TitleParserTest : InjectingTestCase() {
val today = Calendar.getInstance()
var title = "Jog today"
var task = taskCreator.createWithValues(title)
var date = DateTimeUtils.newDateTime(task.getDueDate())
var date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.dayOfWeek, today[Calendar.DAY_OF_WEEK])
// Calendar starts 1-6, date.getDay() starts at 0
title = "Jog tomorrow"
task = taskCreator.createWithValues(title)
date = DateTimeUtils.newDateTime(task.getDueDate())
date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.dayOfWeek % 7, (today[Calendar.DAY_OF_WEEK] + 1) % 7)
val days = arrayOf(
"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday")
@ -169,11 +169,11 @@ class TitleParserTest : InjectingTestCase() {
for (i in 1..6) {
title = "Jog " + days[i]
task = taskCreator.createWithValues(title)
date = DateTimeUtils.newDateTime(task.getDueDate())
date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.dayOfWeek, i + 1)
title = "Jog " + abrevDays[i]
task = taskCreator.createWithValues(title)
date = DateTimeUtils.newDateTime(task.getDueDate())
date = DateTimeUtils.newDateTime(task.dueDate!!)
assertEquals(date.dayOfWeek, i + 1)
}
}
@ -186,12 +186,12 @@ class TitleParserTest : InjectingTestCase() {
for (acceptedString in acceptedStrings) {
val title = "Jog $acceptedString"
val task = taskCreator.createWithValues(title)
assertEquals(task.getPriority() as Int, Task.Priority.NONE)
assertEquals(task.priority, Task.Priority.NONE)
}
for (acceptedString in acceptedStrings) {
val title = "$acceptedString jog"
val task = taskCreator.createWithValues(title)
assertNotSame(task.getPriority(), Task.Priority.NONE)
assertNotSame(task.priority, Task.Priority.NONE)
}
}
@ -203,20 +203,20 @@ class TitleParserTest : InjectingTestCase() {
for (acceptedStringAtEnd in acceptedStringsAtEnd) {
task = taskCreator.basicQuickAddTask(
"Jog $acceptedStringAtEnd") // test at end of task. should set importance.
assertEquals(task.getPriority() as Int, Task.Priority.LOW)
assertEquals(task.priority, Task.Priority.LOW)
}
for (acceptedStringAtEnd in acceptedStringsAtEnd) {
task = taskCreator.basicQuickAddTask(acceptedStringAtEnd
+ " jog") // test at beginning of task. should not set importance.
assertEquals(task.getPriority() as Int, Task.Priority.LOW)
assertEquals(task.priority, Task.Priority.LOW)
}
for (acceptedStringAnywhere in acceptedStringsAnywhere) {
task = taskCreator.basicQuickAddTask(
"Jog $acceptedStringAnywhere") // test at end of task. should set importance.
assertEquals(task.getPriority() as Int, Task.Priority.LOW)
assertEquals(task.priority, Task.Priority.LOW)
task = taskCreator.basicQuickAddTask(
"$acceptedStringAnywhere jog") // test at beginning of task. should set importance.
assertEquals(task.getPriority() as Int, Task.Priority.LOW)
assertEquals(task.priority, Task.Priority.LOW)
}
}
@ -227,18 +227,18 @@ class TitleParserTest : InjectingTestCase() {
for (acceptedStringAtEnd in acceptedStringsAtEnd) {
var title = "Jog $acceptedStringAtEnd"
var task = taskCreator.createWithValues(title)
assertEquals(task.getPriority() as Int, Task.Priority.MEDIUM)
assertEquals(task.priority, Task.Priority.MEDIUM)
title = "$acceptedStringAtEnd jog"
task = taskCreator.createWithValues(title)
assertNotSame(task.getPriority(), Task.Priority.MEDIUM)
assertNotSame(task.priority, Task.Priority.MEDIUM)
}
for (acceptedStringAnywhere in acceptedStringsAnywhere) {
var title = "Jog $acceptedStringAnywhere"
var task = taskCreator.createWithValues(title)
assertEquals(task.getPriority() as Int, Task.Priority.MEDIUM)
assertEquals(task.priority, Task.Priority.MEDIUM)
title = "$acceptedStringAnywhere jog"
task = taskCreator.createWithValues(title)
assertEquals(task.getPriority() as Int, Task.Priority.MEDIUM)
assertEquals(task.priority, Task.Priority.MEDIUM)
}
}
@ -255,18 +255,18 @@ class TitleParserTest : InjectingTestCase() {
for (acceptedStringAtEnd in acceptedStringsAtEnd) {
var title = "Jog $acceptedStringAtEnd"
var task = taskCreator.createWithValues(title)
assertEquals(task.getPriority() as Int, Task.Priority.HIGH)
assertEquals(task.priority, Task.Priority.HIGH)
title = "$acceptedStringAtEnd jog"
task = taskCreator.createWithValues(title)
assertNotSame(task.getPriority(), Task.Priority.HIGH)
assertNotSame(task.priority, Task.Priority.HIGH)
}
for (acceptedStringAnywhere in acceptedStringsAnywhere) {
var title = "Jog $acceptedStringAnywhere"
var task = taskCreator.createWithValues(title)
assertEquals(task.getPriority() as Int, Task.Priority.HIGH)
assertEquals(task.priority, Task.Priority.HIGH)
title = "$acceptedStringAnywhere jog"
task = taskCreator.createWithValues(title)
assertEquals(task.getPriority() as Int, Task.Priority.HIGH)
assertEquals(task.priority, Task.Priority.HIGH)
}
}
// ----------------Priority end----------------//
@ -279,19 +279,19 @@ class TitleParserTest : InjectingTestCase() {
val rrule = RRule()
rrule.freq = Frequency.DAILY
rrule.interval = 1
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertFalse(task.hasDueTime())
assertFalse(task.hasDueDate())
title = "Jog every day"
task = taskCreator.createWithValues(title)
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertFalse(task.hasDueTime())
assertFalse(task.hasDueDate())
for (i in 1..12) {
title = "Jog every $i days."
rrule.interval = i
task = taskCreator.createWithValues(title)
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertFalse(task.hasDueTime())
assertFalse(task.hasDueDate())
}
@ -305,19 +305,19 @@ class TitleParserTest : InjectingTestCase() {
val rrule = RRule()
rrule.freq = Frequency.WEEKLY
rrule.interval = 1
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertFalse(task.hasDueTime())
assertFalse(task.hasDueDate())
title = "Jog every week"
task = taskCreator.createWithValues(title)
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertFalse(task.hasDueTime())
assertFalse(task.hasDueDate())
for (i in 1..12) {
title = "Jog every $i weeks"
rrule.interval = i
task = taskCreator.createWithValues(title)
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertFalse(task.hasDueTime())
assertFalse(task.hasDueDate())
}
@ -331,19 +331,19 @@ class TitleParserTest : InjectingTestCase() {
val rrule = RRule()
rrule.freq = Frequency.MONTHLY
rrule.interval = 1
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertFalse(task.hasDueTime())
assertFalse(task.hasDueDate())
title = "Jog every month"
task = taskCreator.createWithValues(title)
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertFalse(task.hasDueTime())
assertFalse(task.hasDueDate())
for (i in 1..12) {
title = "Jog every $i months"
rrule.interval = i
task = taskCreator.createWithValues(title)
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertFalse(task.hasDueTime())
assertFalse(task.hasDueDate())
}
@ -356,17 +356,17 @@ class TitleParserTest : InjectingTestCase() {
val rrule = RRule()
rrule.freq = Frequency.DAILY
rrule.interval = 1
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertTrue(task.hasDueDate())
title = "Jog every day starting from today"
task = taskCreator.createWithValues(title)
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertTrue(task.hasDueDate())
for (i in 1..12) {
title = "Jog every $i days starting from today"
rrule.interval = i
task = taskCreator.createWithValues(title)
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertTrue(task.hasDueDate())
}
}
@ -378,17 +378,17 @@ class TitleParserTest : InjectingTestCase() {
val rrule = RRule()
rrule.freq = Frequency.WEEKLY
rrule.interval = 1
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertTrue(task.hasDueDate())
title = "Jog every week starting from today"
task = taskCreator.createWithValues(title)
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertTrue(task.hasDueDate())
for (i in 1..12) {
title = "Jog every $i weeks starting from today"
rrule.interval = i
task = taskCreator.createWithValues(title)
assertEquals(task.getRecurrence(), rrule.toIcal())
assertEquals(task.recurrence, rrule.toIcal())
assertTrue(task.hasDueDate())
}
}
@ -401,7 +401,7 @@ class TitleParserTest : InjectingTestCase() {
var task: Task
for (acceptedString in acceptedStrings) {
task = Task()
task.setTitle("Jog $acceptedString") // test at end of task. should set importance.
task.title = "Jog $acceptedString" // test at end of task. should set importance.
val tags = ArrayList<String>()
TitleParser.listHelper(tagDataDao, task, tags)
val tag = TitleParser.trimParenthesis(acceptedString)
@ -418,7 +418,7 @@ class TitleParserTest : InjectingTestCase() {
var task: Task
for (acceptedString in acceptedStrings) {
task = Task()
task.setTitle("Jog $acceptedString") // test at end of task. should set importance.
task.title = "Jog $acceptedString" // test at end of task. should set importance.
val tags = ArrayList<String>()
TitleParser.listHelper(tagDataDao, task, tags)
val tag = TitleParser.trimParenthesis(acceptedString)

@ -22,7 +22,7 @@ class SubtasksHelperTest : SubtasksTestCase() {
private fun createTask(title: String, uuid: String) {
val t = Task()
t.setTitle(title)
t.title = title
t.uuid = uuid
taskDao.createNew(t)
}

@ -46,7 +46,7 @@ class SubtasksMovingTest : SubtasksTestCase() {
private fun createTask(title: String): Task {
val task = Task()
task.setTitle(title)
task.title = title
taskDao.createNew(task)
return task
}

@ -29,7 +29,7 @@ abstract class SubtasksTestCase : InjectingTestCase() {
fun expectParentAndPosition(task: Task, parent: Task?, positionInParent: Int) {
val parentId = if (parent == null) "-1" else parent.uuid
val n = updater.findNodeForTask(task.uuid)
assertNotNull("No node found for task " + task.getTitle(), n)
assertNotNull("No node found for task " + task.title, n)
assertEquals("Parent mismatch", parentId, n.parent.uuid)
assertEquals("Position mismatch", positionInParent, n.parent.children.indexOf(n))
}

@ -14,8 +14,8 @@ open class NewSyncTestCase : InjectingTestCase() {
fun createTask(): Task {
val task = Task()
task.setTitle(SYNC_TASK_TITLE)
task.setPriority(SYNC_TASK_IMPORTANCE)
task.title = SYNC_TASK_TITLE
task.priority = SYNC_TASK_IMPORTANCE
taskDao.createNew(task)
return task
}

@ -27,12 +27,12 @@ class AppleRemindersTests {
@Test
fun readTitle() {
assertEquals("Test title", vtodo("apple/basic_no_due_date.txt").getTitle())
assertEquals("Test title", vtodo("apple/basic_no_due_date.txt").title)
}
@Test
fun readDescription() {
assertEquals("Test description", vtodo("apple/basic_no_due_date.txt").getNotes())
assertEquals("Test description", vtodo("apple/basic_no_due_date.txt").notes)
}
@Test
@ -46,7 +46,7 @@ class AppleRemindersTests {
fun readDueDate() {
assertEquals(
DateTime(2018, 4, 16, 18, 0, 1, 0).millis,
vtodo("apple/basic_due_date.txt").getDueDate() as Long)
vtodo("apple/basic_due_date.txt").dueDate)
}
@Test
@ -58,26 +58,26 @@ class AppleRemindersTests {
@Test
fun repeatDaily() {
assertEquals("RRULE:FREQ=DAILY;INTERVAL=1", vtodo("apple/repeat_daily.txt").getRecurrence())
assertEquals("RRULE:FREQ=DAILY;INTERVAL=1", vtodo("apple/repeat_daily.txt").recurrence)
}
@Test
fun noPriority() {
assertEquals(Task.Priority.NONE, vtodo("apple/priority_none.txt").getPriority() as Int)
assertEquals(Task.Priority.NONE, vtodo("apple/priority_none.txt").priority)
}
@Test
fun lowPriority() {
assertEquals(Task.Priority.LOW, vtodo("apple/priority_low.txt").getPriority() as Int)
assertEquals(Task.Priority.LOW, vtodo("apple/priority_low.txt").priority)
}
@Test
fun mediumPriority() {
assertEquals(Task.Priority.MEDIUM, vtodo("apple/priority_medium.txt").getPriority() as Int)
assertEquals(Task.Priority.MEDIUM, vtodo("apple/priority_medium.txt").priority)
}
@Test
fun highPriority() {
assertEquals(Task.Priority.HIGH, vtodo("apple/priority_high.txt").getPriority() as Int)
assertEquals(Task.Priority.HIGH, vtodo("apple/priority_high.txt").priority)
}
}

@ -27,12 +27,12 @@ class NextCloudTests {
@Test
fun readTitle() {
assertEquals("Test title", vtodo("nextcloud/basic_no_due_date.txt").getTitle())
assertEquals("Test title", vtodo("nextcloud/basic_no_due_date.txt").title)
}
@Test
fun readDescription() {
assertEquals("Test description", vtodo("nextcloud/basic_no_due_date.txt").getNotes())
assertEquals("Test description", vtodo("nextcloud/basic_no_due_date.txt").notes)
}
@Test
@ -46,56 +46,56 @@ class NextCloudTests {
fun readDueDate() {
assertEquals(
DateTime(2018, 4, 17, 17, 0, 1).millis,
vtodo("nextcloud/basic_due_date.txt").getDueDate() as Long)
vtodo("nextcloud/basic_due_date.txt").dueDate)
}
@Test
fun priorityNoStars() {
assertEquals(Task.Priority.NONE, vtodo("nextcloud/priority_no_stars.txt").getPriority() as Int)
assertEquals(Task.Priority.NONE, vtodo("nextcloud/priority_no_stars.txt").priority)
}
@Test
fun priorityOneStar() {
assertEquals(Task.Priority.LOW, vtodo("nextcloud/priority_1_star.txt").getPriority() as Int)
assertEquals(Task.Priority.LOW, vtodo("nextcloud/priority_1_star.txt").priority)
}
@Test
fun priorityTwoStars() {
assertEquals(Task.Priority.LOW, vtodo("nextcloud/priority_2_stars.txt").getPriority() as Int)
assertEquals(Task.Priority.LOW, vtodo("nextcloud/priority_2_stars.txt").priority)
}
@Test
fun priorityThreeStars() {
assertEquals(Task.Priority.LOW, vtodo("nextcloud/priority_3_stars.txt").getPriority() as Int)
assertEquals(Task.Priority.LOW, vtodo("nextcloud/priority_3_stars.txt").priority)
}
@Test
fun priorityFourStars() {
assertEquals(Task.Priority.LOW, vtodo("nextcloud/priority_4_stars.txt").getPriority() as Int)
assertEquals(Task.Priority.LOW, vtodo("nextcloud/priority_4_stars.txt").priority)
}
@Test
fun priorityFiveStars() {
assertEquals(Task.Priority.MEDIUM, vtodo("nextcloud/priority_5_stars.txt").getPriority() as Int)
assertEquals(Task.Priority.MEDIUM, vtodo("nextcloud/priority_5_stars.txt").priority)
}
@Test
fun prioritySixStars() {
assertEquals(Task.Priority.HIGH, vtodo("nextcloud/priority_6_stars.txt").getPriority() as Int)
assertEquals(Task.Priority.HIGH, vtodo("nextcloud/priority_6_stars.txt").priority)
}
@Test
fun prioritySevenStars() {
assertEquals(Task.Priority.HIGH, vtodo("nextcloud/priority_7_stars.txt").getPriority() as Int)
assertEquals(Task.Priority.HIGH, vtodo("nextcloud/priority_7_stars.txt").priority)
}
@Test
fun priorityEightStars() {
assertEquals(Task.Priority.HIGH, vtodo("nextcloud/priority_8_stars.txt").getPriority() as Int)
assertEquals(Task.Priority.HIGH, vtodo("nextcloud/priority_8_stars.txt").priority)
}
@Test
fun priorityNineStars() {
assertEquals(Task.Priority.HIGH, vtodo("nextcloud/priority_9_stars.txt").getPriority() as Int)
assertEquals(Task.Priority.HIGH, vtodo("nextcloud/priority_9_stars.txt").priority)
}
}

@ -27,63 +27,63 @@ class ThunderbirdTests {
@Test
fun readTitle() {
assertEquals("Test title", vtodo("thunderbird/basic_no_due_date.txt").getTitle())
assertEquals("Test title", vtodo("thunderbird/basic_no_due_date.txt").title)
}
@Test
fun readDescription() {
assertEquals("Test description", vtodo("thunderbird/basic_no_due_date.txt").getNotes())
assertEquals("Test description", vtodo("thunderbird/basic_no_due_date.txt").notes)
}
@Test
fun readCreationDate() {
assertEquals(
DateTime(2018, 4, 17, 11, 31, 52).millis,
vtodo("thunderbird/basic_no_due_date.txt").creationDate as Long)
vtodo("thunderbird/basic_no_due_date.txt").creationDate)
}
@Test
fun readDueDate() {
assertEquals(
DateTime(2018, 4, 17, 14, 0, 1).millis,
vtodo("thunderbird/basic_due_date.txt").getDueDate() as Long)
vtodo("thunderbird/basic_due_date.txt").dueDate)
}
@Test
fun completed() {
assertEquals(
DateTime(2018, 4, 17, 16, 24, 29).millis,
vtodo("thunderbird/basic_completed.txt").completionDate as Long)
vtodo("thunderbird/basic_completed.txt").completionDate)
}
@Test
fun repeatDaily() {
assertEquals(
"RRULE:FREQ=DAILY;INTERVAL=1", vtodo("thunderbird/repeat_daily.txt").getRecurrence())
"RRULE:FREQ=DAILY;INTERVAL=1", vtodo("thunderbird/repeat_daily.txt").recurrence)
}
@Test
fun priorityNotSet() {
assertEquals(Task.Priority.NONE, vtodo("thunderbird/basic_no_due_date.txt").getPriority() as Int)
assertEquals(Task.Priority.NONE, vtodo("thunderbird/basic_no_due_date.txt").priority)
}
@Test
fun priorityNotSpecified() {
assertEquals(Task.Priority.NONE, vtodo("thunderbird/priority_unspecified.txt").getPriority() as Int)
assertEquals(Task.Priority.NONE, vtodo("thunderbird/priority_unspecified.txt").priority)
}
@Test
fun lowPriority() {
assertEquals(Task.Priority.LOW, vtodo("thunderbird/priority_low.txt").getPriority() as Int)
assertEquals(Task.Priority.LOW, vtodo("thunderbird/priority_low.txt").priority)
}
@Test
fun normalPriority() {
assertEquals(Task.Priority.MEDIUM, vtodo("thunderbird/priority_normal.txt").getPriority() as Int)
assertEquals(Task.Priority.MEDIUM, vtodo("thunderbird/priority_normal.txt").priority)
}
@Test
fun highPriority() {
assertEquals(Task.Priority.HIGH, vtodo("thunderbird/priority_high.txt").getPriority() as Int)
assertEquals(Task.Priority.HIGH, vtodo("thunderbird/priority_high.txt").priority)
}
}

@ -36,8 +36,8 @@ class CaldavDaoTests : InjectingTestCase() {
tagDataDao.createNew(two)
tagDao.insert(newTag(with(TASK, task), with(TAGDATA, one)))
tagDao.insert(newTag(with(TASK, task), with(TAGDATA, two)))
caldavDao.insert(CaldavTask(task.getId(), "calendar"))
assertEquals(listOf(task.getId()), caldavDao.getTasksWithTags())
caldavDao.insert(CaldavTask(task.id!!, "calendar"))
assertEquals(listOf(task.id!!), caldavDao.getTasksWithTags())
}
@Test
@ -55,7 +55,7 @@ class CaldavDaoTests : InjectingTestCase() {
val task = newTask(with(ID, 1L))
taskDao.createNew(task)
tagDataDao.createNew(newTagData())
caldavDao.insert(CaldavTask(task.getId(), "calendar"))
caldavDao.insert(CaldavTask(task.id!!, "calendar"))
assertTrue(caldavDao.getTasksWithTags().isEmpty())
}

@ -33,20 +33,20 @@ class DeletionDaoTests : InjectingTestCase() {
fun markDeletedUpdatesModificationTime() {
var task = newTask(MakeItEasy.with(CREATION_TIME, DateTime().minusMinutes(1)))
taskDao.createNew(task)
deletionDao.markDeleted(listOf(task.getId()))
task = taskDao.fetch(task.getId())!!
assertTrue(task.modificationDate > task.creationDate)
assertTrue(task.modificationDate < DateTimeUtils.currentTimeMillis())
deletionDao.markDeleted(listOf(task.id!!))
task = taskDao.fetch(task.id!!)!!
assertTrue(task.modificationDate!! > task.creationDate!!)
assertTrue(task.modificationDate!! < DateTimeUtils.currentTimeMillis())
}
@Test
fun markDeletedUpdatesDeletionTime() {
var task = newTask(MakeItEasy.with(CREATION_TIME, DateTime().minusMinutes(1)))
taskDao.createNew(task)
deletionDao.markDeleted(listOf(task.getId()))
task = taskDao.fetch(task.getId())!!
assertTrue(task.deletionDate > task.creationDate)
assertTrue(task.deletionDate < DateTimeUtils.currentTimeMillis())
deletionDao.markDeleted(listOf(task.id!!))
task = taskDao.fetch(task.id!!)!!
assertTrue(task.deletionDate!! > task.creationDate!!)
assertTrue(task.deletionDate!! < DateTimeUtils.currentTimeMillis())
}
override fun inject(component: TestComponent) = component.inject(this)

@ -164,7 +164,7 @@ class GoogleTaskDaoTests : InjectingTestCase() {
private fun insert(googleTask: GoogleTask, top: Boolean) {
val task = newTask()
taskDao.createNew(task)
googleTask.task = task.getId()
googleTask.task = task.id!!
googleTaskDao.insertAndShift(googleTask, top)
}

@ -73,7 +73,7 @@ class TagDataDaoTest : InjectingTestCase() {
tagDataDao.createNew(tagTwo)
tagDao.insert(newTag(with(TAGDATA, tagOne), with(TASK, taskOne)))
tagDao.insert(newTag(with(TAGDATA, tagTwo), with(TASK, taskTwo)))
assertEquals(listOf(tagOne), tagDataDao.getTagDataForTask(taskOne.getId()))
assertEquals(listOf(tagOne), tagDataDao.getTagDataForTask(taskOne.id!!))
}
@Test

@ -18,29 +18,29 @@ class GoogleTaskSynchronizerTest {
@Test
fun testMergeDate() {
val local = newTask(with(DUE_DATE, DateTime(2016, 3, 12)))
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).getDueDate(), local)
assertEquals(DateTime(2016, 3, 11, 12, 0).millis, local.getDueDate().toLong())
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate!!, local)
assertEquals(DateTime(2016, 3, 11, 12, 0).millis, local.dueDate)
}
@Test
fun testMergeTime() {
val local = newTask(with(DUE_TIME, DateTime(2016, 3, 11, 13, 30)))
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).getDueDate(), local)
assertEquals(DateTime(2016, 3, 11, 13, 30, 1).millis, local.getDueDate().toLong())
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate!!, local)
assertEquals(DateTime(2016, 3, 11, 13, 30, 1).millis, local.dueDate)
}
@Test
fun testDueDateAdjustHideBackwards() {
val local = newTask(with(DUE_DATE, DateTime(2016, 3, 12)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE))
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).getDueDate(), local)
assertEquals(DateTime(2016, 3, 11).millis, local.getHideUntil().toLong())
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate!!, local)
assertEquals(DateTime(2016, 3, 11).millis, local.hideUntil)
}
@Test
fun testDueDateAdjustHideForwards() {
val local = newTask(with(DUE_DATE, DateTime(2016, 3, 12)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE))
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 14))).getDueDate(), local)
assertEquals(DateTime(2016, 3, 14).millis, local.getHideUntil().toLong())
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 14))).dueDate!!, local)
assertEquals(DateTime(2016, 3, 14).millis, local.hideUntil)
}
@Test
@ -48,9 +48,9 @@ class GoogleTaskSynchronizerTest {
val local = newTask(
with(DUE_TIME, DateTime(2016, 3, 12, 13, 30)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).getDueDate(), local)
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate!!, local)
assertEquals(
DateTime(2016, 3, 11, 13, 30, 1).millis, local.getHideUntil().toLong())
DateTime(2016, 3, 11, 13, 30, 1).millis, local.hideUntil)
}
@Test
@ -58,16 +58,16 @@ class GoogleTaskSynchronizerTest {
val local = newTask(
with(DUE_TIME, DateTime(2016, 3, 12, 13, 30)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 14))).getDueDate(), local)
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 14))).dueDate!!, local)
assertEquals(
DateTime(2016, 3, 14, 13, 30, 1).millis, local.getHideUntil().toLong())
DateTime(2016, 3, 14, 13, 30, 1).millis, local.hideUntil)
}
@Test
fun testDueDateClearHide() {
val local = newTask(with(DUE_DATE, DateTime(2016, 3, 12)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE))
GoogleTaskSynchronizer.mergeDates(newTask().getDueDate(), local)
assertEquals(0, local.getHideUntil().toLong())
GoogleTaskSynchronizer.mergeDates(newTask().dueDate!!, local)
assertEquals(0L, local.hideUntil)
}
@Test
@ -75,8 +75,8 @@ class GoogleTaskSynchronizerTest {
val local = newTask(
with(DUE_TIME, DateTime(2016, 3, 12, 13, 30)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))
GoogleTaskSynchronizer.mergeDates(newTask().getDueDate(), local)
assertEquals(0, local.getHideUntil().toLong())
GoogleTaskSynchronizer.mergeDates(newTask().dueDate!!, local)
assertEquals(0L, local.hideUntil)
}
@Test

@ -51,7 +51,7 @@ class BackupServiceTests : InjectingTestCase() {
// make a temporary task
val task = Task()
task.setTitle("helicopter")
task.title = "helicopter"
taskDao.createNew(task)
}

@ -18,8 +18,8 @@ object TagMaker {
private val instantiator = Instantiator { lookup: PropertyLookup<Tag> ->
val tag = Tag()
val task = lookup.valueOf(TASK, null as Task?)!!
tag.task = task.getId()
tag.setTaskUid(task.uuid)
tag.task = task.id!!
tag.setTaskUid(task.uuid!!)
tag.tagUid = lookup.valueOf(TAGUID, null as String?)
val tagData = lookup.valueOf(TAGDATA, null as TagData?)
if (tagData != null) {

@ -34,23 +34,23 @@ object TaskMaker {
val task = Task()
val title = lookup.valueOf(TITLE, null as String?)
if (!Strings.isNullOrEmpty(title)) {
task.setTitle(title)
task.title = title
}
val id = lookup.valueOf(ID, Task.NO_ID)
if (id != Task.NO_ID) {
task.setId(id)
task.id = id
}
val priority = lookup.valueOf(PRIORITY, -1)
if (priority >= 0) {
task.setPriority(priority)
task.priority = priority
}
val dueDate = lookup.valueOf(DUE_DATE, null as DateTime?)
if (dueDate != null) {
task.setDueDate(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, dueDate.millis))
task.dueDate = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, dueDate.millis)
}
val dueTime = lookup.valueOf(DUE_TIME, null as DateTime?)
if (dueTime != null) {
task.setDueDate(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, dueTime.millis))
task.dueDate = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, dueTime.millis)
}
val completionTime = lookup.valueOf(COMPLETION_TIME, null as DateTime?)
if (completionTime != null) {
@ -66,7 +66,7 @@ object TaskMaker {
}
val hideType = lookup.valueOf(HIDE_TYPE, -1)
if (hideType >= 0) {
task.setHideUntil(task.createHideUntil(hideType, 0))
task.hideUntil = task.createHideUntil(hideType, 0)
}
val reminderFlags = lookup.valueOf(REMINDERS, -1)
if (reminderFlags >= 0) {
@ -86,7 +86,7 @@ object TaskMaker {
}
val creationTime = lookup.valueOf(CREATION_TIME, DateTimeUtils.newDateTime())
task.creationDate = creationTime.millis
task.setParent(lookup.valueOf(PARENT, 0L))
task.parent = lookup.valueOf(PARENT, 0L)
task
}

@ -225,7 +225,7 @@ abstract class TaskDao(private val database: Database) {
* success.
*/
@JvmOverloads
fun save(task: Task, original: Task? = fetch(task.getId())) {
fun save(task: Task, original: Task? = fetch(task.id!!)) {
if (!task.insignificantChange(original)) {
task.modificationDate = DateUtilities.now()
}
@ -239,16 +239,17 @@ abstract class TaskDao(private val database: Database) {
@Update
abstract fun update(task: Task): Int
fun createNew(task: Task) {
task.id = null
if (task.created == 0L) {
task.created = DateUtilities.now()
if (task.creationDate == 0L) {
task.creationDate = DateUtilities.now()
}
if (Task.isUuidEmpty(task.remoteId)) {
if (Task.isUuidEmpty(task.remoteId!!)) {
task.remoteId = UUIDHelper.newUUID()
}
val insert = insert(task)
task.setId(insert)
task.id = insert
}
@Query("SELECT * FROM tasks "

@ -1,918 +0,0 @@
/*
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.data;
import static com.todoroo.astrid.data.SyncFlags.SUPPRESS_SYNC;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import static org.tasks.Strings.isNullOrEmpty;
import static org.tasks.date.DateTimeUtils.newDateTime;
import android.content.ContentValues;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.IntDef;
import androidx.core.os.ParcelCompat;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import com.google.ical.values.RRule;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.sql.Field;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.TaskDao;
import java.lang.annotation.Retention;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;
import org.tasks.backup.XmlReader;
import org.tasks.data.Tag;
import org.tasks.time.DateTime;
import timber.log.Timber;
@Entity(
tableName = "tasks",
indices = {
@Index(name = "t_rid", value = "remoteId", unique = true),
@Index(
name = "active_and_visible",
value = {"completed", "deleted", "hideUntil"})
})
public class Task implements Parcelable {
// --- table and uri
/** table for this model */
public static final Table TABLE = new Table("tasks");
public static final Field FIELDS = Field.field("tasks.*");
public static final long NO_ID = 0;
// --- properties
public static final LongProperty ID = new LongProperty(TABLE, "_id");
public static final StringProperty TITLE = new StringProperty(TABLE, "title");
public static final IntegerProperty IMPORTANCE = new IntegerProperty(TABLE, "importance");
public static final LongProperty DUE_DATE = new LongProperty(TABLE, "dueDate");
public static final LongProperty HIDE_UNTIL = new LongProperty(TABLE, "hideUntil");
public static final LongProperty MODIFICATION_DATE = new LongProperty(TABLE, "modified");
public static final LongProperty CREATION_DATE = new LongProperty(TABLE, "created");
public static final LongProperty COMPLETION_DATE = new LongProperty(TABLE, "completed");
public static final LongProperty DELETION_DATE = new LongProperty(TABLE, "deleted");
public static final StringProperty NOTES = new StringProperty(TABLE, "notes");
public static final LongProperty TIMER_START = new LongProperty(TABLE, "timerStart");
public static final LongProperty PARENT = new LongProperty(TABLE, "parent");
/** constant value for no uuid */
public static final String NO_UUID = "0"; // $NON-NLS-1$
public static final StringProperty UUID = new StringProperty(TABLE, "remoteId");
/** whether to send a reminder at deadline */
public static final int NOTIFY_AT_DEADLINE = 1 << 1;
/** whether to send reminders while task is overdue */
public static final int NOTIFY_AFTER_DEADLINE = 1 << 2;
/** reminder mode non-stop */
public static final int NOTIFY_MODE_NONSTOP = 1 << 3;
/** reminder mode five times (exclusive with non-stop) */
public static final int NOTIFY_MODE_FIVE = 1 << 4;
public static final Parcelable.Creator<Task> CREATOR =
new Parcelable.Creator<Task>() {
@Override
public Task createFromParcel(Parcel source) {
return new Task(source);
}
@Override
public Task[] newArray(int size) {
return new Task[size];
}
};
/** urgency array index -> significance */
public static final int URGENCY_NONE = 0;
public static final int URGENCY_SPECIFIC_DAY = 7;
public static final int URGENCY_SPECIFIC_DAY_TIME = 8;
/** hide until array index -> significance */
public static final int HIDE_UNTIL_NONE = 0;
public static final int HIDE_UNTIL_DUE = 1;
public static final int HIDE_UNTIL_DAY_BEFORE = 2;
public static final int HIDE_UNTIL_WEEK_BEFORE = 3;
public static final int HIDE_UNTIL_SPECIFIC_DAY = 4;
// --- for astrid.com
public static final int HIDE_UNTIL_SPECIFIC_DAY_TIME = 5;
public static final int HIDE_UNTIL_DUE_TIME = 6;
static final int URGENCY_TODAY = 1;
static final int URGENCY_TOMORROW = 2;
// --- notification flags
static final int URGENCY_DAY_AFTER = 3;
static final int URGENCY_NEXT_WEEK = 4;
static final int URGENCY_IN_TWO_WEEKS = 5;
/** ID */
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "_id")
public transient Long id = NO_ID;
// --- importance settings (note: importance > 3 are supported via plugin)
/** Name of Task */
@ColumnInfo(name = "title")
public String title = "";
@ColumnInfo(name = "importance")
public Integer priority = Priority.NONE;
/** Unixtime Task is due, 0 if not set */
@ColumnInfo(name = "dueDate")
public Long dueDate = 0L;
/** Unixtime Task should be hidden until, 0 if not set */
@ColumnInfo(name = "hideUntil")
public Long hideUntil = 0L;
/** Unixtime Task was created */
@ColumnInfo(name = "created")
public Long created = 0L;
/** Unixtime Task was last touched */
@ColumnInfo(name = "modified")
public Long modified = 0L;
/** Unixtime Task was completed. 0 means active */
@ColumnInfo(name = "completed")
public Long completed = 0L;
/** Unixtime Task was deleted. 0 means not deleted */
@ColumnInfo(name = "deleted")
public Long deleted = 0L;
// --- data access boilerplate
@ColumnInfo(name = "notes")
public String notes = "";
@ColumnInfo(name = "estimatedSeconds")
public Integer estimatedSeconds = 0;
@ColumnInfo(name = "elapsedSeconds")
public Integer elapsedSeconds = 0;
@ColumnInfo(name = "timerStart")
public Long timerStart = 0L;
/** Flags for when to send reminders */
@ColumnInfo(name = "notificationFlags")
public Integer notificationFlags = 0;
/** Reminder period, in milliseconds. 0 means disabled */
@ColumnInfo(name = "notifications")
public Long notifications = 0L;
// --- parcelable helpers
/** Unixtime the last reminder was triggered */
@ColumnInfo(name = "lastNotified")
public Long lastNotified = 0L;
// --- data access methods
/** Unixtime snooze is set (0 -> no snooze) */
@ColumnInfo(name = "snoozeTime")
public Long snoozeTime = 0L;
@ColumnInfo(name = "recurrence")
public String recurrence = "";
@ColumnInfo(name = "repeatUntil")
public Long repeatUntil = 0L;
@ColumnInfo(name = "calendarUri")
public String calendarUri = "";
/** Remote id */
@ColumnInfo(name = "remoteId")
public String remoteId = NO_UUID;
@ColumnInfo(name = "collapsed")
public boolean collapsed;
@ColumnInfo(name = "parent")
public transient long parent;
@ColumnInfo(name = "parent_uuid")
public String parentUuid;
// --- due and hide until date management
@Ignore private transient HashMap<String, Object> transitoryData = null;
public Task() {}
@Ignore
public Task(XmlReader reader) {
calendarUri = reader.readString("calendarUri");
completed = reader.readLong("completed");
created = reader.readLong("created");
deleted = reader.readLong("deleted");
dueDate = reader.readLong("dueDate");
elapsedSeconds = reader.readInteger("elapsedSeconds");
estimatedSeconds = reader.readInteger("estimatedSeconds");
hideUntil = reader.readLong("hideUntil");
priority = reader.readInteger("importance");
modified = reader.readLong("modified");
notes = reader.readString("notes");
recurrence = reader.readString("recurrence");
notificationFlags = reader.readInteger("notificationFlags");
lastNotified = reader.readLong("lastNotified");
notifications = reader.readLong("notifications");
snoozeTime = reader.readLong("snoozeTime");
repeatUntil = reader.readLong("repeatUntil");
timerStart = reader.readLong("timerStart");
title = reader.readString("title");
remoteId = reader.readString("remoteId");
}
@Ignore
public Task(Parcel parcel) {
calendarUri = parcel.readString();
completed = parcel.readLong();
created = parcel.readLong();
deleted = parcel.readLong();
dueDate = parcel.readLong();
elapsedSeconds = parcel.readInt();
estimatedSeconds = parcel.readInt();
hideUntil = parcel.readLong();
id = parcel.readLong();
priority = parcel.readInt();
modified = parcel.readLong();
notes = parcel.readString();
recurrence = parcel.readString();
notificationFlags = parcel.readInt();
lastNotified = parcel.readLong();
notifications = parcel.readLong();
snoozeTime = parcel.readLong();
repeatUntil = parcel.readLong();
timerStart = parcel.readLong();
title = parcel.readString();
remoteId = parcel.readString();
transitoryData = parcel.readHashMap(ContentValues.class.getClassLoader());
collapsed = ParcelCompat.readBoolean(parcel);
parent = parcel.readLong();
parentUuid = parcel.readString();
}
/**
* Creates due date for this task. If this due date has no time associated, we move it to the last
* millisecond of the day.
*
* @param setting one of the URGENCY_* constants
* @param customDate if specific day or day & time is set, this value
*/
public static long createDueDate(int setting, long customDate) {
long date;
switch (setting) {
case URGENCY_NONE:
date = 0;
break;
case URGENCY_TODAY:
date = DateUtilities.now();
break;
case URGENCY_TOMORROW:
date = DateUtilities.now() + DateUtilities.ONE_DAY;
break;
case URGENCY_DAY_AFTER:
date = DateUtilities.now() + 2 * DateUtilities.ONE_DAY;
break;
case URGENCY_NEXT_WEEK:
date = DateUtilities.now() + DateUtilities.ONE_WEEK;
break;
case URGENCY_IN_TWO_WEEKS:
date = DateUtilities.now() + 2 * DateUtilities.ONE_WEEK;
break;
case URGENCY_SPECIFIC_DAY:
case URGENCY_SPECIFIC_DAY_TIME:
date = customDate;
break;
default:
throw new IllegalArgumentException("Unknown setting " + setting);
}
if (date <= 0) {
return date;
}
DateTime dueDate = newDateTime(date).withMillisOfSecond(0);
if (setting != URGENCY_SPECIFIC_DAY_TIME) {
dueDate =
dueDate
.withHourOfDay(12)
.withMinuteOfHour(0)
.withSecondOfMinute(0); // Seconds == 0 means no due time
} else {
dueDate = dueDate.withSecondOfMinute(1); // Seconds > 0 means due time exists
}
return dueDate.getMillis();
}
/** Checks whether provided due date has a due time or only a date */
public static boolean hasDueTime(long dueDate) {
return dueDate > 0 && (dueDate % 60000 > 0);
}
public static boolean isValidUuid(String uuid) {
try {
long value = Long.parseLong(uuid);
return value > 0;
} catch (NumberFormatException e) {
Timber.e(e);
return isUuidEmpty(uuid);
}
}
public static boolean isUuidEmpty(String uuid) {
return NO_UUID.equals(uuid) || isNullOrEmpty(uuid);
}
public long getId() {
return id == null ? NO_ID : id;
}
public void setId(long id) {
this.id = id;
}
public String getUuid() {
return isNullOrEmpty(remoteId) ? NO_UUID : remoteId;
}
public void setUuid(String uuid) {
remoteId = uuid;
}
/** Checks whether task is done. Requires COMPLETION_DATE */
public boolean isCompleted() {
return completed > 0;
}
/** Checks whether task is deleted. Will return false if DELETION_DATE not read */
public boolean isDeleted() {
return deleted > 0;
}
/** Checks whether task is hidden. Requires HIDDEN_UNTIL */
public boolean isHidden() {
return hideUntil > DateUtilities.now();
}
public boolean hasHideUntilDate() {
return hideUntil > 0;
}
/** Checks whether task is done. Requires DUE_DATE */
public boolean hasDueDate() {
return dueDate > 0;
}
/**
* Create hide until for this task.
*
* @param setting one of the HIDE_UNTIL_* constants
* @param customDate if specific day is set, this value
*/
public long createHideUntil(int setting, long customDate) {
long date;
switch (setting) {
case HIDE_UNTIL_NONE:
return 0;
case HIDE_UNTIL_DUE:
case HIDE_UNTIL_DUE_TIME:
date = dueDate;
break;
case HIDE_UNTIL_DAY_BEFORE:
date = dueDate - DateUtilities.ONE_DAY;
break;
case HIDE_UNTIL_WEEK_BEFORE:
date = dueDate - DateUtilities.ONE_WEEK;
break;
case HIDE_UNTIL_SPECIFIC_DAY:
case HIDE_UNTIL_SPECIFIC_DAY_TIME:
date = customDate;
break;
default:
throw new IllegalArgumentException("Unknown setting " + setting);
}
if (date <= 0) {
return date;
}
DateTime hideUntil = newDateTime(date).withMillisOfSecond(0); // get rid of millis
if (setting != HIDE_UNTIL_SPECIFIC_DAY_TIME && setting != HIDE_UNTIL_DUE_TIME) {
hideUntil = hideUntil.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
} else {
hideUntil = hideUntil.withSecondOfMinute(1);
}
return hideUntil.getMillis();
}
/** Checks whether this due date has a due time or only a date */
public boolean hasDueTime() {
return hasDueDate() && hasDueTime(getDueDate());
}
public boolean isOverdue() {
long dueDate = getDueDate();
long compareTo = hasDueTime() ? DateUtilities.now() : newDateTime().startOfDay().getMillis();
return dueDate < compareTo && !isCompleted();
}
public boolean repeatAfterCompletion() {
return getRecurrence().contains("FROM=COMPLETION");
}
public String sanitizedRecurrence() {
return getRecurrenceWithoutFrom().replaceAll("BYDAY=;", ""); // $NON-NLS-1$//$NON-NLS-2$
}
public String getRecurrenceWithoutFrom() {
return getRecurrence().replaceAll(";?FROM=[^;]*", "");
}
public Long getDueDate() {
return dueDate;
}
public void setDueDate(Long dueDate) {
this.dueDate = dueDate;
}
public void setDueDateAdjustingHideUntil(Long newDueDate) {
if (dueDate > 0) {
if (hideUntil > 0) {
setHideUntil(newDueDate > 0 ? hideUntil + newDueDate - dueDate : 0);
}
}
setDueDate(newDueDate);
}
public boolean isRecurring() {
return !isNullOrEmpty(recurrence);
}
public String getRecurrence() {
return recurrence;
}
public void setRecurrence(String recurrence) {
this.recurrence = recurrence;
}
public void setRecurrence(RRule rrule, boolean afterCompletion) {
setRecurrence(rrule.toIcal() + (afterCompletion ? ";FROM=COMPLETION" : ""));
}
public Long getCreationDate() {
return created;
}
public void setCreationDate(Long creationDate) {
created = creationDate;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Long getDeletionDate() {
return deleted;
}
public void setDeletionDate(Long deletionDate) {
deleted = deletionDate;
}
public Long getHideUntil() {
return hideUntil;
}
public void setHideUntil(Long hideUntil) {
this.hideUntil = hideUntil;
}
public Long getReminderLast() {
return lastNotified;
}
public void setReminderLast(Long reminderLast) {
lastNotified = reminderLast;
}
public Long getReminderSnooze() {
return snoozeTime;
}
public void setReminderSnooze(Long reminderSnooze) {
snoozeTime = reminderSnooze;
}
public Integer getElapsedSeconds() {
return elapsedSeconds;
}
public void setElapsedSeconds(Integer elapsedSeconds) {
this.elapsedSeconds = elapsedSeconds;
}
public Long getTimerStart() {
return timerStart;
}
public void setTimerStart(Long timerStart) {
this.timerStart = timerStart;
}
public Long getRepeatUntil() {
return repeatUntil;
}
public void setRepeatUntil(Long repeatUntil) {
this.repeatUntil = repeatUntil;
}
public String getCalendarURI() {
return calendarUri;
}
public @Priority Integer getPriority() {
return priority;
}
public void setPriority(@Priority Integer priority) {
this.priority = priority;
}
public Long getCompletionDate() {
return completed;
}
public void setCompletionDate(Long completionDate) {
completed = completionDate;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public boolean hasNotes() {
return !isNullOrEmpty(notes);
}
public Long getModificationDate() {
return modified;
}
public void setModificationDate(Long modificationDate) {
modified = modificationDate;
}
public Integer getReminderFlags() {
return notificationFlags;
}
public void setReminderFlags(Integer reminderFlags) {
notificationFlags = reminderFlags;
}
public Long getReminderPeriod() {
return notifications;
}
public void setReminderPeriod(Long reminderPeriod) {
notifications = reminderPeriod;
}
public Integer getEstimatedSeconds() {
return estimatedSeconds;
}
public void setEstimatedSeconds(Integer estimatedSeconds) {
this.estimatedSeconds = estimatedSeconds;
}
public void setCalendarUri(String calendarUri) {
this.calendarUri = calendarUri;
}
public long getParent() {
return parent;
}
public void setParent(long parent) {
this.parent = parent;
}
public String getParentUuid() {
return parentUuid;
}
public void setParentUuid(String parentUuid) {
this.parentUuid = parentUuid;
}
public boolean isNotifyModeNonstop() {
return isReminderFlagSet(Task.NOTIFY_MODE_NONSTOP);
}
public boolean isNotifyModeFive() {
return isReminderFlagSet(Task.NOTIFY_MODE_FIVE);
}
public boolean isNotifyAfterDeadline() {
return isReminderFlagSet(Task.NOTIFY_AFTER_DEADLINE);
}
public boolean isNotifyAtDeadline() {
return isReminderFlagSet(Task.NOTIFY_AT_DEADLINE);
}
private boolean isReminderFlagSet(int flag) {
return (notificationFlags & flag) > 0;
}
public boolean isNew() {
return getId() == NO_ID;
}
public boolean isCollapsed() {
return collapsed;
}
/** {@inheritDoc} */
@Override
public int describeContents() {
return 0;
}
/** {@inheritDoc} */
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(calendarUri);
dest.writeLong(completed);
dest.writeLong(created);
dest.writeLong(deleted);
dest.writeLong(dueDate);
dest.writeInt(elapsedSeconds);
dest.writeInt(estimatedSeconds);
dest.writeLong(hideUntil);
dest.writeLong(id);
dest.writeInt(priority);
dest.writeLong(modified);
dest.writeString(notes);
dest.writeString(recurrence);
dest.writeInt(notificationFlags);
dest.writeLong(lastNotified);
dest.writeLong(notifications);
dest.writeLong(snoozeTime);
dest.writeLong(repeatUntil);
dest.writeLong(timerStart);
dest.writeString(title);
dest.writeString(remoteId);
dest.writeMap(transitoryData);
ParcelCompat.writeBoolean(dest, collapsed);
dest.writeLong(parent);
dest.writeString(parentUuid);
}
@Override
public String toString() {
return "Task{"
+ "id="
+ id
+ ", title='"
+ title
+ '\''
+ ", priority="
+ priority
+ ", dueDate="
+ dueDate
+ ", hideUntil="
+ hideUntil
+ ", created="
+ created
+ ", modified="
+ modified
+ ", completed="
+ completed
+ ", deleted="
+ deleted
+ ", notes='"
+ notes
+ '\''
+ ", estimatedSeconds="
+ estimatedSeconds
+ ", elapsedSeconds="
+ elapsedSeconds
+ ", timerStart="
+ timerStart
+ ", notificationFlags="
+ notificationFlags
+ ", notifications="
+ notifications
+ ", lastNotified="
+ lastNotified
+ ", snoozeTime="
+ snoozeTime
+ ", recurrence='"
+ recurrence
+ '\''
+ ", repeatUntil="
+ repeatUntil
+ ", calendarUri='"
+ calendarUri
+ '\''
+ ", remoteId='"
+ remoteId
+ '\''
+ ", collapsed="
+ collapsed
+ ", parent="
+ parent
+ ", parentUuid='"
+ parentUuid
+ '\''
+ ", transitoryData="
+ transitoryData
+ '}';
}
public boolean insignificantChange(Task task) {
if (this == task) {
return true;
}
if (task == null) {
return false;
}
return Objects.equals(id, task.id)
&& Objects.equals(title, task.title)
&& Objects.equals(priority, task.priority)
&& Objects.equals(dueDate, task.dueDate)
&& Objects.equals(hideUntil, task.hideUntil)
&& Objects.equals(created, task.created)
&& Objects.equals(modified, task.modified)
&& Objects.equals(completed, task.completed)
&& Objects.equals(deleted, task.deleted)
&& Objects.equals(notes, task.notes)
&& Objects.equals(estimatedSeconds, task.estimatedSeconds)
&& Objects.equals(elapsedSeconds, task.elapsedSeconds)
&& Objects.equals(notificationFlags, task.notificationFlags)
&& Objects.equals(notifications, task.notifications)
&& Objects.equals(recurrence, task.recurrence)
&& Objects.equals(repeatUntil, task.repeatUntil)
&& Objects.equals(calendarUri, task.calendarUri)
&& parent == task.parent
&& Objects.equals(parentUuid, task.parentUuid)
&& Objects.equals(remoteId, task.remoteId);
}
public boolean googleTaskUpToDate(Task original) {
if (this == original) {
return true;
}
if (original == null) {
return false;
}
return Objects.equals(title, original.title)
&& Objects.equals(dueDate, original.dueDate)
&& Objects.equals(completed, original.completed)
&& Objects.equals(deleted, original.deleted)
&& parent == original.parent
&& Objects.equals(notes, original.notes);
}
public boolean caldavUpToDate(Task original) {
if (this == original) {
return true;
}
if (original == null) {
return false;
}
return Objects.equals(title, original.title)
&& Objects.equals(priority, original.priority)
&& Objects.equals(dueDate, original.dueDate)
&& Objects.equals(completed, original.completed)
&& Objects.equals(deleted, original.deleted)
&& Objects.equals(notes, original.notes)
&& Objects.equals(recurrence, original.recurrence)
&& parent == original.parent
&& Objects.equals(repeatUntil, original.repeatUntil);
}
public boolean isSaved() {
return getId() != NO_ID;
}
public synchronized void suppressSync() {
putTransitory(SUPPRESS_SYNC, true);
}
public synchronized void suppressRefresh() {
putTransitory(TaskDao.TRANS_SUPPRESS_REFRESH, true);
}
public synchronized void putTransitory(String key, Object value) {
if (transitoryData == null) {
transitoryData = new HashMap<>();
}
transitoryData.put(key, value);
}
public ArrayList<String> getTags() {
Object tags = getTransitory(Tag.KEY);
return tags == null ? new ArrayList<>() : (ArrayList<String>) tags;
}
public void setTags(ArrayList<String> tags) {
if (transitoryData == null) {
transitoryData = new HashMap<>();
}
transitoryData.put(Tag.KEY, tags);
}
public boolean hasTransitory(String key) {
return transitoryData != null && transitoryData.containsKey(key);
}
public <T> T getTransitory(String key) {
if (transitoryData == null) {
return null;
}
return (T) transitoryData.get(key);
}
// --- Convenience wrappers for using transitories as flags
public boolean checkTransitory(String flag) {
Object trans = getTransitory(flag);
return trans != null;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Task)) {
return false;
}
Task task = (Task) o;
return collapsed == task.collapsed
&& parent == task.parent
&& Objects.equals(id, task.id)
&& Objects.equals(title, task.title)
&& Objects.equals(priority, task.priority)
&& Objects.equals(dueDate, task.dueDate)
&& Objects.equals(hideUntil, task.hideUntil)
&& Objects.equals(created, task.created)
&& Objects.equals(modified, task.modified)
&& Objects.equals(completed, task.completed)
&& Objects.equals(deleted, task.deleted)
&& Objects.equals(notes, task.notes)
&& Objects.equals(estimatedSeconds, task.estimatedSeconds)
&& Objects.equals(elapsedSeconds, task.elapsedSeconds)
&& Objects.equals(timerStart, task.timerStart)
&& Objects.equals(notificationFlags, task.notificationFlags)
&& Objects.equals(notifications, task.notifications)
&& Objects.equals(lastNotified, task.lastNotified)
&& Objects.equals(snoozeTime, task.snoozeTime)
&& Objects.equals(recurrence, task.recurrence)
&& Objects.equals(repeatUntil, task.repeatUntil)
&& Objects.equals(calendarUri, task.calendarUri)
&& Objects.equals(remoteId, task.remoteId)
&& Objects.equals(parentUuid, task.parentUuid)
&& Objects.equals(transitoryData, task.transitoryData);
}
@Override
public int hashCode() {
return Objects
.hash(id, title, priority, dueDate, hideUntil, created, modified, completed, deleted, notes,
estimatedSeconds, elapsedSeconds, timerStart, notificationFlags, notifications,
lastNotified, snoozeTime, recurrence, repeatUntil, calendarUri, remoteId, collapsed,
parent, parentUuid, transitoryData);
}
@Retention(SOURCE)
@IntDef({Priority.HIGH, Priority.MEDIUM, Priority.LOW, Priority.NONE})
public @interface Priority {
int HIGH = 0;
int MEDIUM = 1;
int LOW = 2;
int NONE = 3;
}
}

@ -0,0 +1,618 @@
package com.todoroo.astrid.data
import android.content.ContentValues
import android.os.Parcel
import android.os.Parcelable
import androidx.annotation.IntDef
import androidx.core.os.ParcelCompat
import androidx.room.*
import com.google.ical.values.RRule
import com.todoroo.andlib.data.Property.*
import com.todoroo.andlib.data.Table
import com.todoroo.andlib.sql.Field
import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.dao.TaskDao
import org.tasks.Strings
import org.tasks.backup.XmlReader
import org.tasks.data.Tag
import org.tasks.date.DateTimeUtils
import timber.log.Timber
import java.util.*
@Entity(
tableName = "tasks",
indices = [
Index(name = "t_rid", value = ["remoteId"], unique = true),
Index(name = "active_and_visible", value = ["completed", "deleted", "hideUntil"])])
open class Task : Parcelable {
/** ID */
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "_id")
@Transient
var id: Long? = NO_ID
/** Name of Task */
@ColumnInfo(name = "title")
var title: String? = ""
@ColumnInfo(name = "importance")
var priority: Int? = Priority.NONE
/** Unixtime Task is due, 0 if not set */
@ColumnInfo(name = "dueDate")
var dueDate: Long? = 0L
/** Unixtime Task should be hidden until, 0 if not set */
@ColumnInfo(name = "hideUntil")
var hideUntil: Long? = 0L
/** Unixtime Task was created */
@ColumnInfo(name = "created")
var creationDate: Long? = 0L
/** Unixtime Task was last touched */
@ColumnInfo(name = "modified")
var modificationDate: Long? = 0L
/** Unixtime Task was completed. 0 means active */
@ColumnInfo(name = "completed")
var completionDate: Long? = 0L
/** Unixtime Task was deleted. 0 means not deleted */
@ColumnInfo(name = "deleted")
var deletionDate: Long? = 0L
// --- data access boilerplate
@ColumnInfo(name = "notes")
var notes: String? = ""
@ColumnInfo(name = "estimatedSeconds")
var estimatedSeconds: Int? = 0
@ColumnInfo(name = "elapsedSeconds")
var elapsedSeconds: Int? = 0
@ColumnInfo(name = "timerStart")
var timerStart: Long? = 0L
/** Flags for when to send reminders */
@ColumnInfo(name = "notificationFlags")
var reminderFlags: Int? = 0
/** Reminder period, in milliseconds. 0 means disabled */
@ColumnInfo(name = "notifications")
var reminderPeriod: Long? = 0L
// --- parcelable helpers
/** Unixtime the last reminder was triggered */
@ColumnInfo(name = "lastNotified")
var reminderLast: Long? = 0L
// --- data access methods
/** Unixtime snooze is set (0 -> no snooze) */
@ColumnInfo(name = "snoozeTime")
var reminderSnooze: Long? = 0L
@ColumnInfo(name = "recurrence")
var recurrence: String? = ""
@ColumnInfo(name = "repeatUntil")
var repeatUntil: Long? = 0L
@ColumnInfo(name = "calendarUri")
var calendarURI: String? = ""
/** Remote id */
@ColumnInfo(name = "remoteId")
var remoteId: String? = NO_UUID
@ColumnInfo(name = "collapsed")
var isCollapsed = false
@ColumnInfo(name = "parent")
@Transient
var parent: Long = 0
@ColumnInfo(name = "parent_uuid")
var parentUuid: String? = null
@Ignore
@Transient
private var transitoryData: HashMap<String, Any>? = null
constructor()
@Ignore
constructor(reader: XmlReader) {
calendarURI = reader.readString("calendarUri")
completionDate = reader.readLong("completed")
creationDate = reader.readLong("created")
deletionDate = reader.readLong("deleted")
dueDate = reader.readLong("dueDate")
elapsedSeconds = reader.readInteger("elapsedSeconds")
estimatedSeconds = reader.readInteger("estimatedSeconds")
hideUntil = reader.readLong("hideUntil")
priority = reader.readInteger("importance")
modificationDate = reader.readLong("modified")
notes = reader.readString("notes")
recurrence = reader.readString("recurrence")
reminderFlags = reader.readInteger("notificationFlags")
reminderLast = reader.readLong("lastNotified")
reminderPeriod = reader.readLong("notifications")
reminderSnooze = reader.readLong("snoozeTime")
repeatUntil = reader.readLong("repeatUntil")
timerStart = reader.readLong("timerStart")
title = reader.readString("title")
remoteId = reader.readString("remoteId")
}
@Ignore
constructor(parcel: Parcel) {
calendarURI = parcel.readString()
completionDate = parcel.readLong()
creationDate = parcel.readLong()
deletionDate = parcel.readLong()
dueDate = parcel.readLong()
elapsedSeconds = parcel.readInt()
estimatedSeconds = parcel.readInt()
hideUntil = parcel.readLong()
id = parcel.readLong()
priority = parcel.readInt()
modificationDate = parcel.readLong()
notes = parcel.readString()
recurrence = parcel.readString()
reminderFlags = parcel.readInt()
reminderLast = parcel.readLong()
reminderPeriod = parcel.readLong()
reminderSnooze = parcel.readLong()
repeatUntil = parcel.readLong()
timerStart = parcel.readLong()
title = parcel.readString()
remoteId = parcel.readString()
transitoryData = parcel.readHashMap(ContentValues::class.java.classLoader) as HashMap<String, Any>?
isCollapsed = ParcelCompat.readBoolean(parcel)
parent = parcel.readLong()
parentUuid = parcel.readString()
}
var uuid: String?
get() = if (Strings.isNullOrEmpty(remoteId)) NO_UUID else remoteId
set(uuid) {
remoteId = uuid
}
/** Checks whether task is done. Requires COMPLETION_DATE */
val isCompleted
get() = completionDate!! > 0
/** Checks whether task is deleted. Will return false if DELETION_DATE not read */
val isDeleted
get() = deletionDate!! > 0
/** Checks whether task is hidden. Requires HIDDEN_UNTIL */
val isHidden
get() = hideUntil!! > DateUtilities.now()
fun hasHideUntilDate() = hideUntil!! > 0
/** Checks whether task is done. Requires DUE_DATE */
fun hasDueDate() = dueDate!! > 0
/**
* Create hide until for this task.
*
* @param setting one of the HIDE_UNTIL_* constants
* @param customDate if specific day is set, this value
*/
fun createHideUntil(setting: Int, customDate: Long): Long {
val date: Long = when (setting) {
HIDE_UNTIL_NONE -> return 0
HIDE_UNTIL_DUE, HIDE_UNTIL_DUE_TIME -> dueDate!!
HIDE_UNTIL_DAY_BEFORE -> dueDate!! - DateUtilities.ONE_DAY
HIDE_UNTIL_WEEK_BEFORE -> dueDate!! - DateUtilities.ONE_WEEK
HIDE_UNTIL_SPECIFIC_DAY, HIDE_UNTIL_SPECIFIC_DAY_TIME -> customDate
else -> throw IllegalArgumentException("Unknown setting $setting")
}
if (date <= 0) {
return date
}
var hideUntil = DateTimeUtils.newDateTime(date).withMillisOfSecond(0) // get rid of millis
hideUntil = if (setting != HIDE_UNTIL_SPECIFIC_DAY_TIME && setting != HIDE_UNTIL_DUE_TIME) {
hideUntil.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0)
} else {
hideUntil.withSecondOfMinute(1)
}
return hideUntil.millis
}
/** Checks whether this due date has a due time or only a date */
fun hasDueTime(): Boolean = hasDueDate() && hasDueTime(dueDate!!)
val isOverdue: Boolean
get() {
val dueDate = dueDate
val compareTo = if (hasDueTime()) DateUtilities.now() else DateTimeUtils.newDateTime().startOfDay().millis
return dueDate!! < compareTo && !isCompleted
}
fun repeatAfterCompletion(): Boolean = recurrence!!.contains("FROM=COMPLETION")
fun sanitizedRecurrence(): String = getRecurrenceWithoutFrom().replace("BYDAY=;".toRegex(), "") // $NON-NLS-1$//$NON-NLS-2$
fun getRecurrenceWithoutFrom(): String = recurrence!!.replace(";?FROM=[^;]*".toRegex(), "")
fun setDueDateAdjustingHideUntil(newDueDate: Long) {
if (dueDate!! > 0) {
if (hideUntil!! > 0) {
hideUntil = if (newDueDate > 0) hideUntil!! + newDueDate - dueDate!! else 0
}
}
dueDate = newDueDate
}
val isRecurring: Boolean
get() = !Strings.isNullOrEmpty(recurrence)
fun setRecurrence(rrule: RRule, afterCompletion: Boolean) {
recurrence = rrule.toIcal() + if (afterCompletion) ";FROM=COMPLETION" else ""
}
fun hasNotes(): Boolean {
return !Strings.isNullOrEmpty(notes)
}
fun setCalendarUri(calendarUri: String?) {
calendarURI = calendarUri
}
val isNotifyModeNonstop: Boolean
get() = isReminderFlagSet(NOTIFY_MODE_NONSTOP)
val isNotifyModeFive: Boolean
get() = isReminderFlagSet(NOTIFY_MODE_FIVE)
val isNotifyAfterDeadline: Boolean
get() = isReminderFlagSet(NOTIFY_AFTER_DEADLINE)
val isNotifyAtDeadline: Boolean
get() = isReminderFlagSet(NOTIFY_AT_DEADLINE)
private fun isReminderFlagSet(flag: Int): Boolean {
return reminderFlags!! and flag > 0
}
val isNew: Boolean
get() = id == NO_ID
/** {@inheritDoc} */
override fun describeContents() = 0
/** {@inheritDoc} */
override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeString(calendarURI)
dest.writeLong(completionDate!!)
dest.writeLong(creationDate!!)
dest.writeLong(deletionDate!!)
dest.writeLong(dueDate!!)
dest.writeInt(elapsedSeconds!!)
dest.writeInt(estimatedSeconds!!)
dest.writeLong(hideUntil!!)
dest.writeLong(id!!)
dest.writeInt(priority!!)
dest.writeLong(modificationDate!!)
dest.writeString(notes)
dest.writeString(recurrence)
dest.writeInt(reminderFlags!!)
dest.writeLong(reminderLast!!)
dest.writeLong(reminderPeriod!!)
dest.writeLong(reminderSnooze!!)
dest.writeLong(repeatUntil!!)
dest.writeLong(timerStart!!)
dest.writeString(title)
dest.writeString(remoteId)
dest.writeMap(transitoryData as Map<*, *>?)
ParcelCompat.writeBoolean(dest, isCollapsed)
dest.writeLong(parent)
dest.writeString(parentUuid)
}
fun insignificantChange(task: Task?): Boolean {
if (this === task) {
return true
}
return if (task == null) {
false
} else id == task.id
&& title == task.title
&& priority == task.priority
&& dueDate == task.dueDate
&& hideUntil == task.hideUntil
&& creationDate == task.creationDate
&& modificationDate == task.modificationDate
&& completionDate == task.completionDate
&& deletionDate == task.deletionDate
&& notes == task.notes
&& estimatedSeconds == task.estimatedSeconds
&& elapsedSeconds == task.elapsedSeconds
&& reminderFlags == task.reminderFlags
&& reminderPeriod == task.reminderPeriod
&& recurrence == task.recurrence
&& repeatUntil == task.repeatUntil
&& calendarURI == task.calendarURI
&& parent == task.parent && parentUuid == task.parentUuid
&& remoteId == task.remoteId
}
fun googleTaskUpToDate(original: Task?): Boolean {
if (this === original) {
return true
}
return if (original == null) {
false
} else title == original.title
&& dueDate == original.dueDate
&& completionDate == original.completionDate
&& deletionDate == original.deletionDate
&& parent == original.parent && notes == original.notes
}
fun caldavUpToDate(original: Task?): Boolean {
if (this === original) {
return true
}
return if (original == null) {
false
} else title == original.title
&& priority == original.priority
&& dueDate == original.dueDate
&& completionDate == original.completionDate
&& deletionDate == original.deletionDate
&& notes == original.notes
&& recurrence == original.recurrence
&& parent == original.parent && repeatUntil == original.repeatUntil
}
val isSaved: Boolean
get() = id != NO_ID
@Synchronized
fun suppressSync() {
putTransitory(SyncFlags.SUPPRESS_SYNC, true)
}
@Synchronized
fun suppressRefresh() {
putTransitory(TaskDao.TRANS_SUPPRESS_REFRESH, true)
}
@Synchronized
fun putTransitory(key: String, value: Any) {
if (transitoryData == null) {
transitoryData = HashMap()
}
transitoryData!![key] = value
}
val tags: ArrayList<String>
get() {
return getTransitory(Tag.KEY) ?: ArrayList()
}
fun setTags(tags: ArrayList<String>) {
if (transitoryData == null) {
transitoryData = HashMap()
}
transitoryData!![Tag.KEY] = tags
}
fun hasTransitory(key: String?): Boolean {
return transitoryData != null && transitoryData!!.containsKey(key)
}
fun <T> getTransitory(key: String?): T? {
return if (transitoryData == null) {
null
} else transitoryData!![key] as T?
}
// --- Convenience wrappers for using transitories as flags
fun checkTransitory(flag: String?): Boolean {
val trans = getTransitory<Any>(flag)
return trans != null
}
override fun toString(): String {
return "Task(id=$id, title=$title, dueDate=$dueDate, hideUntil=$hideUntil, creationDate=$creationDate, modificationDate=$modificationDate, completionDate=$completionDate, deletionDate=$deletionDate, notes=$notes, estimatedSeconds=$estimatedSeconds, elapsedSeconds=$elapsedSeconds, timerStart=$timerStart, reminderFlags=$reminderFlags, reminderPeriod=$reminderPeriod, reminderLast=$reminderLast, reminderSnooze=$reminderSnooze, recurrence=$recurrence, repeatUntil=$repeatUntil, calendarURI=$calendarURI, remoteId=$remoteId, isCollapsed=$isCollapsed, parent=$parent, parentUuid=$parentUuid, transitoryData=$transitoryData)"
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Task) return false
if (id != other.id) return false
if (title != other.title) return false
if (dueDate != other.dueDate) return false
if (hideUntil != other.hideUntil) return false
if (creationDate != other.creationDate) return false
if (modificationDate != other.modificationDate) return false
if (completionDate != other.completionDate) return false
if (deletionDate != other.deletionDate) return false
if (notes != other.notes) return false
if (estimatedSeconds != other.estimatedSeconds) return false
if (elapsedSeconds != other.elapsedSeconds) return false
if (timerStart != other.timerStart) return false
if (reminderFlags != other.reminderFlags) return false
if (reminderPeriod != other.reminderPeriod) return false
if (reminderLast != other.reminderLast) return false
if (reminderSnooze != other.reminderSnooze) return false
if (recurrence != other.recurrence) return false
if (repeatUntil != other.repeatUntil) return false
if (calendarURI != other.calendarURI) return false
if (remoteId != other.remoteId) return false
if (isCollapsed != other.isCollapsed) return false
if (parent != other.parent) return false
if (parentUuid != other.parentUuid) return false
if (transitoryData != other.transitoryData) return false
return true
}
override fun hashCode(): Int {
var result = id?.hashCode() ?: 0
result = 31 * result + (title?.hashCode() ?: 0)
result = 31 * result + dueDate.hashCode()
result = 31 * result + hideUntil.hashCode()
result = 31 * result + creationDate.hashCode()
result = 31 * result + modificationDate.hashCode()
result = 31 * result + completionDate.hashCode()
result = 31 * result + deletionDate.hashCode()
result = 31 * result + (notes?.hashCode() ?: 0)
result = 31 * result + estimatedSeconds!!
result = 31 * result + elapsedSeconds!!
result = 31 * result + timerStart.hashCode()
result = 31 * result + reminderFlags!!
result = 31 * result + reminderPeriod.hashCode()
result = 31 * result + reminderLast.hashCode()
result = 31 * result + reminderSnooze.hashCode()
result = 31 * result + (recurrence?.hashCode() ?: 0)
result = 31 * result + repeatUntil.hashCode()
result = 31 * result + (calendarURI?.hashCode() ?: 0)
result = 31 * result + (remoteId?.hashCode() ?: 0)
result = 31 * result + isCollapsed.hashCode()
result = 31 * result + parent.hashCode()
result = 31 * result + (parentUuid?.hashCode() ?: 0)
result = 31 * result + (transitoryData?.hashCode() ?: 0)
return result
}
@Retention(AnnotationRetention.SOURCE)
@IntDef(Priority.HIGH, Priority.MEDIUM, Priority.LOW, Priority.NONE)
annotation class Priority {
companion object {
const val HIGH = 0
const val MEDIUM = 1
const val LOW = 2
const val NONE = 3
}
}
companion object {
// --- table and uri
/** table for this model */
@JvmField val TABLE = Table("tasks")
@JvmField val FIELDS = Field.field("tasks.*")
const val NO_ID: Long = 0
// --- properties
@JvmField val ID = LongProperty(TABLE, "_id")
@JvmField val TITLE = StringProperty(TABLE, "title")
@JvmField val IMPORTANCE = IntegerProperty(TABLE, "importance")
@JvmField val DUE_DATE = LongProperty(TABLE, "dueDate")
@JvmField val HIDE_UNTIL = LongProperty(TABLE, "hideUntil")
@JvmField val MODIFICATION_DATE = LongProperty(TABLE, "modified")
@JvmField val CREATION_DATE = LongProperty(TABLE, "created")
@JvmField val COMPLETION_DATE = LongProperty(TABLE, "completed")
@JvmField val DELETION_DATE = LongProperty(TABLE, "deleted")
@JvmField val NOTES = StringProperty(TABLE, "notes")
@JvmField val TIMER_START = LongProperty(TABLE, "timerStart")
@JvmField val PARENT = LongProperty(TABLE, "parent")
/** constant value for no uuid */
const val NO_UUID = "0" // $NON-NLS-1$
@JvmField val UUID = StringProperty(TABLE, "remoteId")
/** whether to send a reminder at deadline */
const val NOTIFY_AT_DEADLINE = 1 shl 1
/** whether to send reminders while task is overdue */
const val NOTIFY_AFTER_DEADLINE = 1 shl 2
/** reminder mode non-stop */
const val NOTIFY_MODE_NONSTOP = 1 shl 3
/** reminder mode five times (exclusive with non-stop) */
const val NOTIFY_MODE_FIVE = 1 shl 4
@JvmField val CREATOR: Parcelable.Creator<Task> = object : Parcelable.Creator<Task> {
override fun createFromParcel(source: Parcel): Task? {
return Task(source)
}
override fun newArray(size: Int): Array<Task?> {
return arrayOfNulls(size)
}
}
/** urgency array index -> significance */
const val URGENCY_NONE = 0
const val URGENCY_SPECIFIC_DAY = 7
const val URGENCY_SPECIFIC_DAY_TIME = 8
/** hide until array index -> significance */
const val HIDE_UNTIL_NONE = 0
const val HIDE_UNTIL_DUE = 1
const val HIDE_UNTIL_DAY_BEFORE = 2
const val HIDE_UNTIL_WEEK_BEFORE = 3
const val HIDE_UNTIL_SPECIFIC_DAY = 4
// --- for astrid.com
const val HIDE_UNTIL_SPECIFIC_DAY_TIME = 5
const val HIDE_UNTIL_DUE_TIME = 6
const val URGENCY_TODAY = 1
const val URGENCY_TOMORROW = 2
// --- notification flags
const val URGENCY_DAY_AFTER = 3
const val URGENCY_NEXT_WEEK = 4
const val URGENCY_IN_TWO_WEEKS = 5
/**
* Creates due date for this task. If this due date has no time associated, we move it to the last
* millisecond of the day.
*
* @param setting one of the URGENCY_* constants
* @param customDate if specific day or day & time is set, this value
*/
@JvmStatic fun createDueDate(setting: Int, customDate: Long): Long {
val date: Long = when (setting) {
URGENCY_NONE -> 0
URGENCY_TODAY -> DateUtilities.now()
URGENCY_TOMORROW -> DateUtilities.now() + DateUtilities.ONE_DAY
URGENCY_DAY_AFTER -> DateUtilities.now() + 2 * DateUtilities.ONE_DAY
URGENCY_NEXT_WEEK -> DateUtilities.now() + DateUtilities.ONE_WEEK
URGENCY_IN_TWO_WEEKS -> DateUtilities.now() + 2 * DateUtilities.ONE_WEEK
URGENCY_SPECIFIC_DAY, URGENCY_SPECIFIC_DAY_TIME -> customDate
else -> throw IllegalArgumentException("Unknown setting $setting")
}
if (date <= 0) {
return date
}
var dueDate = DateTimeUtils.newDateTime(date).withMillisOfSecond(0)
dueDate = if (setting != URGENCY_SPECIFIC_DAY_TIME) {
dueDate
.withHourOfDay(12)
.withMinuteOfHour(0)
.withSecondOfMinute(0) // Seconds == 0 means no due time
} else {
dueDate.withSecondOfMinute(1) // Seconds > 0 means due time exists
}
return dueDate.millis
}
/** Checks whether provided due date has a due time or only a date */
@JvmStatic fun hasDueTime(dueDate: Long): Boolean {
return dueDate > 0 && dueDate % 60000 > 0
}
@JvmStatic fun isValidUuid(uuid: String): Boolean {
return try {
val value = uuid.toLong()
value > 0
} catch (e: NumberFormatException) {
Timber.e(e)
isUuidEmpty(uuid)
}
}
@JvmStatic fun isUuidEmpty(uuid: String?): Boolean {
return NO_UUID == uuid || Strings.isNullOrEmpty(uuid)
}
}
}

@ -189,7 +189,7 @@ public class TaskMover {
tasks.put(id, new CaldavTask(id, listId));
for (Task child : taskDao.fetchChildren(task.getId())) {
CaldavTask newTask = new CaldavTask(child.getId(), listId);
newTask.setRemoteParent(tasks.get(child.parent).getRemoteId());
newTask.setRemoteParent(tasks.get(child.getParent()).getRemoteId());
tasks.put(child.getId(), newTask);
}
caldavDao.insert(tasks.values());

@ -114,7 +114,7 @@ class iCalendar @Inject constructor(
val remoteModel = CaldavConverter.toCaldav(caldavTask, task)
val categories = remoteModel.categories
categories.clear()
categories.addAll(tagDataDao.getTagDataForTask(task.getId()).map { it.name!! })
categories.addAll(tagDataDao.getTagDataForTask(task.id!!).map { it.name!! })
if (isNullOrEmpty(caldavTask.remoteId)) {
val caldavUid = UUIDHelper.newUUID()
caldavTask.remoteId = caldavUid
@ -122,7 +122,7 @@ class iCalendar @Inject constructor(
} else {
remoteModel.uid = caldavTask.remoteId
}
val location = locationDao.getGeofences(task.getId())
val location = locationDao.getGeofences(task.id!!)
val localGeo = toGeo(location)
if (localGeo == null || !localGeo.equalish(remoteModel.geoPosition)) {
remoteModel.geoPosition = localGeo
@ -145,7 +145,7 @@ class iCalendar @Inject constructor(
if (existing == null) {
task = taskCreator.createWithValues("")
taskDao.createNew(task)
caldavTask = CaldavTask(task.getId(), calendar.uuid, remote.uid, obj)
caldavTask = CaldavTask(task.id!!, calendar.uuid, remote.uid, obj)
} else {
task = taskDao.fetch(existing.task)!!
caldavTask = existing
@ -153,12 +153,12 @@ class iCalendar @Inject constructor(
CaldavConverter.apply(task, remote)
val geo = remote.geoPosition
if (geo == null) {
locationDao.getActiveGeofences(task.getId()).forEach {
locationDao.getActiveGeofences(task.id!!).forEach {
locationDao.delete(it.geofence)
geofenceApi.update(it.place)
}
} else {
setPlace(task.getId(), geo)
setPlace(task.id!!, geo)
}
tagDao.applyTags(task, tagDataDao, getTags(remote.categories))
task.suppressSync()

@ -34,7 +34,7 @@ class Tag {
constructor(task: Task, tagData: TagData) : this(task, tagData.name, tagData.remoteId)
@Ignore
constructor(task: Task, name: String?, tagUid: String?) : this(task.getId(), task.uuid, name, tagUid)
constructor(task: Task, name: String?, tagUid: String?) : this(task.id!!, task.uuid, name, tagUid)
@Ignore
constructor(taskId: Long, taskUid: String?, name: String?, tagUid: String?) {

@ -34,7 +34,7 @@ abstract class TagDao {
@Transaction
open fun applyTags(task: Task, tagDataDao: TagDataDao, current: List<TagData>): Boolean {
val taskId = task.getId()
val taskId = task.id!!
val existing = HashSet(tagDataDao.getTagDataForTask(taskId))
val selected = HashSet<TagData>(current)
val added = selected subtract existing

@ -89,14 +89,14 @@ abstract class TagDataDao {
val modified = HashSet<Long>()
val keep = partiallySelected.plus(selected).map { it.remoteId!! }
for (sublist in tasks.chunked(DbUtils.MAX_SQLITE_ARGS - keep.size)) {
val tags = tagsToDelete(sublist.map(Task::id), keep)
val tags = tagsToDelete(sublist.map { it.id!! }, keep)
deleteTags(tags)
modified.addAll(tags.map(Tag::task))
}
for (task in tasks) {
val added = selected subtract getTagDataForTask(task.getId())
val added = selected subtract getTagDataForTask(task.id!!)
if (added.isNotEmpty()) {
modified.add(task.getId())
modified.add(task.id!!)
insert(added.map { Tag(task, it) })
}
}

@ -240,7 +240,7 @@ class DateTimePicker : InjectingBottomSheetDialogFragment() {
if (taskId > 0) {
val task: Task = taskDao.fetch(taskId)!!
if (newDateTime(dueDate).isAfterNow) {
notificationManager.cancel(task.getId())
notificationManager.cancel(task.id!!)
}
task.setDueDateAdjustingHideUntil(dueDate)
taskDao.save(task)

@ -14,14 +14,14 @@ import javax.inject.Inject
class CheckBoxProvider @Inject constructor(@ForActivity private val context: Context, private val colorProvider: ColorProvider) {
fun getCheckBox(task: Task) = getCheckBox(task.isCompleted, task.isRecurring, task.priority)
fun getCheckBox(task: Task) = getCheckBox(task.isCompleted, task.isRecurring, task.priority!!)
fun getCheckBox(complete: Boolean, repeating: Boolean, priority: Int) =
getDrawable(getDrawableRes(complete, repeating), priority)
fun getWidgetCheckBox(task: Task): Bitmap {
val wrapped = DrawableUtil.getWrapped(context, getDrawableRes(task.isCompleted, task.isRecurring))
DrawableUtil.setTint(wrapped, colorProvider.getPriorityColor(task.priority, false))
DrawableUtil.setTint(wrapped, colorProvider.getPriorityColor(task.priority!!, false))
return convertToBitmap(wrapped)
}

Loading…
Cancel
Save