mirror of https://github.com/tasks/tasks
Compare commits
338 Commits
Author | SHA1 | Date |
---|---|---|
renovate[bot] | f8bb045d76 | 3 days ago |
renovate[bot] | 4040a2379b | 3 days ago |
Alex Baker | c4ee7479ca | 3 days ago |
Alex Baker | be861597ef | 3 days ago |
Alex Baker | f27332595d | 3 days ago |
Alex Baker | ea7f051d85 | 3 days ago |
Alex Baker | 8be7fab033 | 3 days ago |
Alex Baker | d6e0c0bdcf | 3 days ago |
Alex Baker | 5ec02011f8 | 3 days ago |
Alex Baker | b35090cd43 | 3 days ago |
renovate[bot] | 92f62450ae | 3 days ago |
renovate[bot] | 3ca6912492 | 3 days ago |
renovate[bot] | 080b1428dd | 3 days ago |
Alex Baker | f67c3bc56c | 3 days ago |
renovate[bot] | 5d0e88a620 | 3 days ago |
renovate[bot] | c5d5795fe2 | 3 days ago |
renovate[bot] | 3bbc0e0ab0 | 3 days ago |
Alex Baker | 009a195580 | 3 days ago |
renovate[bot] | 772f69d8c0 | 4 days ago |
renovate[bot] | 4229bf7067 | 4 days ago |
Alex Baker | 212a4b0a3d | 4 days ago |
Alex Baker | 4ddfe937b0 | 5 days ago |
Alex Baker | 19de0e08a5 | 5 days ago |
Alex Baker | 60211355e0 | 6 days ago |
Alex Baker | 17d218aa4e | 6 days ago |
Alex Baker | 505c8c29d5 | 7 days ago |
Alex Baker | 7149308c97 | 7 days ago |
Alex Baker | 2c5a497007 | 1 week ago |
Alex Baker | 09f53fe1e5 | 1 week ago |
Alex Baker | 5da4183aed | 1 week ago |
Alex Baker | d35912e503 | 1 week ago |
renovate[bot] | 82fd99f83e | 1 week ago |
renovate[bot] | f944becea1 | 1 week ago |
Alex Baker | acd713dc5b | 1 week ago |
Alex Baker | 1a93c87ad9 | 1 week ago |
Alex Baker | c4e25b8b15 | 1 week ago |
Alex Baker | e11c0d2528 | 1 week ago |
Alex Baker | 2fc6833854 | 1 week ago |
Alex Baker | 4a2fb13d10 | 2 weeks ago |
Alex Baker | a2572e2dee | 2 weeks ago |
Alex Baker | 64e05c9f8f | 2 weeks ago |
Alex Baker | ad833b5f49 | 2 weeks ago |
Alex Baker | eea944cc7b | 2 weeks ago |
Alex Baker | c82dfc7d39 | 2 weeks ago |
Alex Baker | 8607f9556a | 2 weeks ago |
Alex Baker | f338e84d46 | 2 weeks ago |
Alex Baker | 9ee739627e | 2 weeks ago |
Alex Baker | a49c233584 | 2 weeks ago |
Alex Baker | 74fca07c1b | 2 weeks ago |
Alex Baker | 5bd0cef42e | 2 weeks ago |
Alex Baker | 4c245edbb4 | 2 weeks ago |
Alex Baker | 97a3f074d0 | 2 weeks ago |
Alex Baker | 86ecd3cf81 | 2 weeks ago |
Alex Baker | 07a2eda5ea | 2 weeks ago |
renovate[bot] | 09ffbdd036 | 2 weeks ago |
renovate[bot] | 60f22146ca | 2 weeks ago |
renovate[bot] | c11225abaf | 2 weeks ago |
dependabot[bot] | 133ea493e3 | 2 weeks ago |
Alex Baker | 0ba901be69 | 3 weeks ago |
Alex Baker | ebe5e5c009 | 3 weeks ago |
Alex Baker | d556863fda | 3 weeks ago |
Alex Baker | 55adbc2025 | 3 weeks ago |
Alex Baker | 06c4255886 | 3 weeks ago |
renovate[bot] | 4734a99bae | 3 weeks ago |
Alex Baker | a6a8cac8e4 | 3 weeks ago |
Alex Baker | c3fc9a57cc | 3 weeks ago |
Alex Baker | 6e14d07d0c | 3 weeks ago |
Alex Baker | 6118121698 | 3 weeks ago |
Alex Baker | 6bf3bd4d08 | 3 weeks ago |
Alex Baker | 065be79355 | 3 weeks ago |
Alex Baker | f8f8ba3c51 | 3 weeks ago |
Alex Baker | 89465f36b3 | 3 weeks ago |
Alex Baker | 1380a34ffa | 3 weeks ago |
Alex Baker | 10af5280a3 | 3 weeks ago |
Alex Baker | 8c0f7b952d | 3 weeks ago |
Alex Baker | 65362b203f | 3 weeks ago |
Alex Baker | 3327f97a17 | 3 weeks ago |
Alex Baker | c9fc02a42e | 4 weeks ago |
renovate[bot] | 93670bb9e4 | 4 weeks ago |
Alex Baker | 1fc6a50d0b | 4 weeks ago |
Alex Baker | e1ef924909 | 4 weeks ago |
Alex Baker | 686cb5d346 | 4 weeks ago |
renovate[bot] | ebec25c4cb | 4 weeks ago |
renovate[bot] | c140f7e673 | 4 weeks ago |
renovate[bot] | efbcf11a4a | 4 weeks ago |
renovate[bot] | 6adee85a37 | 4 weeks ago |
Alex Baker | 5c8643110b | 4 weeks ago |
Alex Baker | abd13aeb75 | 4 weeks ago |
Alex Baker | c210fe1893 | 4 weeks ago |
Alex Baker | 26aa916c20 | 4 weeks ago |
renovate[bot] | 1eff2d1cd5 | 4 weeks ago |
islam2hamy | c90e683ea3 | 4 weeks ago |
Alex Baker | 3cd0295b71 | 4 weeks ago |
Alex Baker | 95c351e9fd | 4 weeks ago |
renovate[bot] | 4ddb7816f1 | 4 weeks ago |
renovate[bot] | 91c30f7bbf | 1 month ago |
renovate[bot] | 3f4398b6e0 | 1 month ago |
renovate[bot] | c822e989a3 | 1 month ago |
renovate[bot] | da146723e5 | 1 month ago |
109247019824 | 931626c84a | 1 month ago |
Alex Baker | c534632c52 | 1 month ago |
Alex Baker | c1347a7455 | 1 month ago |
renovate[bot] | 9544909a58 | 1 month ago |
Yurt Page | 5c10dce2b9 | 1 month ago |
Alex Baker | 584d4a5cbb | 1 month ago |
Alex Baker | 7c68a7fa59 | 1 month ago |
purushottamyadavbattula | 215cc838ef | 1 month ago |
Alex Baker | d60472d1bc | 1 month ago |
Alex Baker | f84a37a60a | 1 month ago |
Alex Baker | 7fb85b6da1 | 1 month ago |
Alex Baker | dc90e583e4 | 1 month ago |
Don Zouras | 0eac5f61eb | 1 month ago |
Milo Ivir | c686ce883d | 1 month ago |
大王叫我来巡山 | ab25398cd0 | 1 month ago |
renovate[bot] | 3b1c133d22 | 1 month ago |
renovate[bot] | 3bfd0ab4f8 | 1 month ago |
Liz de Sartiges | ffc0113d7f | 1 month ago |
Don Zouras | 9de9718ad5 | 1 month ago |
Oğuz Ersen | a7d2c9c406 | 1 month ago |
gallegonovato | b3006b9ac2 | 1 month ago |
Don Zouras | de3ef1f9c9 | 1 month ago |
Alex Baker | ce9e722a3f | 1 month ago |
Alex Baker | 4b892a0eb1 | 1 month ago |
Hady | e6e275834a | 1 month ago |
Alex Baker | 782f4d6d7c | 1 month ago |
elmuffo | a1da71d3e1 | 1 month ago |
Alex Baker | c793a300cc | 1 month ago |
Ilya Bizyaev | bf84bf9e82 | 1 month ago |
SC | 363b29babb | 2 months ago |
min7-i | c1ff953f5c | 2 months ago |
Alex Baker | 63482e5db9 | 2 months ago |
Emin Tufan Çetin | 2f7dc0c7f1 | 2 months ago |
Lionel HANNEQUIN | d672507fae | 2 months ago |
Jonatan Nyberg | ce2a3c8a3f | 2 months ago |
sorifukobexomajepasiricupuva33 | 9cd114d68b | 2 months ago |
Patrick V. Leguizamon | 0e663f0e08 | 2 months ago |
Mayhm | 1d1efd008d | 2 months ago |
Alex Baker | 26ab3d5866 | 2 months ago |
Mayhm | 9a4fcbbd39 | 2 months ago |
Alex Baker | 72bfda9224 | 2 months ago |
Alex Baker | 1067de4183 | 2 months ago |
Alex Baker | d686b8c7e0 | 2 months ago |
Alex Baker | b2efb42d55 | 2 months ago |
Fabio Parri | 3448808c94 | 2 months ago |
Alex Baker | 06a9626052 | 2 months ago |
Alex Baker | e92ab7f7e1 | 2 months ago |
Alex Baker | 4ff7b18c0f | 2 months ago |
Alex Baker | 91887f6b17 | 2 months ago |
Alex Baker | cf30b56098 | 2 months ago |
Alex Baker | 9bcadaab5a | 2 months ago |
Alex Baker | be766074b0 | 2 months ago |
Ihor Hordiichuk | 64a42a3f61 | 2 months ago |
Mayhm | 7b65ba6f06 | 2 months ago |
109247019824 | ac2b270e9e | 2 months ago |
Alex Baker | db2ea0a039 | 2 months ago |
renovate[bot] | 08b78fe9f4 | 2 months ago |
Alex Baker | 1a1301ae3e | 2 months ago |
Milo Ivir | d00061aa7f | 2 months ago |
大王叫我来巡山 | 45add6ab32 | 2 months ago |
Pierfrancesco Passerini | af43737c4e | 2 months ago |
macpac59 | dd40e59b17 | 2 months ago |
gallegonovato | 13f3248a01 | 2 months ago |
renovate[bot] | f6972e3e30 | 2 months ago |
Alex Baker | 83cf48a836 | 2 months ago |
Alex Baker | b7b4747a04 | 2 months ago |
Alex Baker | 6bec2ceef0 | 2 months ago |
Milo Ivir | d1e60d6512 | 2 months ago |
bittin1ddc447d824349b2 | 2b85089d3a | 2 months ago |
ferranpujolcamins | 2a0ef9feb6 | 2 months ago |
109247019824 | 33adbbd884 | 2 months ago |
Alex Baker | c25eb2e0c5 | 2 months ago |
Alex Baker | 14026356eb | 3 months ago |
Alex Baker | b328651dd4 | 3 months ago |
Alex Baker | a0e9bfabeb | 3 months ago |
大王叫我来巡山 | a1ad421b33 | 3 months ago |
Mayhm | 3488a08af1 | 3 months ago |
gallegonovato | b71d1af516 | 3 months ago |
Alex Baker | 041dce8617 | 3 months ago |
Alex Baker | 3d92ca78dd | 3 months ago |
Alex Baker | a32fce2d8b | 3 months ago |
Alex Baker | 4fb3cda173 | 3 months ago |
Alex Baker | f33cc896dd | 3 months ago |
Alex Baker | 4d1d6a06a8 | 3 months ago |
Alex Baker | 2202516688 | 3 months ago |
Alex Baker | d4a5008ecb | 3 months ago |
Alex Baker | 08189e10f1 | 3 months ago |
Anonymous | d3e4c066d8 | 3 months ago |
Anonymous | bbc5ae4d6d | 3 months ago |
Anonymous | c6cc00cf07 | 3 months ago |
Anonymous | 22e8720021 | 3 months ago |
Anonymous | a3ce98f0ea | 3 months ago |
macpac59 | 258f607d52 | 3 months ago |
ngocanhtve | 927acae7e4 | 3 months ago |
Odweta | 49ad9bafe3 | 3 months ago |
Alex Baker | 6df616d9ce | 3 months ago |
Alex Baker | 157668e35a | 3 months ago |
Aslam Karachiwala | efdf343869 | 3 months ago |
renovate[bot] | 5606df17c5 | 3 months ago |
renovate[bot] | fc3b4971f4 | 3 months ago |
renovate[bot] | 6a1699bb33 | 3 months ago |
renovate[bot] | e49303d5ca | 3 months ago |
renovate[bot] | 4b55569b51 | 3 months ago |
renovate[bot] | 2d7145cde3 | 3 months ago |
renovate[bot] | f2ab8bed95 | 3 months ago |
renovate[bot] | a5bc4cf536 | 3 months ago |
renovate[bot] | 1b35372b3a | 3 months ago |
Alex Baker | c0fd4bf66a | 3 months ago |
renovate[bot] | 5d366f0d61 | 3 months ago |
renovate[bot] | d0635ac6f3 | 3 months ago |
renovate[bot] | 8d4cf4daa5 | 3 months ago |
renovate[bot] | d1e439e70e | 3 months ago |
renovate[bot] | 4d4c3e5193 | 4 months ago |
Alex Baker | 20f87061fd | 4 months ago |
renovate[bot] | c03e3747c6 | 4 months ago |
renovate[bot] | 925b1b9124 | 4 months ago |
Alex Baker | 43db712f64 | 4 months ago |
Alex Baker | 9d33a73ee6 | 4 months ago |
renovate[bot] | 391c600ce2 | 4 months ago |
renovate[bot] | ee4ae94817 | 4 months ago |
renovate[bot] | 70b4be1447 | 4 months ago |
Don Zouras | bc54d92789 | 4 months ago |
Сергій | 2f34724b95 | 4 months ago |
Alex Baker | 940fdc28dd | 4 months ago |
Alex Baker | 68542fce38 | 4 months ago |
renovate[bot] | 7ba2977100 | 4 months ago |
Don Zouras | cb242539f0 | 4 months ago |
bittin1ddc447d824349b2 | 304841f2c3 | 4 months ago |
Don Zouras | 819ea797e6 | 4 months ago |
abc0922001 | 2dbea57262 | 4 months ago |
Don Zouras | 516a916fd5 | 4 months ago |
109247019824 | 3bd52efc80 | 4 months ago |
renovate[bot] | 64af955ea7 | 4 months ago |
Milo Ivir | 4cc5ec9639 | 4 months ago |
大王叫我来巡山 | 0d9292e53a | 4 months ago |
Oğuz Ersen | 732ccf1913 | 4 months ago |
gallegonovato | a2852bdbbf | 4 months ago |
Don Zouras | 68790ad401 | 4 months ago |
Alex Baker | e9afacb595 | 4 months ago |
Alex Baker | cf182aceab | 4 months ago |
Alex Baker | db889d233a | 4 months ago |
Alex Baker | 457b89c092 | 4 months ago |
Don Zouras | ad53af1b6a | 4 months ago |
renovate[bot] | 2c32b08c97 | 4 months ago |
renovate[bot] | a2fcf57c9e | 4 months ago |
renovate[bot] | 59a61325f2 | 4 months ago |
vulewuxe86 | 38a6064677 | 4 months ago |
renovate[bot] | 67daccf3e8 | 4 months ago |
renovate[bot] | dfe829d2a1 | 4 months ago |
renovate[bot] | 23c64f4d28 | 4 months ago |
renovate[bot] | e4b8f694f3 | 4 months ago |
renovate[bot] | e667c80731 | 4 months ago |
renovate[bot] | 909b077e25 | 4 months ago |
Don Zouras | e6fab9ad45 | 4 months ago |
raulmagdalena | 9474f5b7af | 4 months ago |
Don Zouras | 1ee051d768 | 4 months ago |
Don Zouras | f42edaa158 | 4 months ago |
RayBB | b97eade59c | 4 months ago |
renovate[bot] | 41aa1ca65f | 4 months ago |
renovate[bot] | 3e9a13ea14 | 5 months ago |
renovate[bot] | d966e8a12b | 5 months ago |
renovate[bot] | 8ba4e64994 | 5 months ago |
109247019824 | ee792f1ceb | 5 months ago |
renovate[bot] | caa09163a1 | 5 months ago |
renovate[bot] | d270abf5b3 | 5 months ago |
renovate[bot] | 1ef530abad | 5 months ago |
renovate[bot] | df26a6dbb9 | 5 months ago |
renovate[bot] | 1882c3b7e0 | 5 months ago |
renovate[bot] | cb53a0ca9f | 5 months ago |
renovate[bot] | b2fdef1ae7 | 5 months ago |
renovate[bot] | defb16ce95 | 5 months ago |
renovate[bot] | 823f99b28a | 6 months ago |
renovate[bot] | 6df872b1a1 | 6 months ago |
renovate[bot] | 133b960583 | 6 months ago |
renovate[bot] | 2e6753faec | 6 months ago |
renovate[bot] | cb07c2c267 | 6 months ago |
renovate[bot] | 23757ab320 | 6 months ago |
Alex Baker | 1b6ce0e48e | 6 months ago |
Kakaeo | 5af012068f | 6 months ago |
Alex Baker | 6c9ffa57d7 | 6 months ago |
Alex Baker | 52c54b1eac | 6 months ago |
Alex Baker | c8d81b44b6 | 6 months ago |
renovate[bot] | ef27a50e42 | 6 months ago |
Alex Baker | bde1356e7f | 6 months ago |
Alex Baker | 6c031925ba | 6 months ago |
Alex Baker | 8058414137 | 6 months ago |
Alex Baker | 3e37ea50f0 | 6 months ago |
renovate[bot] | 62f5a9c492 | 6 months ago |
renovate[bot] | a84fd65722 | 6 months ago |
renovate[bot] | 517b2d8f1b | 6 months ago |
renovate[bot] | 90942bf0be | 6 months ago |
Alex Baker | 83c3d1c4ba | 6 months ago |
Software In Interlingua | 6362ece569 | 6 months ago |
renovate[bot] | 8df85041b8 | 6 months ago |
ngocanhtve | 6d85af4c34 | 6 months ago |
Olli | 63f001dd72 | 6 months ago |
renovate[bot] | de49a50944 | 6 months ago |
renovate[bot] | df20d2f593 | 6 months ago |
renovate[bot] | fd16772236 | 6 months ago |
renovate[bot] | b77caac255 | 6 months ago |
renovate[bot] | ad058ed09b | 6 months ago |
Alex Baker | 8312113d7b | 6 months ago |
Alex Baker | ee21cc660e | 6 months ago |
Alex Baker | 5edc481ffe | 6 months ago |
Alex Baker | d0360a4862 | 6 months ago |
Alex Baker | ac35002408 | 6 months ago |
Subham Jena | 582ebad0f0 | 6 months ago |
Shaban Mamedov | 684c47184a | 6 months ago |
ngocanhtve | ac7a519e4e | 6 months ago |
renovate[bot] | 5c2b41af9d | 7 months ago |
renovate[bot] | 13986cf380 | 7 months ago |
CennoxX | c4f0b404e9 | 7 months ago |
Alex Baker | 145b5afbc6 | 7 months ago |
elig0n | 0b87a206fe | 7 months ago |
mm4c | d0e70ceea8 | 7 months ago |
J. Lavoie | bf3546a878 | 7 months ago |
Alex Baker | 8895acbf6b | 7 months ago |
Alex Baker | a52b1200f5 | 7 months ago |
renovate[bot] | 23964e807a | 7 months ago |
Alex Baker | 287b106dd4 | 7 months ago |
renovate[bot] | 33bab626e0 | 7 months ago |
renovate[bot] | a980cd75cc | 7 months ago |
renovate[bot] | 7eac4ac223 | 7 months ago |
renovate[bot] | 82cb2f7d3f | 7 months ago |
renovate[bot] | da2646597c | 7 months ago |
renovate[bot] | 495855133c | 7 months ago |
renovate[bot] | 242cb61662 | 7 months ago |
renovate[bot] | ab8886f3dc | 7 months ago |
Alex Baker | e48e92d2e6 | 7 months ago |
Alex Baker | 5f22f5cd38 | 7 months ago |
Alex Baker | 8a47cc2934 | 7 months ago |
Alex Baker | 0d94729d37 | 7 months ago |
Alex Baker | 14599eb3c0 | 7 months ago |
Alex Baker | b477623524 | 7 months ago |
Alex Baker | c8bfb67b50 | 7 months ago |
Alex Baker | 0a36e58525 | 7 months ago |
Alex Baker | 94a719cb66 | 7 months ago |
Alex Baker | b5748aa8e6 | 7 months ago |
Alex Baker | 7fd5647cb8 | 7 months ago |
@ -1 +1 @@
|
||||
3.2.2
|
||||
3.3.1
|
||||
|
@ -1,106 +1,255 @@
|
||||
package com.todoroo.astrid.alarms
|
||||
|
||||
import com.natpryce.makeiteasy.MakeItEasy.with
|
||||
import com.todoroo.andlib.utility.DateUtilities
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import dagger.hilt.android.testing.UninstallModules
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.tasks.data.Alarm
|
||||
import org.tasks.data.Alarm.Companion.TYPE_DATE_TIME
|
||||
import org.tasks.data.Alarm.Companion.TYPE_RANDOM
|
||||
import org.tasks.data.Alarm.Companion.TYPE_SNOOZE
|
||||
import org.tasks.data.Alarm.Companion.whenDue
|
||||
import org.tasks.data.Alarm.Companion.whenOverdue
|
||||
import org.tasks.data.AlarmDao
|
||||
import org.tasks.data.TaskDao
|
||||
import org.tasks.date.DateTimeUtils.newDateTime
|
||||
import org.tasks.SuspendFreeze.Companion.freezeAt
|
||||
import org.tasks.data.createDueDate
|
||||
import org.tasks.data.dao.TaskDao
|
||||
import org.tasks.data.entity.Alarm
|
||||
import org.tasks.data.entity.Notification
|
||||
import org.tasks.data.entity.Task
|
||||
import org.tasks.injection.InjectingTestCase
|
||||
import org.tasks.injection.ProductionModule
|
||||
import org.tasks.jobs.AlarmEntry
|
||||
import org.tasks.jobs.NotificationQueue
|
||||
import org.tasks.makers.TaskMaker.COMPLETION_TIME
|
||||
import org.tasks.makers.TaskMaker.DELETION_TIME
|
||||
import org.tasks.makers.TaskMaker.DUE_DATE
|
||||
import org.tasks.makers.TaskMaker.DUE_TIME
|
||||
import org.tasks.makers.TaskMaker.REMINDER_LAST
|
||||
import org.tasks.makers.TaskMaker.newTask
|
||||
import org.tasks.time.DateTime
|
||||
import org.tasks.time.DateTimeUtils2
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
@UninstallModules(ProductionModule::class)
|
||||
@HiltAndroidTest
|
||||
class AlarmJobServiceTest : InjectingTestCase() {
|
||||
@Inject lateinit var alarmDao: AlarmDao
|
||||
@Inject lateinit var taskDao: TaskDao
|
||||
@Inject lateinit var jobs: NotificationQueue
|
||||
@Inject lateinit var alarmService: AlarmService
|
||||
|
||||
@Test
|
||||
fun scheduleAlarm() = runBlocking {
|
||||
val task = taskDao.createNew(newTask())
|
||||
val alarm = insertAlarm(Alarm(task, DateTime(2017, 9, 24, 19, 57).millis, TYPE_DATE_TIME))
|
||||
|
||||
verify(AlarmEntry(alarm, task, DateTime(2017, 9, 24, 19, 57).millis, TYPE_DATE_TIME))
|
||||
fun testNoAlarms() = runBlocking {
|
||||
testResults(emptyList(), 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun ignoreStaleAlarm() = runBlocking {
|
||||
val alarmTime = DateTime(2017, 9, 24, 19, 57)
|
||||
val task = taskDao.createNew(newTask(with(REMINDER_LAST, alarmTime.endOfMinute())))
|
||||
alarmDao.insert(Alarm(task, alarmTime.millis, TYPE_DATE_TIME))
|
||||
fun futureAlarmWithNoPastAlarm() = runBlocking {
|
||||
freezeAt(DateTime(2024, 5, 17, 23, 20)) {
|
||||
taskDao.insert(
|
||||
Task(
|
||||
dueDate = createDueDate(
|
||||
Task.URGENCY_SPECIFIC_DAY,
|
||||
DateTime(2024, 5, 18).millis
|
||||
)
|
||||
)
|
||||
)
|
||||
alarmService.synchronizeAlarms(1, mutableSetOf(Alarm(type = Alarm.TYPE_REL_END)))
|
||||
|
||||
testResults(emptyList(), DateTime(2024, 5, 18, 18, 0).millis)
|
||||
}
|
||||
}
|
||||
|
||||
verify()
|
||||
@Test
|
||||
fun pastAlarmWithNoFutureAlarm() = runBlocking {
|
||||
freezeAt(DateTime(2024, 5, 17, 23, 20)) {
|
||||
taskDao.insert(
|
||||
Task(
|
||||
dueDate = createDueDate(
|
||||
Task.URGENCY_SPECIFIC_DAY,
|
||||
DateTime(2024, 5, 17).millis
|
||||
)
|
||||
)
|
||||
)
|
||||
alarmService.synchronizeAlarms(1, mutableSetOf(Alarm(type = Alarm.TYPE_REL_END)))
|
||||
|
||||
testResults(
|
||||
listOf(
|
||||
Notification(
|
||||
taskId = 1L,
|
||||
timestamp = DateTimeUtils2.currentTimeMillis(),
|
||||
type = Alarm.TYPE_REL_END
|
||||
)
|
||||
),
|
||||
0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dontScheduleReminderForCompletedTask() = runBlocking {
|
||||
val task = taskDao.insert(
|
||||
newTask(
|
||||
with(DUE_DATE, newDateTime()),
|
||||
with(COMPLETION_TIME, newDateTime())
|
||||
fun pastRecurringAlarmWithFutureRecurrence() = runBlocking {
|
||||
freezeAt(DateTime(2024, 5, 17, 23, 20)) {
|
||||
taskDao.insert(
|
||||
Task(
|
||||
dueDate = createDueDate(
|
||||
Task.URGENCY_SPECIFIC_DAY,
|
||||
DateTime(2024, 5, 17).millis
|
||||
)
|
||||
)
|
||||
)
|
||||
alarmService.synchronizeAlarms(
|
||||
1,
|
||||
mutableSetOf(
|
||||
Alarm(
|
||||
type = Alarm.TYPE_REL_END,
|
||||
repeat = 1,
|
||||
interval = TimeUnit.HOURS.toMillis(6)
|
||||
)
|
||||
)
|
||||
)
|
||||
alarmDao.insert(whenDue(task))
|
||||
|
||||
verify()
|
||||
testResults(
|
||||
listOf(
|
||||
Notification(
|
||||
taskId = 1L,
|
||||
timestamp = DateTimeUtils2.currentTimeMillis(),
|
||||
type = Alarm.TYPE_REL_END
|
||||
)
|
||||
),
|
||||
DateTime(2024, 5, 18, 0, 0).millis
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dontScheduleReminderForDeletedTask() = runBlocking {
|
||||
val task = taskDao.insert(
|
||||
newTask(
|
||||
with(DUE_DATE, newDateTime()),
|
||||
with(DELETION_TIME, newDateTime())
|
||||
fun pastAlarmsRemoveSnoozed() = runBlocking {
|
||||
freezeAt(DateTime(2024, 5, 17, 23, 20)) {
|
||||
taskDao.insert(
|
||||
Task(
|
||||
dueDate = createDueDate(
|
||||
Task.URGENCY_SPECIFIC_DAY,
|
||||
DateTime(2024, 5, 17).millis
|
||||
)
|
||||
)
|
||||
)
|
||||
alarmService.synchronizeAlarms(
|
||||
1,
|
||||
mutableSetOf(
|
||||
Alarm(type = Alarm.TYPE_REL_END),
|
||||
Alarm(time = DateTimeUtils2.currentTimeMillis(), type = Alarm.TYPE_SNOOZE)
|
||||
)
|
||||
)
|
||||
|
||||
testResults(
|
||||
listOf(
|
||||
Notification(
|
||||
taskId = 1L,
|
||||
timestamp = DateTimeUtils2.currentTimeMillis(),
|
||||
type = Alarm.TYPE_REL_END
|
||||
)
|
||||
),
|
||||
0
|
||||
)
|
||||
alarmDao.insert(whenDue(task))
|
||||
|
||||
verify()
|
||||
assertEquals(
|
||||
listOf(Alarm(id = 1, task = 1, time = 0, type = Alarm.TYPE_REL_END)),
|
||||
alarmService.getAlarms(1)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun snoozeOverridesAll() = runBlocking {
|
||||
val now = newDateTime()
|
||||
val task = taskDao.insert(newTask(with(DUE_TIME, now)))
|
||||
fun futureSnoozeOverrideOverdue() = runBlocking {
|
||||
freezeAt(DateTime(2024, 5, 17, 23, 20)) {
|
||||
taskDao.insert(
|
||||
Task(
|
||||
dueDate = createDueDate(
|
||||
Task.URGENCY_SPECIFIC_DAY,
|
||||
DateTime(2024, 5, 17).millis
|
||||
)
|
||||
)
|
||||
)
|
||||
alarmService.synchronizeAlarms(
|
||||
1,
|
||||
mutableSetOf(
|
||||
Alarm(type = Alarm.TYPE_REL_END),
|
||||
Alarm(
|
||||
time = DateTimeUtils2.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5),
|
||||
type = Alarm.TYPE_SNOOZE
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
testResults(
|
||||
emptyList(),
|
||||
DateTimeUtils2.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
alarmDao.insert(whenDue(task))
|
||||
alarmDao.insert(whenOverdue(task))
|
||||
alarmDao.insert(Alarm(task, DateUtilities.ONE_HOUR, TYPE_RANDOM))
|
||||
val alarm = alarmDao.insert(Alarm(task, now.plusMonths(12).millis, TYPE_SNOOZE))
|
||||
@Test
|
||||
fun ignoreStaleAlarm() = runBlocking {
|
||||
freezeAt(DateTime(2024, 5, 17, 23, 20)) {
|
||||
taskDao.insert(
|
||||
Task(
|
||||
dueDate = createDueDate(
|
||||
Task.URGENCY_SPECIFIC_DAY,
|
||||
DateTime(2024, 5, 17).millis
|
||||
),
|
||||
reminderLast = DateTime(2024, 5, 17, 18, 0).millis,
|
||||
)
|
||||
)
|
||||
alarmService.synchronizeAlarms(
|
||||
1,
|
||||
mutableSetOf(Alarm(type = Alarm.TYPE_REL_END))
|
||||
)
|
||||
|
||||
verify(AlarmEntry(alarm, task, now.plusMonths(12).millis, TYPE_SNOOZE))
|
||||
testResults(
|
||||
emptyList(),
|
||||
0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun insertAlarm(alarm: Alarm): Long {
|
||||
alarm.id = alarmDao.insert(alarm)
|
||||
return alarm.id
|
||||
@Test
|
||||
fun dontScheduleForCompletedTask() = runBlocking {
|
||||
freezeAt(DateTime(2024, 5, 17, 23, 20)) {
|
||||
taskDao.insert(
|
||||
Task(
|
||||
dueDate = createDueDate(
|
||||
Task.URGENCY_SPECIFIC_DAY,
|
||||
DateTime(2024, 5, 17).millis
|
||||
),
|
||||
completionDate = DateTime(2024, 5, 17, 14, 0).millis,
|
||||
)
|
||||
)
|
||||
alarmService.synchronizeAlarms(
|
||||
1,
|
||||
mutableSetOf(Alarm(type = Alarm.TYPE_REL_END))
|
||||
)
|
||||
|
||||
testResults(
|
||||
emptyList(),
|
||||
0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun verify(vararg alarms: AlarmEntry) {
|
||||
alarmService.scheduleAllAlarms()
|
||||
@Test
|
||||
fun dontScheduleForDeletedTask() = runBlocking {
|
||||
freezeAt(DateTime(2024, 5, 17, 23, 20)) {
|
||||
taskDao.insert(
|
||||
Task(
|
||||
dueDate = createDueDate(
|
||||
Task.URGENCY_SPECIFIC_DAY,
|
||||
DateTime(2024, 5, 17).millis
|
||||
),
|
||||
deletionDate = DateTime(2024, 5, 17, 14, 0).millis,
|
||||
)
|
||||
)
|
||||
alarmService.synchronizeAlarms(
|
||||
1,
|
||||
mutableSetOf(Alarm(type = Alarm.TYPE_REL_END))
|
||||
)
|
||||
|
||||
assertEquals(alarms.toList(), jobs.getJobs())
|
||||
testResults(
|
||||
emptyList(),
|
||||
0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun testResults(notifications: List<Notification>, nextAlarm: Long) {
|
||||
val actualNextAlarm = alarmService.triggerAlarms {
|
||||
assertEquals(notifications, it)
|
||||
it.forEach { taskDao.setLastNotified(it.taskId, DateTimeUtils2.currentTimeMillis()) }
|
||||
}
|
||||
assertEquals(nextAlarm, actualNextAlarm)
|
||||
}
|
||||
}
|
@ -1,50 +1,68 @@
|
||||
package com.todoroo.astrid.repeats
|
||||
|
||||
import com.natpryce.makeiteasy.MakeItEasy.with
|
||||
import org.tasks.data.entity.Task
|
||||
import com.todoroo.astrid.service.TaskCompleter
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import dagger.hilt.android.testing.UninstallModules
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.tasks.data.TaskDao
|
||||
import org.tasks.data.dao.TaskDao
|
||||
import org.tasks.injection.InjectingTestCase
|
||||
import org.tasks.injection.ProductionModule
|
||||
import org.tasks.makers.TaskMaker.COMPLETION_TIME
|
||||
import org.tasks.makers.TaskMaker.PARENT
|
||||
import org.tasks.makers.TaskMaker.RECUR
|
||||
import org.tasks.makers.TaskMaker.newTask
|
||||
import org.tasks.time.DateTime
|
||||
import org.tasks.time.DateTimeUtils2.currentTimeMillis
|
||||
import javax.inject.Inject
|
||||
|
||||
@UninstallModules(ProductionModule::class)
|
||||
@HiltAndroidTest
|
||||
class RepeatWithSubtasksTests : InjectingTestCase() {
|
||||
@Inject lateinit var taskDao: TaskDao
|
||||
@Inject lateinit var repeat: RepeatTaskHelper
|
||||
@Inject lateinit var taskCompleter: TaskCompleter
|
||||
|
||||
@Test
|
||||
fun uncompleteGrandchildren() = runBlocking {
|
||||
val grandparent = taskDao.createNew(newTask(with(RECUR, "RRULE:FREQ=DAILY")))
|
||||
val parent = taskDao.createNew(newTask(with(PARENT, grandparent)))
|
||||
val child = taskDao.createNew(newTask(
|
||||
with(PARENT, parent),
|
||||
with(COMPLETION_TIME, DateTime())
|
||||
))
|
||||
val grandparent = taskDao.createNew(
|
||||
Task(
|
||||
recurrence = "RRULE:FREQ=DAILY"
|
||||
)
|
||||
)
|
||||
val parent = taskDao.createNew(
|
||||
Task(
|
||||
parent = grandparent
|
||||
)
|
||||
)
|
||||
val child = taskDao.createNew(
|
||||
Task(
|
||||
parent = parent,
|
||||
completionDate = currentTimeMillis(),
|
||||
)
|
||||
)
|
||||
|
||||
repeat.handleRepeat(taskDao.fetch(grandparent)!!)
|
||||
assertTrue(taskDao.fetch(child)!!.isCompleted)
|
||||
|
||||
taskCompleter.setComplete(grandparent)
|
||||
|
||||
assertFalse(taskDao.fetch(child)!!.isCompleted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uncompleteGoogleTaskChildren() = runBlocking {
|
||||
val parent = taskDao.createNew(newTask(with(RECUR, "RRULE:FREQ=DAILY")))
|
||||
val child = taskDao.createNew(newTask(
|
||||
with(PARENT, parent),
|
||||
with(COMPLETION_TIME, DateTime())
|
||||
))
|
||||
val parent = taskDao.createNew(
|
||||
Task(
|
||||
recurrence = "RRULE:FREQ=DAILY"
|
||||
)
|
||||
)
|
||||
val child = taskDao.createNew(
|
||||
Task(
|
||||
parent = parent,
|
||||
completionDate = currentTimeMillis(),
|
||||
)
|
||||
)
|
||||
|
||||
assertTrue(taskDao.fetch(child)!!.isCompleted)
|
||||
|
||||
repeat.handleRepeat(taskDao.fetch(parent)!!)
|
||||
taskCompleter.setComplete(parent)
|
||||
|
||||
assertFalse(taskDao.fetch(child)!!.isCompleted)
|
||||
}
|
||||
|
@ -0,0 +1,161 @@
|
||||
package org.tasks.ui.editviewmodel
|
||||
|
||||
import com.todoroo.astrid.core.BuiltInFilterExposer
|
||||
import org.tasks.data.entity.Task
|
||||
import com.todoroo.astrid.service.TaskDeleter
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import dagger.hilt.android.testing.UninstallModules
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.tasks.LocalBroadcastManager
|
||||
import org.tasks.analytics.Firebase
|
||||
import org.tasks.billing.Inventory
|
||||
import org.tasks.data.dao.DeletionDao
|
||||
import org.tasks.data.dao.TaskDao
|
||||
import org.tasks.injection.InjectingTestCase
|
||||
import org.tasks.injection.ProductionModule
|
||||
import org.tasks.preferences.Preferences
|
||||
import org.tasks.time.DateTimeUtils2.currentTimeMillis
|
||||
import org.tasks.ui.TaskListViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@UninstallModules(ProductionModule::class)
|
||||
@HiltAndroidTest
|
||||
class TaskListViewModelTest : InjectingTestCase() {
|
||||
private lateinit var viewModel: TaskListViewModel
|
||||
@Inject lateinit var preferences: Preferences
|
||||
@Inject lateinit var taskDao: TaskDao
|
||||
@Inject lateinit var taskDeleter: TaskDeleter
|
||||
@Inject lateinit var deletionDao: DeletionDao
|
||||
@Inject lateinit var localBroadcastManager: LocalBroadcastManager
|
||||
@Inject lateinit var inventory: Inventory
|
||||
@Inject lateinit var firebase: Firebase
|
||||
|
||||
@Before
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
viewModel = TaskListViewModel(
|
||||
context = context,
|
||||
preferences = preferences,
|
||||
taskDao = taskDao,
|
||||
deletionDao = deletionDao,
|
||||
taskDeleter = taskDeleter,
|
||||
localBroadcastManager = localBroadcastManager,
|
||||
inventory = inventory,
|
||||
firebase = firebase,
|
||||
)
|
||||
viewModel.setFilter(BuiltInFilterExposer.getMyTasksFilter(context.resources))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clearCompletedTask() = runBlocking {
|
||||
val task = taskDao.createNew(
|
||||
Task(completionDate = currentTimeMillis())
|
||||
)
|
||||
|
||||
clearCompleted()
|
||||
|
||||
assertTrue(taskDao.fetch(task)!!.isDeleted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dontDeleteTaskWithRecurringParent() = runBlocking {
|
||||
val parent = taskDao.createNew(
|
||||
Task(
|
||||
recurrence = "RRULE:FREQ=DAILY;INTERVAL=1"
|
||||
)
|
||||
)
|
||||
val child = taskDao.createNew(
|
||||
Task(
|
||||
parent = parent,
|
||||
completionDate = currentTimeMillis(),
|
||||
)
|
||||
)
|
||||
|
||||
clearCompleted()
|
||||
|
||||
assertFalse(taskDao.fetch(child)!!.isDeleted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dontDeleteTaskWithRecurringGrandparent() = runBlocking {
|
||||
val grandparent = taskDao.createNew(
|
||||
Task(recurrence = "RRULE:FREQ=DAILY;INTERVAL=1")
|
||||
)
|
||||
val parent = taskDao.createNew(
|
||||
Task(parent = grandparent)
|
||||
)
|
||||
val child = taskDao.createNew(
|
||||
Task(
|
||||
parent = parent,
|
||||
completionDate = currentTimeMillis(),
|
||||
)
|
||||
)
|
||||
|
||||
clearCompleted()
|
||||
|
||||
assertFalse(taskDao.fetch(child)!!.isDeleted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clearGrandchildWithNoRecurringAncestors() = runBlocking {
|
||||
val grandparent = taskDao.createNew(Task())
|
||||
val parent = taskDao.createNew(
|
||||
Task(parent = grandparent)
|
||||
)
|
||||
val child = taskDao.createNew(
|
||||
Task(
|
||||
parent = parent,
|
||||
completionDate = currentTimeMillis(),
|
||||
)
|
||||
)
|
||||
|
||||
clearCompleted()
|
||||
|
||||
assertTrue(taskDao.fetch(child)!!.isDeleted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clearGrandchildWithCompletedRecurringAncestor() = runBlocking {
|
||||
val grandparent = taskDao.createNew(
|
||||
Task(
|
||||
recurrence = "RRULE:FREQ=DAILY;INTERVAL=1",
|
||||
completionDate = currentTimeMillis(),
|
||||
)
|
||||
)
|
||||
val parent = taskDao.createNew(
|
||||
Task(parent = grandparent)
|
||||
)
|
||||
val child = taskDao.createNew(
|
||||
Task(
|
||||
parent = parent,
|
||||
completionDate = currentTimeMillis(),
|
||||
)
|
||||
)
|
||||
|
||||
clearCompleted()
|
||||
|
||||
assertTrue(taskDao.fetch(child)!!.isDeleted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clearHiddenSubtask() = runBlocking {
|
||||
preferences.showCompleted = false
|
||||
val parent = taskDao.createNew(Task())
|
||||
val child = taskDao.createNew(
|
||||
Task(
|
||||
parent = parent,
|
||||
completionDate = currentTimeMillis(),
|
||||
)
|
||||
)
|
||||
|
||||
clearCompleted()
|
||||
|
||||
assertTrue(taskDao.fetch(child)!!.isDeleted)
|
||||
}
|
||||
|
||||
private suspend fun clearCompleted() = viewModel.markDeleted(viewModel.getTasksToClear())
|
||||
}
|
@ -0,0 +1,205 @@
|
||||
package com.todoroo.astrid.activity
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.todoroo.astrid.activity.MainActivity.Companion.LOAD_FILTER
|
||||
import com.todoroo.astrid.activity.MainActivity.Companion.OPEN_FILTER
|
||||
import com.todoroo.astrid.api.CaldavFilter
|
||||
import com.todoroo.astrid.api.CustomFilter
|
||||
import com.todoroo.astrid.api.Filter
|
||||
import com.todoroo.astrid.api.GtasksFilter
|
||||
import com.todoroo.astrid.api.TagFilter
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.tasks.LocalBroadcastManager
|
||||
import org.tasks.R
|
||||
import org.tasks.Tasks.Companion.IS_GENERIC
|
||||
import org.tasks.billing.Inventory
|
||||
import org.tasks.compose.drawer.DrawerItem
|
||||
import org.tasks.data.dao.CaldavDao
|
||||
import org.tasks.data.NO_COUNT
|
||||
import org.tasks.data.entity.Task
|
||||
import org.tasks.data.dao.TaskDao
|
||||
import org.tasks.data.count
|
||||
import org.tasks.filters.FilterProvider
|
||||
import org.tasks.filters.NavigationDrawerSubheader
|
||||
import org.tasks.filters.PlaceFilter
|
||||
import org.tasks.preferences.DefaultFilterProvider
|
||||
import org.tasks.preferences.Preferences
|
||||
import org.tasks.themes.ColorProvider
|
||||
import org.tasks.themes.CustomIcons
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class MainActivityViewModel @Inject constructor(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
private val defaultFilterProvider: DefaultFilterProvider,
|
||||
private val filterProvider: FilterProvider,
|
||||
private val taskDao: TaskDao,
|
||||
private val localBroadcastManager: LocalBroadcastManager,
|
||||
private val inventory: Inventory,
|
||||
private val colorProvider: ColorProvider,
|
||||
private val caldavDao: CaldavDao,
|
||||
private val preferences: Preferences,
|
||||
) : ViewModel() {
|
||||
|
||||
data class State(
|
||||
val begForMoney: Boolean = false,
|
||||
val filter: Filter,
|
||||
val task: Task? = null,
|
||||
val drawerOpen: Boolean = false,
|
||||
val drawerItems: ImmutableList<DrawerItem> = persistentListOf(),
|
||||
)
|
||||
|
||||
private val _state = MutableStateFlow(
|
||||
State(
|
||||
filter = savedStateHandle.get<Filter>(OPEN_FILTER)
|
||||
?: savedStateHandle.get<String>(LOAD_FILTER)?.let {
|
||||
runBlocking { defaultFilterProvider.getFilterFromPreference(it) }
|
||||
}
|
||||
?: runBlocking { defaultFilterProvider.getStartupFilter() },
|
||||
begForMoney = if (IS_GENERIC) !inventory.hasTasksAccount else !inventory.hasPro,
|
||||
)
|
||||
)
|
||||
val state = _state.asStateFlow()
|
||||
|
||||
private val refreshReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
when (intent?.action) {
|
||||
LocalBroadcastManager.REFRESH,
|
||||
LocalBroadcastManager.REFRESH_LIST -> updateFilters()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun resetFilter() {
|
||||
setFilter(defaultFilterProvider.getDefaultOpenFilter())
|
||||
}
|
||||
|
||||
fun setFilter(
|
||||
filter: Filter,
|
||||
task: Task? = null,
|
||||
) {
|
||||
if (filter == _state.value.filter && task == null) {
|
||||
return
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
filter = filter,
|
||||
task = task,
|
||||
)
|
||||
}
|
||||
updateFilters()
|
||||
defaultFilterProvider.setLastViewedFilter(filter)
|
||||
}
|
||||
|
||||
fun setDrawerOpen(open: Boolean) {
|
||||
_state.update { it.copy(drawerOpen = open) }
|
||||
}
|
||||
|
||||
init {
|
||||
localBroadcastManager.registerRefreshListReceiver(refreshReceiver)
|
||||
updateFilters()
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
localBroadcastManager.unregisterReceiver(refreshReceiver)
|
||||
}
|
||||
|
||||
fun updateFilters() = viewModelScope.launch(Dispatchers.Default) {
|
||||
val selected = state.value.filter
|
||||
filterProvider
|
||||
.drawerItems()
|
||||
.map { item ->
|
||||
when (item) {
|
||||
is Filter ->
|
||||
DrawerItem.Filter(
|
||||
title = item.title ?: "",
|
||||
icon = getIcon(item),
|
||||
color = getColor(item),
|
||||
count = item.count.takeIf { it != NO_COUNT } ?: try {
|
||||
taskDao.count(item)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
0
|
||||
},
|
||||
selected = item.areItemsTheSame(selected),
|
||||
shareCount = if (item is CaldavFilter) item.principals else 0,
|
||||
type = { item },
|
||||
)
|
||||
is NavigationDrawerSubheader ->
|
||||
DrawerItem.Header(
|
||||
title = item.title ?: "",
|
||||
collapsed = item.isCollapsed,
|
||||
hasError = item.error,
|
||||
canAdd = item.addIntent != null,
|
||||
type = { item },
|
||||
)
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
.let { filters -> _state.update { it.copy(drawerItems = filters.toPersistentList()) } }
|
||||
}
|
||||
|
||||
private fun getColor(filter: Filter): Int {
|
||||
if (filter.tint != 0) {
|
||||
val color = colorProvider.getThemeColor(filter.tint, true)
|
||||
if (color.isFree || inventory.purchasedThemes()) {
|
||||
return color.primaryColor
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
private fun getIcon(filter: Filter): Int {
|
||||
if (filter.icon < 1000 || filter.icon == CustomIcons.PLACE || inventory.hasPro) {
|
||||
val icon = CustomIcons.getIconResId(filter.icon)
|
||||
if (icon != null) {
|
||||
return icon
|
||||
}
|
||||
}
|
||||
return when (filter) {
|
||||
is TagFilter -> R.drawable.ic_outline_label_24px
|
||||
is GtasksFilter,
|
||||
is CaldavFilter -> R.drawable.ic_list_24px
|
||||
|
||||
is CustomFilter -> R.drawable.ic_outline_filter_list_24px
|
||||
is PlaceFilter -> R.drawable.ic_outline_place_24px
|
||||
else -> filter.icon
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleCollapsed(subheader: NavigationDrawerSubheader) = viewModelScope.launch {
|
||||
val collapsed = !subheader.isCollapsed
|
||||
when (subheader.subheaderType) {
|
||||
NavigationDrawerSubheader.SubheaderType.PREFERENCE -> {
|
||||
preferences.setBoolean(subheader.id.toInt(), collapsed)
|
||||
localBroadcastManager.broadcastRefreshList()
|
||||
}
|
||||
NavigationDrawerSubheader.SubheaderType.GOOGLE_TASKS,
|
||||
NavigationDrawerSubheader.SubheaderType.CALDAV,
|
||||
NavigationDrawerSubheader.SubheaderType.TASKS,
|
||||
NavigationDrawerSubheader.SubheaderType.ETESYNC -> {
|
||||
caldavDao.setCollapsed(subheader.id, collapsed)
|
||||
localBroadcastManager.broadcastRefreshList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setTask(task: Task?) {
|
||||
_state.update { it.copy(task = task) }
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.todoroo.astrid.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.tasks.databinding.FilterAdapterActionBinding
|
||||
import org.tasks.filters.NavigationDrawerAction
|
||||
import org.tasks.themes.DrawableUtil
|
||||
|
||||
class ActionViewHolder internal constructor(
|
||||
private val context: Context,
|
||||
itemView: View,
|
||||
private val onClick: (NavigationDrawerAction) -> Unit
|
||||
) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
private val row: View
|
||||
private val text: TextView
|
||||
private val icon: ImageView
|
||||
|
||||
init {
|
||||
FilterAdapterActionBinding.bind(itemView).let {
|
||||
row = it.row
|
||||
text = it.text
|
||||
icon = it.icon
|
||||
}
|
||||
}
|
||||
|
||||
fun bind(filter: NavigationDrawerAction) {
|
||||
text.text = filter.title
|
||||
icon.setImageDrawable(DrawableUtil.getWrapped(context, filter.icon))
|
||||
row.setOnClickListener {
|
||||
onClick.invoke(filter)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package com.todoroo.astrid.adapter
|
||||
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class SeparatorViewHolder internal constructor(itemView: View) : RecyclerView.ViewHolder(itemView)
|
@ -0,0 +1,8 @@
|
||||
package com.todoroo.astrid.api
|
||||
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
class EmptyFilter(override val sql: String? = "WHERE 0", override val title: String? = null) : Filter {
|
||||
override fun areItemsTheSame(other: FilterListItem): Boolean = false
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue