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()
taskDao.createNew(task)
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)
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.id!!, alarmTime.millis))
alarmDao.insert(Alarm(task.id, alarmTime.millis))
alarmService.scheduleAllAlarms()
}

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

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

@ -29,7 +29,7 @@ class TaskTest : InjectingTestCase() {
fun testReadTaskFromDb() {
val task = Task()
taskDao.createNew(task)
val fromDb = taskDao.fetch(task.id!!)
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.dueDate!!, 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.dueDate!!, 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.dueDate!!, 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

@ -206,7 +206,7 @@ class AdvancedRepeatTest {
}
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)
}

@ -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.dueDate!!)
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.dueDate!!)
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.dueDate!!)
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.dueDate!!)
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.dueDate!!)
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.dueDate!!)
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.dueDate!!)
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.dueDate!!)
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.dueDate!!)
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.dueDate!!)
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.dueDate!!)
date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.dayOfWeek, i + 1)
title = "Jog " + abrevDays[i]
task = taskCreator.createWithValues(title)
date = DateTimeUtils.newDateTime(task.dueDate!!)
date = DateTimeUtils.newDateTime(task.dueDate)
assertEquals(date.dayOfWeek, i + 1)
}
}

@ -39,7 +39,7 @@ class AppleRemindersTests {
fun readCreationDate() {
assertEquals(
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
@ -53,7 +53,7 @@ class AppleRemindersTests {
fun completed() {
assertEquals(
DateTime(2018, 4, 17, 13, 43, 2).millis,
vtodo("apple/basic_completed.txt").completionDate as Long)
vtodo("apple/basic_completed.txt").completionDate)
}
@Test

@ -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.id!!, "calendar"))
assertEquals(listOf(task.id!!), 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.id!!, "calendar"))
caldavDao.insert(CaldavTask(task.id, "calendar"))
assertTrue(caldavDao.getTasksWithTags().isEmpty())
}

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

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

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

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

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

@ -58,7 +58,7 @@ import org.tasks.notifications.NotificationDao;
CaldavAccount.class,
GoogleTaskAccount.class
},
version = 73)
version = 74)
public abstract class Database extends RoomDatabase {
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.PermaSql
import com.todoroo.astrid.data.Task
import com.todoroo.astrid.data.Task.Companion.NO_ID
import com.todoroo.astrid.helper.UUIDHelper
import org.tasks.BuildConfig
import org.tasks.data.Place
@ -225,7 +226,7 @@ abstract class TaskDao(private val database: Database) {
* success.
*/
@JvmOverloads
fun save(task: Task, original: Task? = fetch(task.id!!)) {
fun save(task: Task, original: Task? = fetch(task.id)) {
if (!task.insignificantChange(original)) {
task.modificationDate = DateUtilities.now()
}
@ -241,11 +242,11 @@ abstract class TaskDao(private val database: Database) {
abstract fun update(task: Task): Int
fun createNew(task: Task) {
task.id = null
task.id = NO_ID
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)

@ -29,76 +29,76 @@ class Task : Parcelable {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "_id")
@Transient
var id: Long? = NO_ID
var id = NO_ID
/** Name of Task */
@ColumnInfo(name = "title")
var title: String? = ""
var title: String? = null
@ColumnInfo(name = "importance")
var priority: Int? = Priority.NONE
var priority = Priority.NONE
/** Unixtime Task is due, 0 if not set */
@ColumnInfo(name = "dueDate")
var dueDate: Long? = 0L
var dueDate = 0L
/** Unixtime Task should be hidden until, 0 if not set */
@ColumnInfo(name = "hideUntil")
var hideUntil: Long? = 0L
var hideUntil = 0L
/** Unixtime Task was created */
@ColumnInfo(name = "created")
var creationDate: Long? = 0L
var creationDate = 0L
/** Unixtime Task was last touched */
@ColumnInfo(name = "modified")
var modificationDate: Long? = 0L
var modificationDate = 0L
/** Unixtime Task was completed. 0 means active */
@ColumnInfo(name = "completed")
var completionDate: Long? = 0L
var completionDate = 0L
/** Unixtime Task was deleted. 0 means not deleted */
@ColumnInfo(name = "deleted")
var deletionDate: Long? = 0L
var deletionDate = 0L
// --- data access boilerplate
@ColumnInfo(name = "notes")
var notes: String? = ""
var notes: String? = null
@ColumnInfo(name = "estimatedSeconds")
var estimatedSeconds: Int? = 0
var estimatedSeconds = 0
@ColumnInfo(name = "elapsedSeconds")
var elapsedSeconds: Int? = 0
var elapsedSeconds = 0
@ColumnInfo(name = "timerStart")
var timerStart: Long? = 0L
var timerStart = 0L
/** Flags for when to send reminders */
@ColumnInfo(name = "notificationFlags")
var reminderFlags: Int? = 0
var reminderFlags = 0
/** Reminder period, in milliseconds. 0 means disabled */
@ColumnInfo(name = "notifications")
var reminderPeriod: Long? = 0L
// --- parcelable helpers
var reminderPeriod = 0L
/** Unixtime the last reminder was triggered */
@ColumnInfo(name = "lastNotified")
var reminderLast: Long? = 0L
// --- data access methods
var reminderLast = 0L
/** Unixtime snooze is set (0 -> no snooze) */
@ColumnInfo(name = "snoozeTime")
var reminderSnooze: Long? = 0L
var reminderSnooze = 0L
@ColumnInfo(name = "recurrence")
var recurrence: String? = ""
var recurrence: String? = null
@ColumnInfo(name = "repeatUntil")
var repeatUntil: Long? = 0L
var repeatUntil = 0L
@ColumnInfo(name = "calendarUri")
var calendarURI: String? = ""
var calendarURI: String? = null
/** Remote id */
@ColumnInfo(name = "remoteId")
@ -109,7 +109,7 @@ class Task : Parcelable {
@ColumnInfo(name = "parent")
@Transient
var parent: Long = 0
var parent = 0L
@ColumnInfo(name = "parent_uuid")
var parentUuid: String? = null
@ -166,35 +166,35 @@ class Task : Parcelable {
repeatUntil = parcel.readLong()
timerStart = parcel.readLong()
title = parcel.readString()
remoteId = parcel.readString()
remoteId = parcel.readString() ?: NO_UUID
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
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
get() = completionDate > 0
/** Checks whether task is deleted. Will return false if DELETION_DATE not read */
val isDeleted
get() = deletionDate!! > 0
get() = deletionDate > 0
/** Checks whether task is hidden. Requires HIDDEN_UNTIL */
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 */
fun hasDueDate() = dueDate!! > 0
fun hasDueDate() = dueDate > 0
/**
* Create hide until for this task.
@ -205,9 +205,9 @@ class Task : Parcelable {
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_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")
}
@ -224,25 +224,25 @@ class Task : Parcelable {
}
/** 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
get() {
val dueDate = dueDate
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) {
if (dueDate!! > 0) {
if (hideUntil!! > 0) {
hideUntil = if (newDueDate > 0) hideUntil!! + newDueDate - dueDate!! else 0
if (dueDate > 0) {
if (hideUntil > 0) {
hideUntil = if (newDueDate > 0) hideUntil + newDueDate - dueDate else 0
}
}
dueDate = newDueDate
@ -259,10 +259,6 @@ class Task : Parcelable {
return !Strings.isNullOrEmpty(notes)
}
fun setCalendarUri(calendarUri: String?) {
calendarURI = calendarUri
}
val isNotifyModeNonstop: Boolean
get() = isReminderFlagSet(NOTIFY_MODE_NONSTOP)
@ -276,7 +272,7 @@ class Task : Parcelable {
get() = isReminderFlagSet(NOTIFY_AT_DEADLINE)
private fun isReminderFlagSet(flag: Int): Boolean {
return reminderFlags!! and flag > 0
return reminderFlags and flag > 0
}
val isNew: Boolean
@ -288,24 +284,24 @@ class Task : Parcelable {
/** {@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.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.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<*, *>?)
@ -419,16 +415,13 @@ class Task : Parcelable {
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 (priority != other.priority) return false
if (dueDate != other.dueDate) return false
if (hideUntil != other.hideUntil) return false
if (creationDate != other.creationDate) return false
@ -456,8 +449,9 @@ class Task : Parcelable {
}
override fun hashCode(): Int {
var result = id?.hashCode() ?: 0
var result = id.hashCode()
result = 31 * result + (title?.hashCode() ?: 0)
result = 31 * result + priority
result = 31 * result + dueDate.hashCode()
result = 31 * result + hideUntil.hashCode()
result = 31 * result + creationDate.hashCode()
@ -465,17 +459,17 @@ class Task : Parcelable {
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 + estimatedSeconds
result = 31 * result + elapsedSeconds
result = 31 * result + timerStart.hashCode()
result = 31 * result + reminderFlags!!
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 + remoteId.hashCode()
result = 31 * result + isCollapsed.hashCode()
result = 31 * result + parent.hashCode()
result = 31 * result + (parentUuid?.hashCode() ?: 0)
@ -483,6 +477,10 @@ class Task : Parcelable {
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)
@IntDef(Priority.HIGH, Priority.MEDIUM, Priority.LOW, Priority.NONE)
annotation class Priority {

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

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

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

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

@ -83,12 +83,12 @@ class iCalendar @Inject constructor(
}
val existing: Location? = locationDao.getGeofences(taskId)
if (existing == null) {
val geofence = Geofence(place!!.uid, preferences)
val geofence = Geofence(place.uid, preferences)
geofence.task = taskId
geofence.id = locationDao.insert(geofence)
} else if (place != existing.place) {
val geofence = existing.geofence
geofence.place = place!!.uid
geofence.place = place.uid
locationDao.update(geofence)
geofenceApi.update(existing.place)
}
@ -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.id!!).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.id!!)
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.id!!, 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.id!!).forEach {
locationDao.getActiveGeofences(task.id).forEach {
locationDao.delete(it.geofence)
geofenceApi.update(it.place)
}
} else {
setPlace(task.id!!, geo)
setPlace(task.id, geo)
}
tagDao.applyTags(task, tagDataDao, getTags(remote.categories))
task.suppressSync()

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

@ -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.id!!, 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.id!!
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 { it.id!! }, keep)
val tags = tagsToDelete(sublist.map(Task::id), keep)
deleteTags(tags)
modified.addAll(tags.map(Tag::task))
}
for (task in tasks) {
val added = selected subtract getTagDataForTask(task.id!!)
val added = selected subtract getTagDataForTask(task.id)
if (added.isNotEmpty()) {
modified.add(task.id!!)
modified.add(task.id)
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 =
new Migration[] {
MIGRATION_35_36,
@ -441,7 +458,8 @@ public class Migrations {
MIGRATION_69_70,
MIGRATION_70_71,
MIGRATION_71_72,
MIGRATION_72_73
MIGRATION_72_73,
MIGRATION_73_74
};
private static Migration NOOP(int from, int to) {

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

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

@ -147,7 +147,7 @@ public class CalendarControlSet extends TaskEditControlFragment {
if (eventUri == null) {
calendarEventProvider.deleteEvent(task);
} 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);
Uri uri = gcalHelper.createTaskEvent(task, values);
if (uri != null) {
task.setCalendarUri(uri.toString());
task.setCalendarURI(uri.toString());
}
} catch (Exception 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) {
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