Remove extra alarm constructor

pull/2906/head
Alex Baker 6 months ago
parent 4c245edbb4
commit 5bd0cef42e

@ -40,7 +40,7 @@ class AlarmJobServiceTest : InjectingTestCase() {
)
)
)
alarmService.synchronizeAlarms(1, mutableSetOf(Alarm(0, 0, Alarm.TYPE_REL_END)))
alarmService.synchronizeAlarms(1, mutableSetOf(Alarm(type = Alarm.TYPE_REL_END)))
testResults(emptyList(), DateTime(2024, 5, 18, 18, 0).millis)
}
@ -57,7 +57,7 @@ class AlarmJobServiceTest : InjectingTestCase() {
)
)
)
alarmService.synchronizeAlarms(1, mutableSetOf(Alarm(0, 0, Alarm.TYPE_REL_END)))
alarmService.synchronizeAlarms(1, mutableSetOf(Alarm(type = Alarm.TYPE_REL_END)))
testResults(
listOf(
@ -87,9 +87,7 @@ class AlarmJobServiceTest : InjectingTestCase() {
1,
mutableSetOf(
Alarm(
0,
0,
Alarm.TYPE_REL_END,
type = Alarm.TYPE_REL_END,
repeat = 1,
interval = TimeUnit.HOURS.toMillis(6)
)
@ -123,8 +121,8 @@ class AlarmJobServiceTest : InjectingTestCase() {
alarmService.synchronizeAlarms(
1,
mutableSetOf(
Alarm(0, 0, Alarm.TYPE_REL_END),
Alarm(0, DateTimeUtils2.currentTimeMillis(), Alarm.TYPE_SNOOZE)
Alarm(type = Alarm.TYPE_REL_END),
Alarm(time = DateTimeUtils2.currentTimeMillis(), type = Alarm.TYPE_SNOOZE)
)
)
@ -160,11 +158,10 @@ class AlarmJobServiceTest : InjectingTestCase() {
alarmService.synchronizeAlarms(
1,
mutableSetOf(
Alarm(0, 0, Alarm.TYPE_REL_END),
Alarm(type = Alarm.TYPE_REL_END),
Alarm(
0,
DateTimeUtils2.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5),
Alarm.TYPE_SNOOZE
time = DateTimeUtils2.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5),
type = Alarm.TYPE_SNOOZE
)
)
)
@ -190,7 +187,7 @@ class AlarmJobServiceTest : InjectingTestCase() {
)
alarmService.synchronizeAlarms(
1,
mutableSetOf(Alarm(0, 0, Alarm.TYPE_REL_END))
mutableSetOf(Alarm(type = Alarm.TYPE_REL_END))
)
testResults(
@ -214,7 +211,7 @@ class AlarmJobServiceTest : InjectingTestCase() {
)
alarmService.synchronizeAlarms(
1,
mutableSetOf(Alarm(0, 0, Alarm.TYPE_REL_END))
mutableSetOf(Alarm(type = Alarm.TYPE_REL_END))
)
testResults(
@ -238,7 +235,7 @@ class AlarmJobServiceTest : InjectingTestCase() {
)
alarmService.synchronizeAlarms(
1,
mutableSetOf(Alarm(0, 0, Alarm.TYPE_REL_END))
mutableSetOf(Alarm(type = Alarm.TYPE_REL_END))
)
testResults(

@ -2,20 +2,23 @@ package org.tasks.data
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.astrid.dao.TaskDao
import org.tasks.data.entity.Task
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.tasks.SuspendFreeze.Companion.freezeAt
import org.tasks.caldav.GeoUtils.toLikeString
import org.tasks.data.entity.Alarm.Companion.TYPE_SNOOZE
import org.tasks.data.dao.AlarmDao
import org.tasks.data.dao.LocationDao
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.TYPE_SNOOZE
import org.tasks.data.entity.Geofence
import org.tasks.data.entity.Place
import org.tasks.data.entity.Task
import org.tasks.date.DateTimeUtils.newDateTime
import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule
@ -122,7 +125,13 @@ class LocationDaoTest : InjectingTestCase() {
val place = Place()
locationDao.insert(place)
val task = taskDao.createNew(newTask())
alarmDao.insert(Alarm(task, newDateTime().plusMinutes(15).millis, TYPE_SNOOZE))
alarmDao.insert(
Alarm(
task = task,
time = newDateTime().plusMinutes(15).millis,
type = TYPE_SNOOZE
)
)
locationDao.insert(Geofence(task = task, place = place.uid, isArrival = true))
assertTrue(locationDao.getArrivalGeofences(place.uid!!, currentTimeMillis()).isEmpty())
@ -135,7 +144,13 @@ class LocationDaoTest : InjectingTestCase() {
val place = Place()
locationDao.insert(place)
val task = taskDao.createNew(newTask())
alarmDao.insert(Alarm(task, newDateTime().plusMinutes(15).millis, TYPE_SNOOZE))
alarmDao.insert(
Alarm(
task = task,
time = newDateTime().plusMinutes(15).millis,
type = TYPE_SNOOZE
)
)
locationDao.insert(Geofence(task = task, place = place.uid, isDeparture = true))
assertTrue(locationDao.getDepartureGeofences(place.uid!!, currentTimeMillis()).isEmpty())
@ -148,7 +163,13 @@ class LocationDaoTest : InjectingTestCase() {
val place = Place()
locationDao.insert(place)
val task = taskDao.createNew(newTask())
alarmDao.insert(Alarm(task, newDateTime().minusMinutes(15).millis, TYPE_SNOOZE))
alarmDao.insert(
Alarm(
task = task,
time = newDateTime().minusMinutes(15).millis,
type = TYPE_SNOOZE
)
)
val geofence = Geofence(task = task, place = place.uid, isArrival = true)
.let { it.copy(id = locationDao.insert(it)) }
@ -164,7 +185,13 @@ class LocationDaoTest : InjectingTestCase() {
val place = Place()
locationDao.insert(place)
val task = taskDao.createNew(newTask())
alarmDao.insert(Alarm(task, newDateTime().minusMinutes(15).millis, TYPE_SNOOZE))
alarmDao.insert(
Alarm(
task = task,
time = newDateTime().minusMinutes(15).millis,
type = TYPE_SNOOZE
)
)
val geofence = Geofence(task = task, place = place.uid, isDeparture = true)
.let { it.copy(id = locationDao.insert(it)) }

@ -1,11 +1,13 @@
package org.tasks.opentasks
import com.natpryce.makeiteasy.MakeItEasy.with
import org.tasks.data.entity.Task
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.tasks.SuspendFreeze.Companion.freezeAt
import org.tasks.TestUtilities.withTZ
@ -13,11 +15,12 @@ import org.tasks.caldav.iCalendar.Companion.collapsed
import org.tasks.caldav.iCalendar.Companion.order
import org.tasks.caldav.iCalendar.Companion.parent
import org.tasks.caldav.iCalendar.Companion.snooze
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.TYPE_SNOOZE
import org.tasks.data.dao.AlarmDao
import org.tasks.data.dao.TagDao
import org.tasks.data.dao.TagDataDao
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.TYPE_SNOOZE
import org.tasks.data.entity.Task
import org.tasks.injection.ProductionModule
import org.tasks.makers.CaldavTaskMaker
import org.tasks.makers.CaldavTaskMaker.CALENDAR
@ -33,7 +36,7 @@ import org.tasks.makers.TaskMaker.COLLAPSED
import org.tasks.makers.TaskMaker.ORDER
import org.tasks.makers.TaskMaker.newTask
import org.tasks.time.DateTime
import java.util.*
import java.util.TimeZone
import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@ -213,7 +216,14 @@ class OpenTasksPropertiesTests : OpenTasksTest() {
?.let { taskDao.fetch(it.task) }
assertEquals(
listOf(Alarm(task!!.id, 1612972355000, TYPE_SNOOZE).apply { id = 1 }),
listOf(
Alarm(
id = 1,
task = task!!.id,
time = 1612972355000,
type = TYPE_SNOOZE
)
),
alarmDao.getAlarms(task.id)
)
}
@ -222,7 +232,13 @@ class OpenTasksPropertiesTests : OpenTasksTest() {
fun pushSnoozeTime() = withTZ(CHICAGO) {
val (listId, list) = openTaskDao.insertList()
val taskId = taskDao.createNew(newTask())
alarmDao.insert(Alarm(taskId, DateTime(2021, 2, 4, 13, 30).millis, TYPE_SNOOZE))
alarmDao.insert(
Alarm(
task = taskId,
time = DateTime(2021, 2, 4, 13, 30).millis,
type = TYPE_SNOOZE
)
)
caldavDao.insert(newCaldavTask(
with(CALENDAR, list.uuid),
@ -241,7 +257,13 @@ class OpenTasksPropertiesTests : OpenTasksTest() {
fun dontPushLapsedSnoozeTime() = withTZ(CHICAGO) {
val (listId, list) = openTaskDao.insertList()
val taskId = taskDao.createNew(newTask())
alarmDao.insert(Alarm(taskId, DateTime(2021, 2, 4, 13, 30).millis, TYPE_SNOOZE))
alarmDao.insert(
Alarm(
task = taskId,
time = DateTime(2021, 2, 4, 13, 30).millis,
type = TYPE_SNOOZE
)
)
caldavDao.insert(newCaldavTask(
with(CALENDAR, list.uuid),
@ -264,10 +286,11 @@ class OpenTasksPropertiesTests : OpenTasksTest() {
val task = caldavDao.getTaskByRemoteId(list.uuid!!, "4CBBC669-70E3-474D-A0A3-0FC42A14A5A5")
?: throw IllegalStateException("Missing task")
val snooze = alarmDao.getSnoozed(listOf(task.task))
assertEquals(1, snooze.size)
alarmDao.delete(snooze.first())
assertTrue(alarmDao.getSnoozed(listOf(task.task)).isEmpty())
assertEquals(
listOf(Alarm(1, task.id, DateTime(2021, 2, 10, 9, 52, 35).millis, TYPE_SNOOZE)),
alarmDao.getAlarms(1)
)
alarmDao.deleteSnoozed(listOf(1))
taskDao.touch(task.task)
synchronizer.sync()

@ -1,6 +1,5 @@
package org.tasks.ui.editviewmodel
import org.tasks.data.entity.Task
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
@ -8,9 +7,10 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.tasks.data.createDueDate
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.whenOverdue
import org.tasks.data.createDueDate
import org.tasks.data.entity.Task
import org.tasks.injection.ProductionModule
import org.tasks.makers.TaskMaker.newTask
import org.tasks.time.DateTimeUtils2.currentTimeMillis
@ -34,7 +34,14 @@ class ReminderTests : BaseTaskEditViewModelTest() {
save()
assertEquals(
listOf(Alarm(1, 0, Alarm.TYPE_REL_START).apply { id = 1 }),
listOf(
Alarm(
id = 1,
task = 1,
time = 0,
type = Alarm.TYPE_REL_START
)
),
alarmDao.getAlarms(task.id)
)
}
@ -55,7 +62,14 @@ class ReminderTests : BaseTaskEditViewModelTest() {
save()
assertEquals(
listOf(Alarm(1, 0, Alarm.TYPE_REL_END).apply { id = 1 }),
listOf(
Alarm(
id = 1,
task = 1,
time = 0,
type = Alarm.TYPE_REL_END
)
),
alarmDao.getAlarms(task.id)
)
}

@ -68,8 +68,8 @@ class AlarmService @Inject constructor(
suspend fun snooze(time: Long, taskIds: List<Long>) {
notificationManager.cancel(taskIds)
alarmDao.getSnoozed(taskIds).let { alarmDao.delete(it) }
taskIds.map { Alarm(it, time, TYPE_SNOOZE) }.let { alarmDao.insert(it) }
alarmDao.deleteSnoozed(taskIds)
alarmDao.insert(taskIds.map { Alarm(task = it, time = time, type = TYPE_SNOOZE) })
taskDao.touch(taskIds)
workManager.triggerNotifications()
}

@ -7,35 +7,35 @@ import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.GtasksFilter
import com.todoroo.astrid.api.PermaSql
import com.todoroo.astrid.dao.TaskDao
import org.tasks.data.entity.Task
import org.tasks.data.entity.Task.Companion.DUE_DATE
import org.tasks.data.entity.Task.Companion.HIDE_UNTIL
import org.tasks.data.entity.Task.Companion.HIDE_UNTIL_NONE
import org.tasks.data.entity.Task.Companion.IMPORTANCE
import com.todoroo.astrid.gcal.GCalHelper
import org.tasks.data.UUIDHelper
import com.todoroo.astrid.utility.TitleParser.parse
import org.tasks.R
import org.tasks.Strings.isNullOrEmpty
import org.tasks.data.GoogleTask
import org.tasks.data.UUIDHelper
import org.tasks.data.createDueDate
import org.tasks.data.createGeofence
import org.tasks.data.createHideUntil
import org.tasks.data.dao.AlarmDao
import org.tasks.data.dao.CaldavDao
import org.tasks.data.dao.GoogleTaskDao
import org.tasks.data.dao.LocationDao
import org.tasks.data.dao.TagDao
import org.tasks.data.dao.TagDataDao
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.TYPE_RANDOM
import org.tasks.data.entity.Alarm.Companion.whenDue
import org.tasks.data.entity.Alarm.Companion.whenOverdue
import org.tasks.data.entity.Alarm.Companion.whenStarted
import org.tasks.data.dao.AlarmDao
import org.tasks.data.dao.CaldavDao
import org.tasks.data.entity.CaldavTask
import org.tasks.data.GoogleTask
import org.tasks.data.dao.GoogleTaskDao
import org.tasks.data.dao.LocationDao
import org.tasks.data.entity.Place
import org.tasks.data.entity.Tag
import org.tasks.data.dao.TagDao
import org.tasks.data.entity.TagData
import org.tasks.data.dao.TagDataDao
import org.tasks.data.createDueDate
import org.tasks.data.createGeofence
import org.tasks.data.createHideUntil
import org.tasks.data.entity.Task
import org.tasks.data.entity.Task.Companion.DUE_DATE
import org.tasks.data.entity.Task.Companion.HIDE_UNTIL
import org.tasks.data.entity.Task.Companion.HIDE_UNTIL_NONE
import org.tasks.data.entity.Task.Companion.IMPORTANCE
import org.tasks.preferences.DefaultFilterProvider
import org.tasks.preferences.Preferences
import org.tasks.time.DateTimeUtils.startOfDay
@ -235,7 +235,7 @@ class TaskCreator @Inject constructor(
}
}
if (randomReminder > 0) {
add(Alarm(id, randomReminder, TYPE_RANDOM))
add(Alarm(task = id, time = randomReminder, type = TYPE_RANDOM))
}
}
}

@ -1,23 +1,23 @@
package com.todoroo.astrid.service
import com.todoroo.astrid.dao.TaskDao
import org.tasks.data.entity.Task
import org.tasks.data.entity.Task.Companion.NO_ID
import com.todoroo.astrid.gcal.GCalHelper
import org.tasks.LocalBroadcastManager
import org.tasks.data.entity.Alarm
import org.tasks.data.dao.AlarmDao
import org.tasks.data.entity.Attachment
import org.tasks.data.dao.CaldavDao
import org.tasks.data.entity.CaldavTask
import org.tasks.data.entity.Geofence
import org.tasks.data.dao.GoogleTaskDao
import org.tasks.data.dao.LocationDao
import org.tasks.data.entity.Tag
import org.tasks.data.dao.TagDao
import org.tasks.data.dao.TagDataDao
import org.tasks.data.dao.TaskAttachmentDao
import org.tasks.data.db.DbUtils.dbchunk
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Attachment
import org.tasks.data.entity.CaldavTask
import org.tasks.data.entity.Geofence
import org.tasks.data.entity.Tag
import org.tasks.data.entity.Task
import org.tasks.data.entity.Task.Companion.NO_ID
import org.tasks.preferences.Preferences
import org.tasks.time.DateTimeUtils2.currentTimeMillis
import javax.inject.Inject
@ -96,7 +96,7 @@ class TaskDuplicator @Inject constructor(
}
val alarms = alarmDao.getAlarms(task.id)
if (alarms.isNotEmpty()) {
alarmDao.insert(alarms.map { Alarm(clone.id, it.time, it.type) })
alarmDao.insert(alarms.map { Alarm(task = clone.id, time = it.time, type = it.type) })
}
gcalHelper.createTaskEventIfEnabled(clone)
taskDao.save(clone, null) // TODO: delete me

@ -31,7 +31,7 @@ import org.tasks.dialogs.DialogBuilder
import org.tasks.dialogs.MyTimePickerDialog
import org.tasks.scheduling.NotificationSchedulerIntentService
import org.tasks.ui.TaskEditControlFragment
import java.util.*
import java.util.Locale
import javax.inject.Inject
@AndroidEntryPoint
@ -98,7 +98,7 @@ class ReminderControlSet : TaskEditControlFragment() {
data.getLongExtra(MyTimePickerDialog.EXTRA_TIMESTAMP, 0L)
val replace: Alarm? = data.getParcelableExtra(EXTRA_REPLACE)
replace?.let { viewModel.removeAlarm(it) }
viewModel.addAlarm(Alarm(0, timestamp, TYPE_DATE_TIME))
viewModel.addAlarm(Alarm(time = timestamp, type = TYPE_DATE_TIME))
}
AlarmRow(
locale = locale,

@ -67,7 +67,12 @@ internal fun VAlarm.toAlarm(): Alarm? {
else ->
return null
}
return Alarm(0L, time, type, repeat?.count ?: 0, duration?.toMillis() ?: 0)
return Alarm(
time = time,
type = type,
repeat = repeat?.count ?: 0,
interval = duration?.toMillis() ?: 0
)
}
private fun net.fortuna.ical4j.model.property.Duration.toMillis() = duration.toMillis()

@ -28,27 +28,27 @@ import org.tasks.caldav.GeoUtils.toGeo
import org.tasks.caldav.GeoUtils.toLikeString
import org.tasks.caldav.extensions.toAlarms
import org.tasks.caldav.extensions.toVAlarms
import org.tasks.data.createDueDate
import org.tasks.data.createGeofence
import org.tasks.data.createHideUntil
import org.tasks.data.dao.AlarmDao
import org.tasks.data.dao.CaldavDao
import org.tasks.data.dao.LocationDao
import org.tasks.data.dao.TagDao
import org.tasks.data.dao.TagDataDao
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.TYPE_RANDOM
import org.tasks.data.entity.Alarm.Companion.TYPE_SNOOZE
import org.tasks.data.dao.AlarmDao
import org.tasks.data.entity.CaldavAccount
import org.tasks.data.entity.CaldavCalendar
import org.tasks.data.entity.CaldavCalendar.Companion.ACCESS_READ_ONLY
import org.tasks.data.dao.CaldavDao
import org.tasks.data.entity.CaldavTask
import org.tasks.data.dao.LocationDao
import org.tasks.data.entity.Place
import org.tasks.data.dao.TagDao
import org.tasks.data.entity.TagData
import org.tasks.data.dao.TagDataDao
import org.tasks.data.entity.Task.Companion.HIDE_UNTIL_SPECIFIC_DAY
import org.tasks.data.entity.Task.Companion.HIDE_UNTIL_SPECIFIC_DAY_TIME
import org.tasks.data.entity.Task.Companion.URGENCY_SPECIFIC_DAY
import org.tasks.data.entity.Task.Companion.URGENCY_SPECIFIC_DAY_TIME
import org.tasks.data.createDueDate
import org.tasks.data.createGeofence
import org.tasks.data.createHideUntil
import org.tasks.date.DateTimeUtils.newDateTime
import org.tasks.date.DateTimeUtils.toDateTime
import org.tasks.date.DateTimeUtils.toLocal
@ -504,7 +504,7 @@ class iCalendar @Inject constructor(
val Task.reminders: List<Alarm>
get() = alarms.filtered.toAlarms().let { alarms ->
snooze?.let { time -> alarms.plus(Alarm(0, time, TYPE_SNOOZE))} ?: alarms
snooze?.let { time -> alarms.plus(Alarm(time = time, type = TYPE_SNOOZE))} ?: alarms
}
internal fun getDateTime(timestamp: Long): DateTime {

@ -3,14 +3,31 @@ package org.tasks.compose
import android.content.res.Configuration
import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.*
import androidx.compose.material.AlertDialog
import androidx.compose.material.Divider
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.RadioButton
import androidx.compose.material.Text
import androidx.compose.material.TextFieldDefaults
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Autorenew
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.ExperimentalComposeUiApi
@ -58,7 +75,7 @@ object AddReminderDialog {
confirmButton = {
Constants.TextButton(text = R.string.ok, onClick = {
time.value.takeIf { it > 0 }?.let { i ->
addAlarm(Alarm(0, i * units.millis, TYPE_RANDOM))
addAlarm(Alarm(time = i * units.millis, type = TYPE_RANDOM))
closeDialog()
}
})
@ -110,7 +127,6 @@ object AddReminderDialog {
time.value.takeIf { it >= 0 }?.let { i ->
addAlarm(
Alarm(
task = 0,
time = -1 * i * units.millis,
type = TYPE_REL_END,
repeat = repeat.value,

@ -168,7 +168,7 @@ class TaskEditViewModel @Inject constructor(
add(Alarm.whenOverdue(0))
}
if (task.randomReminder > 0) {
add(Alarm(0, task.randomReminder, Alarm.TYPE_RANDOM))
add(Alarm(time = task.randomReminder, type = Alarm.TYPE_RANDOM))
}
}
} else {

@ -2,15 +2,13 @@ package com.todoroo.astrid.alarms
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.andlib.utility.DateUtilities.ONE_WEEK
import org.tasks.data.entity.Task.Companion.HIDE_UNTIL_DUE
import org.tasks.data.entity.Task.Companion.HIDE_UNTIL_DUE_TIME
import org.tasks.data.entity.Task.Companion.URGENCY_SPECIFIC_DAY_TIME
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Test
import org.tasks.Freeze.Companion.freezeAt
import org.tasks.data.createDueDate
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.TYPE_DATE_TIME
import org.tasks.data.entity.Alarm.Companion.TYPE_RANDOM
@ -20,7 +18,9 @@ import org.tasks.data.entity.Alarm.Companion.TYPE_SNOOZE
import org.tasks.data.entity.Alarm.Companion.whenDue
import org.tasks.data.entity.Alarm.Companion.whenOverdue
import org.tasks.data.entity.Alarm.Companion.whenStarted
import org.tasks.data.createDueDate
import org.tasks.data.entity.Task.Companion.HIDE_UNTIL_DUE
import org.tasks.data.entity.Task.Companion.HIDE_UNTIL_DUE_TIME
import org.tasks.data.entity.Task.Companion.URGENCY_SPECIFIC_DAY_TIME
import org.tasks.date.DateTimeUtils.newDateTime
import org.tasks.date.DateTimeUtils.toDateTime
import org.tasks.makers.AlarmEntryMaker.TIME
@ -58,7 +58,7 @@ class AlarmCalculatorTest {
assertNull(
alarmCalculator.toAlarmEntry(
newTask(with(REMINDER_LAST, now)),
Alarm(0L, now.millis, TYPE_DATE_TIME)
Alarm(time = now.millis, type = TYPE_DATE_TIME)
)
)
}
@ -67,7 +67,7 @@ class AlarmCalculatorTest {
fun dateTimeReminder() {
val alarm = alarmCalculator.toAlarmEntry(
newTask(with(REMINDER_LAST, now)),
Alarm(0L, now.millis + 1, TYPE_DATE_TIME)
Alarm(time = now.millis + 1, type = TYPE_DATE_TIME)
)
assertEquals(newAlarmEntry(with(TIME, now.plusMillis(1)), with(TYPE, TYPE_DATE_TIME)), alarm)
@ -77,7 +77,7 @@ class AlarmCalculatorTest {
fun dontIgnoreOldSnooze() {
val alarm = alarmCalculator.toAlarmEntry(
newTask(with(REMINDER_LAST, now)),
Alarm(0L, now.millis, TYPE_SNOOZE)
Alarm(time = now.millis, type = TYPE_SNOOZE)
)
assertEquals(
@ -148,7 +148,7 @@ class AlarmCalculatorTest {
freezeAt(DateTime(2023, 11, 3, 17, 13)) {
val alarm = alarmCalculator.toAlarmEntry(
newTask(with(DUE_DATE, newDateTime())),
Alarm(0L, DAYS.toMillis(1), TYPE_REL_END)
Alarm(time = DAYS.toMillis(1), type = TYPE_REL_END)
)
assertEquals(
@ -165,7 +165,7 @@ class AlarmCalculatorTest {
fun scheduleRelativeAfterDueTime() = runBlocking {
val alarm = alarmCalculator.toAlarmEntry(
newTask(with(DUE_TIME, now)),
Alarm(0, DAYS.toMillis(1), TYPE_REL_END)
Alarm(time = DAYS.toMillis(1), type = TYPE_REL_END)
)
assertEquals(
@ -182,7 +182,7 @@ class AlarmCalculatorTest {
freezeAt(DateTime(2023, 11, 3, 17, 13)) {
val alarm = alarmCalculator.toAlarmEntry(
newTask(with(DUE_DATE, newDateTime()), with(HIDE_TYPE, HIDE_UNTIL_DUE)),
Alarm(0, DAYS.toMillis(1), TYPE_REL_START)
Alarm(time = DAYS.toMillis(1), type = TYPE_REL_START)
)
assertEquals(
@ -199,7 +199,7 @@ class AlarmCalculatorTest {
fun scheduleRelativeAfterStartTime() = runBlocking {
val alarm = alarmCalculator.toAlarmEntry(
newTask(with(DUE_TIME, now), with(HIDE_TYPE, HIDE_UNTIL_DUE_TIME)),
Alarm(0, DAYS.toMillis(1), TYPE_REL_START)
Alarm(time = DAYS.toMillis(1), type = TYPE_REL_START)
)
assertEquals(
@ -215,7 +215,7 @@ class AlarmCalculatorTest {
fun scheduleFirstRepeatReminder() = runBlocking {
val alarm = alarmCalculator.toAlarmEntry(
newTask(with(DUE_TIME, now), with(REMINDER_LAST, now.plusMinutes(4))),
Alarm(0, 0, TYPE_REL_END, 1, MINUTES.toMillis(5))
Alarm(type = TYPE_REL_END, repeat = 1, interval = MINUTES.toMillis(5))
)
assertEquals(
@ -231,7 +231,7 @@ class AlarmCalculatorTest {
fun scheduleSecondRepeatReminder() = runBlocking {
val alarm = alarmCalculator.toAlarmEntry(
newTask(with(DUE_TIME, now), with(REMINDER_LAST, now.plusMinutes(6))),
Alarm(0, 0, TYPE_REL_END, 2, MINUTES.toMillis(5))
Alarm(type = TYPE_REL_END, repeat = 2, interval = MINUTES.toMillis(5))
)
assertEquals(
@ -247,7 +247,7 @@ class AlarmCalculatorTest {
fun terminateRepeatReminder() = runBlocking {
val alarm = alarmCalculator.toAlarmEntry(
newTask(with(DUE_TIME, now), with(REMINDER_LAST, now.plusMinutes(10))),
Alarm(0L, 0, TYPE_REL_END, 2, MINUTES.toMillis(5))
Alarm(type = TYPE_REL_END, repeat = 2, interval = MINUTES.toMillis(5))
)
assertNull(alarm)
@ -306,7 +306,7 @@ class AlarmCalculatorTest {
with(REMINDER_LAST, now.minusDays(14)),
with(CREATION_TIME, now.minusDays(30)),
),
Alarm(0L, ONE_WEEK, TYPE_RANDOM)
Alarm(time = ONE_WEEK, type = TYPE_RANDOM)
)
assertEquals(
@ -328,7 +328,7 @@ class AlarmCalculatorTest {
)
val alarm = alarmCalculator.toAlarmEntry(
task,
Alarm(0L, ONE_WEEK, TYPE_RANDOM)
Alarm(time = ONE_WEEK, type = TYPE_RANDOM)
)
assertEquals(
@ -348,7 +348,7 @@ class AlarmCalculatorTest {
with(REMINDER_LAST, null as DateTime?),
with(CREATION_TIME, now.minusDays(1)),
),
Alarm(0L, ONE_WEEK, TYPE_RANDOM)
Alarm(time = ONE_WEEK, type = TYPE_RANDOM)
)
assertEquals(
@ -371,7 +371,7 @@ class AlarmCalculatorTest {
with(REMINDER_LAST, now.minusDays(1)),
with(CREATION_TIME, now.minusDays(30)),
),
Alarm(0L, ONE_WEEK, TYPE_RANDOM)
Alarm(time = ONE_WEEK, type = TYPE_RANDOM)
)
assertEquals(

@ -1,6 +1,5 @@
package org.tasks.caldav
import org.tasks.data.entity.Task
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
@ -10,8 +9,9 @@ import org.tasks.TestUtilities.alarms
import org.tasks.TestUtilities.vtodo
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.TYPE_DATE_TIME
import org.tasks.data.entity.Task
import org.tasks.time.DateTime
import java.util.*
import java.util.TimeZone
class AppleRemindersTests {
private val defaultTimeZone = TimeZone.getDefault()
@ -85,7 +85,7 @@ class AppleRemindersTests {
@Test
fun dateTimeReminder() {
assertEquals(
listOf(Alarm(0, 1642568400000, TYPE_DATE_TIME)),
listOf(Alarm(time = 1642568400000, type = TYPE_DATE_TIME)),
"apple/date_time_reminder.txt".alarms
)
}

@ -1,6 +1,5 @@
package org.tasks.caldav
import org.tasks.data.entity.Task
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
@ -14,8 +13,9 @@ import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.TYPE_DATE_TIME
import org.tasks.data.entity.Alarm.Companion.TYPE_REL_END
import org.tasks.data.entity.Alarm.Companion.TYPE_REL_START
import org.tasks.data.entity.Task
import org.tasks.time.DateTime
import java.util.*
import java.util.TimeZone
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeUnit.MINUTES
@ -113,7 +113,7 @@ class ThunderbirdTests {
@Test
fun dateTimeReminder() {
assertEquals(
listOf(Alarm(task = 0, time = 1642791600000, type = TYPE_DATE_TIME)),
listOf(Alarm(time = 1642791600000, type = TYPE_DATE_TIME)),
"thunderbird/date_time_reminder.txt".alarms
)
}
@ -121,7 +121,7 @@ class ThunderbirdTests {
@Test
fun reminderBeforeStart() {
assertEquals(
listOf(Alarm(task = 0, time = -TimeUnit.HOURS.toMillis(1), type = TYPE_REL_START)),
listOf(Alarm(time = -TimeUnit.HOURS.toMillis(1), type = TYPE_REL_START)),
"thunderbird/reminder_before_start.txt".alarms
)
}
@ -129,7 +129,7 @@ class ThunderbirdTests {
@Test
fun reminderAfterStart() {
assertEquals(
listOf(Alarm(task = 0, time = MINUTES.toMillis(15), type = TYPE_REL_START)),
listOf(Alarm(time = MINUTES.toMillis(15), type = TYPE_REL_START)),
"thunderbird/reminder_after_start.txt".alarms
)
}
@ -137,7 +137,7 @@ class ThunderbirdTests {
@Test
fun reminderBeforeEnd() {
assertEquals(
listOf(Alarm(task = 0, time = -MINUTES.toMillis(15), type = TYPE_REL_END)),
listOf(Alarm(time = -MINUTES.toMillis(15), type = TYPE_REL_END)),
"thunderbird/reminder_before_end.txt".alarms
)
}
@ -145,7 +145,7 @@ class ThunderbirdTests {
@Test
fun reminderAfterEnd() {
assertEquals(
listOf(Alarm(task = 0, time = MINUTES.toMillis(15), type = TYPE_REL_END)),
listOf(Alarm(time = MINUTES.toMillis(15), type = TYPE_REL_END)),
"thunderbird/reminder_after_end.txt".alarms
)
}
@ -153,7 +153,7 @@ class ThunderbirdTests {
@Test
fun reminderAtStart() {
assertEquals(
listOf(Alarm(task = 0, time = 0, type = TYPE_REL_START)),
listOf(Alarm(type = TYPE_REL_START)),
"thunderbird/reminder_at_start.txt".alarms
)
}
@ -161,7 +161,7 @@ class ThunderbirdTests {
@Test
fun reminder50Days() {
assertEquals(
listOf(Alarm(task = 0, time = -TimeUnit.DAYS.toMillis(50), type = TYPE_REL_START)),
listOf(Alarm(time = -TimeUnit.DAYS.toMillis(50), type = TYPE_REL_START)),
"thunderbird/reminder_50_days.txt".alarms
)
}

@ -17,11 +17,8 @@ class VAlarmTests {
assertEquals(
"BEGIN:VALARM\r\nTRIGGER;VALUE=DATE-TIME:20220121T190000Z\r\nACTION:DISPLAY\r\nDESCRIPTION:Default Tasks.org description\r\nEND:VALARM\r\n",
Alarm(
0,
DateTime(2022, 1, 21, 19, 0, 0, 0, UTC).millis,
TYPE_DATE_TIME,
0,
0
time = DateTime(2022, 1, 21, 19, 0, 0, 0, UTC).millis,
type = TYPE_DATE_TIME,
).toVAlarm().toString()
)
}
@ -29,11 +26,8 @@ class VAlarmTests {
@Test
fun dateTimeFromAlarm() {
val alarm = Alarm(
0,
DateTime(2022, 1, 21, 19, 0, 0, 0, UTC).millis,
TYPE_DATE_TIME,
0,
0
time = DateTime(2022, 1, 21, 19, 0, 0, 0, UTC).millis,
type = TYPE_DATE_TIME,
)
assertEquals(alarm, alarm.toVAlarm()?.toAlarm())
}
@ -42,13 +36,13 @@ class VAlarmTests {
fun beforeStartToVAlarm() {
assertEquals(
"BEGIN:VALARM\r\nTRIGGER;RELATED=START:-PT1H15M\r\nACTION:DISPLAY\r\nDESCRIPTION:Default Tasks.org description\r\nEND:VALARM\r\n",
Alarm(0, -MINUTES.toMillis(75), TYPE_REL_START, 0, 0).toVAlarm().toString()
Alarm(time = -MINUTES.toMillis(75), type = TYPE_REL_START).toVAlarm().toString()
)
}
@Test
fun beforeStartFromAlarm() {
val alarm = Alarm(0, -MINUTES.toMillis(75), TYPE_REL_START, 0, 0)
val alarm = Alarm(time = -MINUTES.toMillis(75), type = TYPE_REL_START)
assertEquals(alarm, alarm.toVAlarm()?.toAlarm())
}
@ -56,13 +50,13 @@ class VAlarmTests {
fun afterStartToVAlarm() {
assertEquals(
"BEGIN:VALARM\r\nTRIGGER;RELATED=START:PT1H15M\r\nACTION:DISPLAY\r\nDESCRIPTION:Default Tasks.org description\r\nEND:VALARM\r\n",
Alarm(0, MINUTES.toMillis(75), TYPE_REL_START, 0, 0).toVAlarm().toString()
Alarm(time = MINUTES.toMillis(75), type = TYPE_REL_START).toVAlarm().toString()
)
}
@Test
fun afterStartFromAlarm() {
val alarm = Alarm(0, MINUTES.toMillis(75), TYPE_REL_START, 0, 0)
val alarm = Alarm(time = MINUTES.toMillis(75), type = TYPE_REL_START)
assertEquals(alarm, alarm.toVAlarm()?.toAlarm())
}
@ -70,13 +64,13 @@ class VAlarmTests {
fun beforeEndToVAlarm() {
assertEquals(
"BEGIN:VALARM\r\nTRIGGER;RELATED=END:-PT1H15M\r\nACTION:DISPLAY\r\nDESCRIPTION:Default Tasks.org description\r\nEND:VALARM\r\n",
Alarm(0, -MINUTES.toMillis(75), TYPE_REL_END, 0, 0).toVAlarm().toString()
Alarm(time = -MINUTES.toMillis(75), type = TYPE_REL_END).toVAlarm().toString()
)
}
@Test
fun beforeEndFromAlarm() {
val alarm = Alarm(0, -MINUTES.toMillis(75), TYPE_REL_END, 0, 0)
val alarm = Alarm(time = -MINUTES.toMillis(75), type = TYPE_REL_END)
assertEquals(alarm, alarm.toVAlarm()?.toAlarm())
}
@ -84,13 +78,13 @@ class VAlarmTests {
fun afterEndToVAlarm() {
assertEquals(
"BEGIN:VALARM\r\nTRIGGER;RELATED=END:PT1H15M\r\nACTION:DISPLAY\r\nDESCRIPTION:Default Tasks.org description\r\nEND:VALARM\r\n",
Alarm(0, MINUTES.toMillis(75), TYPE_REL_END, 0, 0).toVAlarm().toString()
Alarm(time = MINUTES.toMillis(75), type = TYPE_REL_END).toVAlarm().toString()
)
}
@Test
fun afterEndFromAlarm() {
val alarm = Alarm(0, MINUTES.toMillis(75), TYPE_REL_END, 0, 0)
val alarm = Alarm(time = MINUTES.toMillis(75), type = TYPE_REL_END)
assertEquals(alarm, alarm.toVAlarm()?.toAlarm())
}
@ -98,13 +92,23 @@ class VAlarmTests {
fun repeatingAlarm() {
assertEquals(
"BEGIN:VALARM\r\nTRIGGER;RELATED=START:P1DT8H\r\nACTION:DISPLAY\r\nDESCRIPTION:Default Tasks.org description\r\nREPEAT:15\r\nDURATION:PT15M\r\nEND:VALARM\r\n",
Alarm(0, HOURS.toMillis(32), TYPE_REL_START, 15, MINUTES.toMillis(15)).toVAlarm().toString()
Alarm(
time = HOURS.toMillis(32),
type = TYPE_REL_START,
repeat = 15,
interval = MINUTES.toMillis(15)
).toVAlarm().toString()
)
}
@Test
fun repeatingFromAlarm() {
val alarm = Alarm(0, HOURS.toMillis(32), TYPE_REL_START, 15, MINUTES.toMillis(15))
val alarm = Alarm(
time = HOURS.toMillis(32),
type = TYPE_REL_START,
repeat = 15,
interval = MINUTES.toMillis(15)
)
assertEquals(alarm, alarm.toVAlarm()?.toAlarm())
}
}

@ -29,13 +29,10 @@ WHERE tasks._id = :taskId
""")
suspend fun getActiveAlarms(taskId: Long): List<Alarm>
@Query("SELECT * FROM alarms WHERE type = $TYPE_SNOOZE AND task IN (:taskIds)")
suspend fun getSnoozed(taskIds: List<Long>): List<Alarm>
@Query("SELECT * FROM alarms WHERE task = :taskId")
suspend fun getAlarms(taskId: Long): List<Alarm>
@Query("DELETE FROM alarms WHERE type = $TYPE_SNOOZE AND task IN(:taskIds)")
@Query("DELETE FROM alarms WHERE type = $TYPE_SNOOZE AND task IN (:taskIds)")
suspend fun deleteSnoozed(taskIds: List<Long>)
@Delete

@ -4,7 +4,6 @@ import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Ignore
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable
@ -43,17 +42,6 @@ data class Alarm(
@ColumnInfo(name = "interval", defaultValue = "0")
var interval: Long = 0,
) : Parcelable {
@Ignore
constructor(task: Long, time: Long, type: Int, repeat: Int = 0, interval: Long = 0): this(
id = 0,
task = task,
time = time,
type = type,
repeat = repeat,
interval = interval
)
fun same(other: Alarm) =
type == other.type &&
time == other.time &&
@ -80,11 +68,17 @@ data class Alarm(
const val TYPE_GEO_ENTER = 5
const val TYPE_GEO_EXIT = 6
fun whenStarted(task: Long) = Alarm(task, 0, TYPE_REL_START)
fun whenStarted(task: Long) = Alarm(task = task, type = TYPE_REL_START)
fun whenDue(task: Long) = Alarm(task, 0, TYPE_REL_END)
fun whenDue(task: Long) = Alarm(task = task, type = TYPE_REL_END)
fun whenOverdue(task: Long) =
Alarm(task, TimeUnit.DAYS.toMillis(1), TYPE_REL_END, 6, TimeUnit.DAYS.toMillis(1))
Alarm(
task = task,
time = TimeUnit.DAYS.toMillis(1),
type = TYPE_REL_END,
repeat = 6,
interval = TimeUnit.DAYS.toMillis(1)
)
}
}
Loading…
Cancel
Save