Make some task fields not null

pull/996/head
Alex Baker 4 years ago
parent b955a0435d
commit 59f579420d

File diff suppressed because it is too large Load Diff

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

@ -35,7 +35,7 @@ class TaskDaoTests : InjectingTestCase() {
task.title = "happy" task.title = "happy"
taskDao.createNew(task) taskDao.createNew(task)
assertEquals(1, taskDao.getAll().size) assertEquals(1, taskDao.getAll().size)
val happyId = task.id!! val happyId = task.id
assertNotSame(Task.NO_ID, happyId) assertNotSame(Task.NO_ID, happyId)
task = taskDao.fetch(happyId)!! task = taskDao.fetch(happyId)!!
assertEquals("happy", task.title) assertEquals("happy", task.title)
@ -47,7 +47,7 @@ class TaskDaoTests : InjectingTestCase() {
assertEquals(2, taskDao.getAll().size) assertEquals(2, taskDao.getAll().size)
// rename sad to melancholy // rename sad to melancholy
val sadId = task.id!! val sadId = task.id
assertNotSame(Task.NO_ID, sadId) assertNotSame(Task.NO_ID, sadId)
task.title = "melancholy" task.title = "melancholy"
taskDao.save(task) taskDao.save(task)

@ -59,11 +59,11 @@ class GtasksMetadataServiceTest : InjectingTestCase() {
val task = Task() val task = Task()
task.title = "cats" task.title = "cats"
taskDao.createNew(task) taskDao.createNew(task)
val metadata = GoogleTask(task.id!!, "") val metadata = GoogleTask(task.id, "")
if (id != null) { if (id != null) {
metadata.remoteId = id metadata.remoteId = id
} }
metadata.task = task.id!! metadata.task = task.id
googleTaskDao.insert(metadata) googleTaskDao.insert(metadata)
return task return task
} }

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

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

@ -206,7 +206,7 @@ class AdvancedRepeatTest {
} }
private fun assertDueDate(actual: Long, expectedWhich: Int, expectedDayOfWeek: Int) { private fun assertDueDate(actual: Long, expectedWhich: Int, expectedDayOfWeek: Int) {
val expected = getDate(task!!.dueDate!!, expectedWhich, expectedDayOfWeek) val expected = getDate(task!!.dueDate, expectedWhich, expectedDayOfWeek)
assertEquals(expected, actual) assertEquals(expected, actual)
} }

@ -68,7 +68,7 @@ class TitleParserTest : InjectingTestCase() {
for (i in 0..22) { for (i in 0..22) {
val testTitle = "Jog on " + titleMonthStrings[i] + " 12." val testTitle = "Jog on " + titleMonthStrings[i] + " 12."
val task = insertTitleAddTask(testTitle) val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.dueDate!!) val date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.monthOfYear, i / 2 + 1) assertEquals(date.monthOfYear, i / 2 + 1)
assertEquals(date.dayOfMonth, 12) assertEquals(date.dayOfMonth, 12)
} }
@ -79,7 +79,7 @@ class TitleParserTest : InjectingTestCase() {
for (i in 1..12) { for (i in 1..12) {
val testTitle = "Jog on $i/12/13" val testTitle = "Jog on $i/12/13"
val task = insertTitleAddTask(testTitle) val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.dueDate!!) val date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.monthOfYear, i) assertEquals(date.monthOfYear, i)
assertEquals(date.dayOfMonth, 12) assertEquals(date.dayOfMonth, 12)
assertEquals(date.year, 2013) assertEquals(date.year, 2013)
@ -90,7 +90,7 @@ class TitleParserTest : InjectingTestCase() {
fun testArmyTime() { fun testArmyTime() {
val testTitle = "Jog on 23:21." val testTitle = "Jog on 23:21."
val task = insertTitleAddTask(testTitle) val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.dueDate!!) val date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.hourOfDay, 23) assertEquals(date.hourOfDay, 23)
assertEquals(date.minuteOfHour, 21) assertEquals(date.minuteOfHour, 21)
} }
@ -99,7 +99,7 @@ class TitleParserTest : InjectingTestCase() {
fun test_AM_PM() { fun test_AM_PM() {
val testTitle = "Jog at 8:33 PM." val testTitle = "Jog at 8:33 PM."
val task = insertTitleAddTask(testTitle) val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.dueDate!!) val date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.hourOfDay, 20) assertEquals(date.hourOfDay, 20)
assertEquals(date.minuteOfHour, 33) assertEquals(date.minuteOfHour, 33)
} }
@ -108,7 +108,7 @@ class TitleParserTest : InjectingTestCase() {
fun test_at_hour() { fun test_at_hour() {
val testTitle = "Jog at 8 PM." val testTitle = "Jog at 8 PM."
val task = insertTitleAddTask(testTitle) val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.dueDate!!) val date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.hourOfDay, 20) assertEquals(date.hourOfDay, 20)
assertEquals(date.minuteOfHour, 0) assertEquals(date.minuteOfHour, 0)
} }
@ -117,7 +117,7 @@ class TitleParserTest : InjectingTestCase() {
fun test_oclock_AM() { fun test_oclock_AM() {
val testTitle = "Jog at 8 o'clock AM." val testTitle = "Jog at 8 o'clock AM."
val task = insertTitleAddTask(testTitle) val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.dueDate!!) val date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.hourOfDay, 8) assertEquals(date.hourOfDay, 8)
assertEquals(date.minuteOfHour, 0) 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") val testTitles = arrayOf("Jog 8 AM", "Jog 8 o'clock AM", "at 8:00 AM")
for (testTitle in testTitles) { for (testTitle in testTitles) {
val task = insertTitleAddTask(testTitle) val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.dueDate!!) val date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.hourOfDay, 8) assertEquals(date.hourOfDay, 8)
assertEquals(date.minuteOfHour, 0) assertEquals(date.minuteOfHour, 0)
} }
@ -140,7 +140,7 @@ class TitleParserTest : InjectingTestCase() {
) )
for (testTitle in testTitles) { for (testTitle in testTitles) {
val task = insertTitleAddTask(testTitle) val task = insertTitleAddTask(testTitle)
val date = DateTimeUtils.newDateTime(task.dueDate!!) val date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.hourOfDay, 12) assertEquals(date.hourOfDay, 12)
assertEquals(date.minuteOfHour, 30) assertEquals(date.minuteOfHour, 30)
} }
@ -156,12 +156,12 @@ class TitleParserTest : InjectingTestCase() {
val today = Calendar.getInstance() val today = Calendar.getInstance()
var title = "Jog today" var title = "Jog today"
var task = taskCreator.createWithValues(title) var task = taskCreator.createWithValues(title)
var date = DateTimeUtils.newDateTime(task.dueDate!!) var date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.dayOfWeek, today[Calendar.DAY_OF_WEEK]) assertEquals(date.dayOfWeek, today[Calendar.DAY_OF_WEEK])
// Calendar starts 1-6, date.getDay() starts at 0 // Calendar starts 1-6, date.getDay() starts at 0
title = "Jog tomorrow" title = "Jog tomorrow"
task = taskCreator.createWithValues(title) task = taskCreator.createWithValues(title)
date = DateTimeUtils.newDateTime(task.dueDate!!) date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.dayOfWeek % 7, (today[Calendar.DAY_OF_WEEK] + 1) % 7) assertEquals(date.dayOfWeek % 7, (today[Calendar.DAY_OF_WEEK] + 1) % 7)
val days = arrayOf( val days = arrayOf(
"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday") "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday")
@ -169,11 +169,11 @@ class TitleParserTest : InjectingTestCase() {
for (i in 1..6) { for (i in 1..6) {
title = "Jog " + days[i] title = "Jog " + days[i]
task = taskCreator.createWithValues(title) task = taskCreator.createWithValues(title)
date = DateTimeUtils.newDateTime(task.dueDate!!) date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.dayOfWeek, i + 1) assertEquals(date.dayOfWeek, i + 1)
title = "Jog " + abrevDays[i] title = "Jog " + abrevDays[i]
task = taskCreator.createWithValues(title) task = taskCreator.createWithValues(title)
date = DateTimeUtils.newDateTime(task.dueDate!!) date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.dayOfWeek, i + 1) assertEquals(date.dayOfWeek, i + 1)
} }
} }

@ -39,7 +39,7 @@ class AppleRemindersTests {
fun readCreationDate() { fun readCreationDate() {
assertEquals( assertEquals(
DateTime(2018, 4, 16, 17, 24, 10).millis, DateTime(2018, 4, 16, 17, 24, 10).millis,
vtodo("apple/basic_no_due_date.txt").creationDate as Long) vtodo("apple/basic_no_due_date.txt").creationDate)
} }
@Test @Test
@ -53,7 +53,7 @@ class AppleRemindersTests {
fun completed() { fun completed() {
assertEquals( assertEquals(
DateTime(2018, 4, 17, 13, 43, 2).millis, DateTime(2018, 4, 17, 13, 43, 2).millis,
vtodo("apple/basic_completed.txt").completionDate as Long) vtodo("apple/basic_completed.txt").completionDate)
} }
@Test @Test

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

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

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

@ -18,28 +18,28 @@ class GoogleTaskSynchronizerTest {
@Test @Test
fun testMergeDate() { fun testMergeDate() {
val local = newTask(with(DUE_DATE, DateTime(2016, 3, 12))) val local = newTask(with(DUE_DATE, DateTime(2016, 3, 12)))
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate!!, local) GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate, local)
assertEquals(DateTime(2016, 3, 11, 12, 0).millis, local.dueDate) assertEquals(DateTime(2016, 3, 11, 12, 0).millis, local.dueDate)
} }
@Test @Test
fun testMergeTime() { fun testMergeTime() {
val local = newTask(with(DUE_TIME, DateTime(2016, 3, 11, 13, 30))) val local = newTask(with(DUE_TIME, DateTime(2016, 3, 11, 13, 30)))
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate!!, local) GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate, local)
assertEquals(DateTime(2016, 3, 11, 13, 30, 1).millis, local.dueDate) assertEquals(DateTime(2016, 3, 11, 13, 30, 1).millis, local.dueDate)
} }
@Test @Test
fun testDueDateAdjustHideBackwards() { fun testDueDateAdjustHideBackwards() {
val local = newTask(with(DUE_DATE, DateTime(2016, 3, 12)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE)) 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))).dueDate!!, local) GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate, local)
assertEquals(DateTime(2016, 3, 11).millis, local.hideUntil) assertEquals(DateTime(2016, 3, 11).millis, local.hideUntil)
} }
@Test @Test
fun testDueDateAdjustHideForwards() { fun testDueDateAdjustHideForwards() {
val local = newTask(with(DUE_DATE, DateTime(2016, 3, 12)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE)) 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))).dueDate!!, local) GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 14))).dueDate, local)
assertEquals(DateTime(2016, 3, 14).millis, local.hideUntil) assertEquals(DateTime(2016, 3, 14).millis, local.hideUntil)
} }
@ -48,7 +48,7 @@ class GoogleTaskSynchronizerTest {
val local = newTask( val local = newTask(
with(DUE_TIME, DateTime(2016, 3, 12, 13, 30)), with(DUE_TIME, DateTime(2016, 3, 12, 13, 30)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)) with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate!!, local) GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 11))).dueDate, local)
assertEquals( assertEquals(
DateTime(2016, 3, 11, 13, 30, 1).millis, local.hideUntil) DateTime(2016, 3, 11, 13, 30, 1).millis, local.hideUntil)
} }
@ -58,7 +58,7 @@ class GoogleTaskSynchronizerTest {
val local = newTask( val local = newTask(
with(DUE_TIME, DateTime(2016, 3, 12, 13, 30)), with(DUE_TIME, DateTime(2016, 3, 12, 13, 30)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)) with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))
GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 14))).dueDate!!, local) GoogleTaskSynchronizer.mergeDates(newTask(with(DUE_DATE, DateTime(2016, 3, 14))).dueDate, local)
assertEquals( assertEquals(
DateTime(2016, 3, 14, 13, 30, 1).millis, local.hideUntil) DateTime(2016, 3, 14, 13, 30, 1).millis, local.hideUntil)
} }
@ -66,7 +66,7 @@ class GoogleTaskSynchronizerTest {
@Test @Test
fun testDueDateClearHide() { fun testDueDateClearHide() {
val local = newTask(with(DUE_DATE, DateTime(2016, 3, 12)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE)) val local = newTask(with(DUE_DATE, DateTime(2016, 3, 12)), with(HIDE_TYPE, Task.HIDE_UNTIL_DUE))
GoogleTaskSynchronizer.mergeDates(newTask().dueDate!!, local) GoogleTaskSynchronizer.mergeDates(newTask().dueDate, local)
assertEquals(0L, local.hideUntil) assertEquals(0L, local.hideUntil)
} }
@ -75,7 +75,7 @@ class GoogleTaskSynchronizerTest {
val local = newTask( val local = newTask(
with(DUE_TIME, DateTime(2016, 3, 12, 13, 30)), with(DUE_TIME, DateTime(2016, 3, 12, 13, 30)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)) with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))
GoogleTaskSynchronizer.mergeDates(newTask().dueDate!!, local) GoogleTaskSynchronizer.mergeDates(newTask().dueDate, local)
assertEquals(0L, local.hideUntil) assertEquals(0L, local.hideUntil)
} }

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

@ -34,7 +34,7 @@ object TaskMaker {
val task = Task() val task = Task()
val title = lookup.valueOf(TITLE, null as String?) val title = lookup.valueOf(TITLE, null as String?)
if (!Strings.isNullOrEmpty(title)) { if (!Strings.isNullOrEmpty(title)) {
task.title = title task.title = title!!
} }
val id = lookup.valueOf(ID, Task.NO_ID) val id = lookup.valueOf(ID, Task.NO_ID)
if (id != Task.NO_ID) { if (id != Task.NO_ID) {

@ -58,7 +58,7 @@ import org.tasks.notifications.NotificationDao;
CaldavAccount.class, CaldavAccount.class,
GoogleTaskAccount.class GoogleTaskAccount.class
}, },
version = 73) version = 74)
public abstract class Database extends RoomDatabase { public abstract class Database extends RoomDatabase {
public static final String NAME = "database"; public static final String NAME = "database";

@ -16,6 +16,7 @@ import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.api.Filter import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.PermaSql import com.todoroo.astrid.api.PermaSql
import com.todoroo.astrid.data.Task import com.todoroo.astrid.data.Task
import com.todoroo.astrid.data.Task.Companion.NO_ID
import com.todoroo.astrid.helper.UUIDHelper import com.todoroo.astrid.helper.UUIDHelper
import org.tasks.BuildConfig import org.tasks.BuildConfig
import org.tasks.data.Place import org.tasks.data.Place
@ -225,7 +226,7 @@ abstract class TaskDao(private val database: Database) {
* success. * success.
*/ */
@JvmOverloads @JvmOverloads
fun save(task: Task, original: Task? = fetch(task.id!!)) { fun save(task: Task, original: Task? = fetch(task.id)) {
if (!task.insignificantChange(original)) { if (!task.insignificantChange(original)) {
task.modificationDate = DateUtilities.now() task.modificationDate = DateUtilities.now()
} }
@ -241,11 +242,11 @@ abstract class TaskDao(private val database: Database) {
abstract fun update(task: Task): Int abstract fun update(task: Task): Int
fun createNew(task: Task) { fun createNew(task: Task) {
task.id = null task.id = NO_ID
if (task.creationDate == 0L) { if (task.creationDate == 0L) {
task.creationDate = DateUtilities.now() task.creationDate = DateUtilities.now()
} }
if (Task.isUuidEmpty(task.remoteId!!)) { if (Task.isUuidEmpty(task.remoteId)) {
task.remoteId = UUIDHelper.newUUID() task.remoteId = UUIDHelper.newUUID()
} }
val insert = insert(task) val insert = insert(task)

@ -29,76 +29,76 @@ class Task : Parcelable {
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "_id") @ColumnInfo(name = "_id")
@Transient @Transient
var id: Long? = NO_ID var id = NO_ID
/** Name of Task */ /** Name of Task */
@ColumnInfo(name = "title") @ColumnInfo(name = "title")
var title: String? = "" var title: String? = null
@ColumnInfo(name = "importance") @ColumnInfo(name = "importance")
var priority: Int? = Priority.NONE var priority = Priority.NONE
/** Unixtime Task is due, 0 if not set */ /** Unixtime Task is due, 0 if not set */
@ColumnInfo(name = "dueDate") @ColumnInfo(name = "dueDate")
var dueDate: Long? = 0L var dueDate = 0L
/** Unixtime Task should be hidden until, 0 if not set */ /** Unixtime Task should be hidden until, 0 if not set */
@ColumnInfo(name = "hideUntil") @ColumnInfo(name = "hideUntil")
var hideUntil: Long? = 0L var hideUntil = 0L
/** Unixtime Task was created */ /** Unixtime Task was created */
@ColumnInfo(name = "created") @ColumnInfo(name = "created")
var creationDate: Long? = 0L var creationDate = 0L
/** Unixtime Task was last touched */ /** Unixtime Task was last touched */
@ColumnInfo(name = "modified") @ColumnInfo(name = "modified")
var modificationDate: Long? = 0L var modificationDate = 0L
/** Unixtime Task was completed. 0 means active */ /** Unixtime Task was completed. 0 means active */
@ColumnInfo(name = "completed") @ColumnInfo(name = "completed")
var completionDate: Long? = 0L var completionDate = 0L
/** Unixtime Task was deleted. 0 means not deleted */ /** Unixtime Task was deleted. 0 means not deleted */
@ColumnInfo(name = "deleted") @ColumnInfo(name = "deleted")
var deletionDate: Long? = 0L var deletionDate = 0L
// --- data access boilerplate // --- data access boilerplate
@ColumnInfo(name = "notes") @ColumnInfo(name = "notes")
var notes: String? = "" var notes: String? = null
@ColumnInfo(name = "estimatedSeconds") @ColumnInfo(name = "estimatedSeconds")
var estimatedSeconds: Int? = 0 var estimatedSeconds = 0
@ColumnInfo(name = "elapsedSeconds") @ColumnInfo(name = "elapsedSeconds")
var elapsedSeconds: Int? = 0 var elapsedSeconds = 0
@ColumnInfo(name = "timerStart") @ColumnInfo(name = "timerStart")
var timerStart: Long? = 0L var timerStart = 0L
/** Flags for when to send reminders */ /** Flags for when to send reminders */
@ColumnInfo(name = "notificationFlags") @ColumnInfo(name = "notificationFlags")
var reminderFlags: Int? = 0 var reminderFlags = 0
/** Reminder period, in milliseconds. 0 means disabled */ /** Reminder period, in milliseconds. 0 means disabled */
@ColumnInfo(name = "notifications") @ColumnInfo(name = "notifications")
var reminderPeriod: Long? = 0L var reminderPeriod = 0L
// --- parcelable helpers
/** Unixtime the last reminder was triggered */ /** Unixtime the last reminder was triggered */
@ColumnInfo(name = "lastNotified") @ColumnInfo(name = "lastNotified")
var reminderLast: Long? = 0L var reminderLast = 0L
// --- data access methods
/** Unixtime snooze is set (0 -> no snooze) */ /** Unixtime snooze is set (0 -> no snooze) */
@ColumnInfo(name = "snoozeTime") @ColumnInfo(name = "snoozeTime")
var reminderSnooze: Long? = 0L var reminderSnooze = 0L
@ColumnInfo(name = "recurrence") @ColumnInfo(name = "recurrence")
var recurrence: String? = "" var recurrence: String? = null
@ColumnInfo(name = "repeatUntil") @ColumnInfo(name = "repeatUntil")
var repeatUntil: Long? = 0L var repeatUntil = 0L
@ColumnInfo(name = "calendarUri") @ColumnInfo(name = "calendarUri")
var calendarURI: String? = "" var calendarURI: String? = null
/** Remote id */ /** Remote id */
@ColumnInfo(name = "remoteId") @ColumnInfo(name = "remoteId")
@ -109,7 +109,7 @@ class Task : Parcelable {
@ColumnInfo(name = "parent") @ColumnInfo(name = "parent")
@Transient @Transient
var parent: Long = 0 var parent = 0L
@ColumnInfo(name = "parent_uuid") @ColumnInfo(name = "parent_uuid")
var parentUuid: String? = null var parentUuid: String? = null
@ -166,35 +166,35 @@ class Task : Parcelable {
repeatUntil = parcel.readLong() repeatUntil = parcel.readLong()
timerStart = parcel.readLong() timerStart = parcel.readLong()
title = parcel.readString() title = parcel.readString()
remoteId = parcel.readString() remoteId = parcel.readString() ?: NO_UUID
transitoryData = parcel.readHashMap(ContentValues::class.java.classLoader) as HashMap<String, Any>? transitoryData = parcel.readHashMap(ContentValues::class.java.classLoader) as HashMap<String, Any>?
isCollapsed = ParcelCompat.readBoolean(parcel) isCollapsed = ParcelCompat.readBoolean(parcel)
parent = parcel.readLong() parent = parcel.readLong()
parentUuid = parcel.readString() parentUuid = parcel.readString()
} }
var uuid: String? var uuid: String
get() = if (Strings.isNullOrEmpty(remoteId)) NO_UUID else remoteId get() = if (Strings.isNullOrEmpty(remoteId)) NO_UUID else remoteId!!
set(uuid) { set(uuid) {
remoteId = uuid remoteId = uuid
} }
/** Checks whether task is done. Requires COMPLETION_DATE */ /** Checks whether task is done. Requires COMPLETION_DATE */
val isCompleted val isCompleted
get() = completionDate!! > 0 get() = completionDate > 0
/** Checks whether task is deleted. Will return false if DELETION_DATE not read */ /** Checks whether task is deleted. Will return false if DELETION_DATE not read */
val isDeleted val isDeleted
get() = deletionDate!! > 0 get() = deletionDate > 0
/** Checks whether task is hidden. Requires HIDDEN_UNTIL */ /** Checks whether task is hidden. Requires HIDDEN_UNTIL */
val isHidden val isHidden
get() = hideUntil!! > DateUtilities.now() get() = hideUntil > DateUtilities.now()
fun hasHideUntilDate() = hideUntil!! > 0 fun hasHideUntilDate() = hideUntil > 0
/** Checks whether task is done. Requires DUE_DATE */ /** Checks whether task is done. Requires DUE_DATE */
fun hasDueDate() = dueDate!! > 0 fun hasDueDate() = dueDate > 0
/** /**
* Create hide until for this task. * Create hide until for this task.
@ -205,9 +205,9 @@ class Task : Parcelable {
fun createHideUntil(setting: Int, customDate: Long): Long { fun createHideUntil(setting: Int, customDate: Long): Long {
val date: Long = when (setting) { val date: Long = when (setting) {
HIDE_UNTIL_NONE -> return 0 HIDE_UNTIL_NONE -> return 0
HIDE_UNTIL_DUE, HIDE_UNTIL_DUE_TIME -> dueDate!! HIDE_UNTIL_DUE, HIDE_UNTIL_DUE_TIME -> dueDate
HIDE_UNTIL_DAY_BEFORE -> dueDate!! - DateUtilities.ONE_DAY HIDE_UNTIL_DAY_BEFORE -> dueDate - DateUtilities.ONE_DAY
HIDE_UNTIL_WEEK_BEFORE -> dueDate!! - DateUtilities.ONE_WEEK HIDE_UNTIL_WEEK_BEFORE -> dueDate - DateUtilities.ONE_WEEK
HIDE_UNTIL_SPECIFIC_DAY, HIDE_UNTIL_SPECIFIC_DAY_TIME -> customDate HIDE_UNTIL_SPECIFIC_DAY, HIDE_UNTIL_SPECIFIC_DAY_TIME -> customDate
else -> throw IllegalArgumentException("Unknown setting $setting") else -> throw IllegalArgumentException("Unknown setting $setting")
} }
@ -224,25 +224,25 @@ class Task : Parcelable {
} }
/** Checks whether this due date has a due time or only a date */ /** Checks whether this due date has a due time or only a date */
fun hasDueTime(): Boolean = hasDueDate() && hasDueTime(dueDate!!) fun hasDueTime(): Boolean = hasDueDate() && hasDueTime(dueDate)
val isOverdue: Boolean val isOverdue: Boolean
get() { get() {
val dueDate = dueDate val dueDate = dueDate
val compareTo = if (hasDueTime()) DateUtilities.now() else DateTimeUtils.newDateTime().startOfDay().millis val compareTo = if (hasDueTime()) DateUtilities.now() else DateTimeUtils.newDateTime().startOfDay().millis
return dueDate!! < compareTo && !isCompleted return dueDate < compareTo && !isCompleted
} }
fun repeatAfterCompletion(): Boolean = recurrence!!.contains("FROM=COMPLETION") fun repeatAfterCompletion(): Boolean = recurrence?.contains("FROM=COMPLETION") ?: false
fun sanitizedRecurrence(): String = getRecurrenceWithoutFrom().replace("BYDAY=;".toRegex(), "") // $NON-NLS-1$//$NON-NLS-2$ fun sanitizedRecurrence(): String? = getRecurrenceWithoutFrom()?.replace("BYDAY=;".toRegex(), "") // $NON-NLS-1$//$NON-NLS-2$
fun getRecurrenceWithoutFrom(): String = recurrence!!.replace(";?FROM=[^;]*".toRegex(), "") fun getRecurrenceWithoutFrom(): String? = recurrence?.replace(";?FROM=[^;]*".toRegex(), "")
fun setDueDateAdjustingHideUntil(newDueDate: Long) { fun setDueDateAdjustingHideUntil(newDueDate: Long) {
if (dueDate!! > 0) { if (dueDate > 0) {
if (hideUntil!! > 0) { if (hideUntil > 0) {
hideUntil = if (newDueDate > 0) hideUntil!! + newDueDate - dueDate!! else 0 hideUntil = if (newDueDate > 0) hideUntil + newDueDate - dueDate else 0
} }
} }
dueDate = newDueDate dueDate = newDueDate
@ -259,10 +259,6 @@ class Task : Parcelable {
return !Strings.isNullOrEmpty(notes) return !Strings.isNullOrEmpty(notes)
} }
fun setCalendarUri(calendarUri: String?) {
calendarURI = calendarUri
}
val isNotifyModeNonstop: Boolean val isNotifyModeNonstop: Boolean
get() = isReminderFlagSet(NOTIFY_MODE_NONSTOP) get() = isReminderFlagSet(NOTIFY_MODE_NONSTOP)
@ -276,7 +272,7 @@ class Task : Parcelable {
get() = isReminderFlagSet(NOTIFY_AT_DEADLINE) get() = isReminderFlagSet(NOTIFY_AT_DEADLINE)
private fun isReminderFlagSet(flag: Int): Boolean { private fun isReminderFlagSet(flag: Int): Boolean {
return reminderFlags!! and flag > 0 return reminderFlags and flag > 0
} }
val isNew: Boolean val isNew: Boolean
@ -288,24 +284,24 @@ class Task : Parcelable {
/** {@inheritDoc} */ /** {@inheritDoc} */
override fun writeToParcel(dest: Parcel, flags: Int) { override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeString(calendarURI) dest.writeString(calendarURI)
dest.writeLong(completionDate!!) dest.writeLong(completionDate)
dest.writeLong(creationDate!!) dest.writeLong(creationDate)
dest.writeLong(deletionDate!!) dest.writeLong(deletionDate)
dest.writeLong(dueDate!!) dest.writeLong(dueDate)
dest.writeInt(elapsedSeconds!!) dest.writeInt(elapsedSeconds)
dest.writeInt(estimatedSeconds!!) dest.writeInt(estimatedSeconds)
dest.writeLong(hideUntil!!) dest.writeLong(hideUntil)
dest.writeLong(id!!) dest.writeLong(id)
dest.writeInt(priority!!) dest.writeInt(priority)
dest.writeLong(modificationDate!!) dest.writeLong(modificationDate)
dest.writeString(notes) dest.writeString(notes)
dest.writeString(recurrence) dest.writeString(recurrence)
dest.writeInt(reminderFlags!!) dest.writeInt(reminderFlags)
dest.writeLong(reminderLast!!) dest.writeLong(reminderLast)
dest.writeLong(reminderPeriod!!) dest.writeLong(reminderPeriod)
dest.writeLong(reminderSnooze!!) dest.writeLong(reminderSnooze)
dest.writeLong(repeatUntil!!) dest.writeLong(repeatUntil)
dest.writeLong(timerStart!!) dest.writeLong(timerStart)
dest.writeString(title) dest.writeString(title)
dest.writeString(remoteId) dest.writeString(remoteId)
dest.writeMap(transitoryData as Map<*, *>?) dest.writeMap(transitoryData as Map<*, *>?)
@ -419,16 +415,13 @@ class Task : Parcelable {
return trans != null 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 { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Task) return false if (other !is Task) return false
if (id != other.id) return false if (id != other.id) return false
if (title != other.title) return false if (title != other.title) return false
if (priority != other.priority) return false
if (dueDate != other.dueDate) return false if (dueDate != other.dueDate) return false
if (hideUntil != other.hideUntil) return false if (hideUntil != other.hideUntil) return false
if (creationDate != other.creationDate) return false if (creationDate != other.creationDate) return false
@ -456,8 +449,9 @@ class Task : Parcelable {
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = id?.hashCode() ?: 0 var result = id.hashCode()
result = 31 * result + (title?.hashCode() ?: 0) result = 31 * result + (title?.hashCode() ?: 0)
result = 31 * result + priority
result = 31 * result + dueDate.hashCode() result = 31 * result + dueDate.hashCode()
result = 31 * result + hideUntil.hashCode() result = 31 * result + hideUntil.hashCode()
result = 31 * result + creationDate.hashCode() result = 31 * result + creationDate.hashCode()
@ -465,17 +459,17 @@ class Task : Parcelable {
result = 31 * result + completionDate.hashCode() result = 31 * result + completionDate.hashCode()
result = 31 * result + deletionDate.hashCode() result = 31 * result + deletionDate.hashCode()
result = 31 * result + (notes?.hashCode() ?: 0) result = 31 * result + (notes?.hashCode() ?: 0)
result = 31 * result + estimatedSeconds!! result = 31 * result + estimatedSeconds
result = 31 * result + elapsedSeconds!! result = 31 * result + elapsedSeconds
result = 31 * result + timerStart.hashCode() result = 31 * result + timerStart.hashCode()
result = 31 * result + reminderFlags!! result = 31 * result + reminderFlags
result = 31 * result + reminderPeriod.hashCode() result = 31 * result + reminderPeriod.hashCode()
result = 31 * result + reminderLast.hashCode() result = 31 * result + reminderLast.hashCode()
result = 31 * result + reminderSnooze.hashCode() result = 31 * result + reminderSnooze.hashCode()
result = 31 * result + (recurrence?.hashCode() ?: 0) result = 31 * result + (recurrence?.hashCode() ?: 0)
result = 31 * result + repeatUntil.hashCode() result = 31 * result + repeatUntil.hashCode()
result = 31 * result + (calendarURI?.hashCode() ?: 0) result = 31 * result + (calendarURI?.hashCode() ?: 0)
result = 31 * result + (remoteId?.hashCode() ?: 0) result = 31 * result + remoteId.hashCode()
result = 31 * result + isCollapsed.hashCode() result = 31 * result + isCollapsed.hashCode()
result = 31 * result + parent.hashCode() result = 31 * result + parent.hashCode()
result = 31 * result + (parentUuid?.hashCode() ?: 0) result = 31 * result + (parentUuid?.hashCode() ?: 0)
@ -483,6 +477,10 @@ class Task : Parcelable {
return result return result
} }
override fun toString(): String {
return "Task(id=$id, title=$title, priority=$priority, 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)"
}
@Retention(AnnotationRetention.SOURCE) @Retention(AnnotationRetention.SOURCE)
@IntDef(Priority.HIGH, Priority.MEDIUM, Priority.LOW, Priority.NONE) @IntDef(Priority.HIGH, Priority.MEDIUM, Priority.LOW, Priority.NONE)
annotation class Priority { annotation class Priority {

@ -78,7 +78,7 @@ public class GCalHelper {
if (preferences.isDefaultCalendarSet()) { if (preferences.isDefaultCalendarSet()) {
Uri calendarUri = createTaskEvent(t, new ContentValues(), deleteEventIfExists); Uri calendarUri = createTaskEvent(t, new ContentValues(), deleteEventIfExists);
if (calendarUri != null) { if (calendarUri != null) {
t.setCalendarUri(calendarUri.toString()); t.setCalendarURI(calendarUri.toString());
} }
} }
} }
@ -137,14 +137,14 @@ public class GCalHelper {
AndroidCalendarEvent event = calendarEventProvider.getEvent(eventUri); AndroidCalendarEvent event = calendarEventProvider.getEvent(eventUri);
if (event == null) { if (event == null) {
task.setCalendarUri(""); task.setCalendarURI("");
return; return;
} }
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put(CalendarContract.Events.CALENDAR_ID, event.getCalendarId()); cv.put(CalendarContract.Events.CALENDAR_ID, event.getCalendarId());
Uri uri = createTaskEvent(task, cv, false); Uri uri = createTaskEvent(task, cv, false);
task.setCalendarUri(uri.toString()); task.setCalendarURI(uri.toString());
} }
public void createStartAndEndDate(Task task, ContentValues values) { public void createStartAndEndDate(Task task, ContentValues values) {

@ -35,6 +35,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import org.tasks.R; import org.tasks.R;
import org.tasks.Strings;
import org.tasks.analytics.Firebase; import org.tasks.analytics.Firebase;
import org.tasks.dialogs.DialogBuilder; import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.ForActivity; import org.tasks.injection.ForActivity;
@ -113,11 +114,16 @@ public class RepeatControlSet extends TaskEditControlFragment {
if (dueDate <= 0) { if (dueDate <= 0) {
dueDate = currentTimeMillis(); dueDate = currentTimeMillis();
} }
try { String recurrenceWithoutFrom = task.getRecurrenceWithoutFrom();
rrule = new RRule(task.getRecurrenceWithoutFrom()); if (Strings.isNullOrEmpty(recurrenceWithoutFrom)) {
rrule.setUntil(new DateTime(task.getRepeatUntil()).toDateValue());
} catch (ParseException e) {
rrule = null; rrule = null;
} else {
try {
rrule = new RRule(recurrenceWithoutFrom);
rrule.setUntil(new DateTime(task.getRepeatUntil()).toDateValue());
} catch (ParseException e) {
rrule = null;
}
} }
} else { } else {
String recurrence = savedInstanceState.getString(EXTRA_RECURRENCE); String recurrence = savedInstanceState.getString(EXTRA_RECURRENCE);

@ -88,7 +88,7 @@ public class TaskCreator {
&& gcalCreateEventEnabled && gcalCreateEventEnabled
&& isNullOrEmpty(task.getCalendarURI())) { && isNullOrEmpty(task.getCalendarURI())) {
Uri calendarUri = gcalHelper.createTaskEvent(task, new ContentValues()); Uri calendarUri = gcalHelper.createTaskEvent(task, new ContentValues());
task.setCalendarUri(calendarUri.toString()); task.setCalendarURI(calendarUri.toString());
} }
createTags(task); createTags(task);

@ -75,7 +75,7 @@ public class TaskDuplicator {
clone.setCreationDate(now()); clone.setCreationDate(now());
clone.setModificationDate(now()); clone.setModificationDate(now());
clone.setCompletionDate(0L); clone.setCompletionDate(0L);
clone.setCalendarUri(""); clone.setCalendarURI("");
clone.setUuid(null); clone.setUuid(null);
clone.suppressSync(); clone.suppressSync();
clone.suppressRefresh(); clone.suppressRefresh();

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

@ -66,7 +66,7 @@ public class CalendarEventProvider {
public void deleteEvent(Task task) { public void deleteEvent(Task task) {
String uri = task.getCalendarURI(); String uri = task.getCalendarURI();
task.setCalendarUri(""); task.setCalendarURI("");
deleteEvent(uri); deleteEvent(uri);
} }

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

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

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

@ -411,6 +411,23 @@ public class Migrations {
} }
}; };
private static final Migration MIGRATION_73_74 =
new Migration(73, 74) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE `tasks` RENAME TO `tasks-temp`");
database.execSQL("DROP INDEX `t_rid`");
database.execSQL("DROP INDEX `active_and_visible`");
database.execSQL("CREATE TABLE IF NOT EXISTS `tasks` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT, `importance` INTEGER NOT NULL, `dueDate` INTEGER NOT NULL, `hideUntil` INTEGER NOT NULL, `created` INTEGER NOT NULL, `modified` INTEGER NOT NULL, `completed` INTEGER NOT NULL, `deleted` INTEGER NOT NULL, `notes` TEXT, `estimatedSeconds` INTEGER NOT NULL, `elapsedSeconds` INTEGER NOT NULL, `timerStart` INTEGER NOT NULL, `notificationFlags` INTEGER NOT NULL, `notifications` INTEGER NOT NULL, `lastNotified` INTEGER NOT NULL, `snoozeTime` INTEGER NOT NULL, `recurrence` TEXT, `repeatUntil` INTEGER NOT NULL, `calendarUri` TEXT, `remoteId` TEXT, `collapsed` INTEGER NOT NULL, `parent` INTEGER NOT NULL, `parent_uuid` TEXT)");
database.execSQL(
"INSERT INTO `tasks` (`_id`, `title`, `importance`, `dueDate`, `hideUntil`, `created`, `modified`, `completed`, `deleted`, `notes`, `estimatedSeconds`, `elapsedSeconds`, `timerStart`, `notificationFlags`, `notifications`, `lastNotified`, `snoozeTime`, `recurrence`, `repeatUntil`, `calendarUri`, `remoteId`, `collapsed`, `parent`, `parent_uuid`) "
+ "SELECT `_id`, `title`, IFNULL(`importance`, 3), IFNULL(`dueDate`, 0), IFNULL(`hideUntil`, 0), IFNULL(`created`, 0), IFNULL(`modified`, 0), IFNULL(`completed`, 0), IFNULL(`deleted`, 0), `notes`, IFNULL(`estimatedSeconds`, 0), IFNULL(`elapsedSeconds`, 0), IFNULL(`timerStart`, 0), IFNULL(`notificationFlags`, 0), IFNULL(`notifications`, 0), IFNULL(`lastNotified`, 0), IFNULL(`snoozeTime`, 0), `recurrence`, IFNULL(`repeatUntil`, 0), `calendarUri`, `remoteId`, `collapsed`, IFNULL(`parent`, 0), `parent_uuid` FROM `tasks-temp`");
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `t_rid` ON `tasks` (`remoteId`)");
database.execSQL("CREATE INDEX IF NOT EXISTS `active_and_visible` ON `tasks` (`completed`, `deleted`, `hideUntil`)");
database.execSQL("DROP TABLE `tasks-temp`");
}
};
public static final Migration[] MIGRATIONS = public static final Migration[] MIGRATIONS =
new Migration[] { new Migration[] {
MIGRATION_35_36, MIGRATION_35_36,
@ -441,7 +458,8 @@ public class Migrations {
MIGRATION_69_70, MIGRATION_69_70,
MIGRATION_70_71, MIGRATION_70_71,
MIGRATION_71_72, MIGRATION_71_72,
MIGRATION_72_73 MIGRATION_72_73,
MIGRATION_73_74
}; };
private static Migration NOOP(int from, int to) { private static Migration NOOP(int from, int to) {

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

@ -18,6 +18,7 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.ReminderService; import com.todoroo.astrid.reminders.ReminderService;
import com.todoroo.astrid.repeats.RepeatTaskHelper; import com.todoroo.astrid.repeats.RepeatTaskHelper;
import com.todoroo.astrid.timers.TimerPlugin; import com.todoroo.astrid.timers.TimerPlugin;
import java.util.Objects;
import javax.inject.Inject; import javax.inject.Inject;
import org.tasks.LocalBroadcastManager; import org.tasks.LocalBroadcastManager;
import org.tasks.R; import org.tasks.R;
@ -89,9 +90,9 @@ public class AfterSaveWork extends InjectingWorker {
reminderService.scheduleAlarm(task); reminderService.scheduleAlarm(task);
boolean completionDateModified = boolean completionDateModified =
!task.getCompletionDate().equals(data.getLong(EXTRA_ORIG_COMPLETED, 0)); !Objects.equals(task.getCompletionDate(), data.getLong(EXTRA_ORIG_COMPLETED, 0));
boolean deletionDateModified = boolean deletionDateModified =
!task.getDeletionDate().equals(data.getLong(EXTRA_ORIG_DELETED, 0)); !Objects.equals(task.getDeletionDate(), data.getLong(EXTRA_ORIG_DELETED, 0));
boolean justCompleted = completionDateModified && task.isCompleted(); boolean justCompleted = completionDateModified && task.isCompleted();
boolean justDeleted = deletionDateModified && task.isDeleted(); boolean justDeleted = deletionDateModified && task.isDeleted();

@ -147,7 +147,7 @@ public class CalendarControlSet extends TaskEditControlFragment {
if (eventUri == null) { if (eventUri == null) {
calendarEventProvider.deleteEvent(task); calendarEventProvider.deleteEvent(task);
} else if (!calendarEntryExists(task.getCalendarURI())) { } else if (!calendarEntryExists(task.getCalendarURI())) {
task.setCalendarUri(""); task.setCalendarURI("");
} }
} }
@ -175,7 +175,7 @@ public class CalendarControlSet extends TaskEditControlFragment {
values.put(CalendarContract.Events.CALENDAR_ID, calendarId); values.put(CalendarContract.Events.CALENDAR_ID, calendarId);
Uri uri = gcalHelper.createTaskEvent(task, values); Uri uri = gcalHelper.createTaskEvent(task, values);
if (uri != null) { if (uri != null) {
task.setCalendarUri(uri.toString()); task.setCalendarURI(uri.toString());
} }
} catch (Exception e) { } catch (Exception e) {
Timber.e(e); Timber.e(e);

@ -14,14 +14,14 @@ import javax.inject.Inject
class CheckBoxProvider @Inject constructor(@param:ForActivity private val context: Context, private val colorProvider: ColorProvider) { class CheckBoxProvider @Inject constructor(@param: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) = fun getCheckBox(complete: Boolean, repeating: Boolean, priority: Int) =
getDrawable(getDrawableRes(complete, repeating), priority) getDrawable(getDrawableRes(complete, repeating), priority)
fun getWidgetCheckBox(task: Task): Bitmap { fun getWidgetCheckBox(task: Task): Bitmap {
val wrapped = DrawableUtil.getWrapped(context, getDrawableRes(task.isCompleted, task.isRecurring)) 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) return convertToBitmap(wrapped)
} }

Loading…
Cancel
Save