From bbd9a24bc7ac70c643cc0e2257707a271a80d224 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Mon, 27 Apr 2020 09:01:01 -0500 Subject: [PATCH] Ignore geofence triggers for hidden tasks --- .../java/org/tasks/data/LocationDaoTest.kt | 63 +++++++++++++++++++ .../main/java/org/tasks/data/LocationDao.java | 6 +- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt b/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt index 4b838b65c..ee41a8098 100644 --- a/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt +++ b/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt @@ -4,6 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import com.natpryce.makeiteasy.MakeItEasy.with import com.todoroo.andlib.utility.DateUtilities.now import com.todoroo.astrid.dao.TaskDao +import com.todoroo.astrid.data.Task import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith @@ -160,6 +161,68 @@ class LocationDaoTest : InjectingTestCase() { } } + @Test + fun ignoreArrivalForHiddenTask() { + Freeze.freezeAt(now()).thawAfter { + val place = newPlace() + locationDao.insert(place) + taskDao.createNew(newTask( + with(ID, 1), + with(DUE_TIME, newDateTime().plusMinutes(15)), + with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))) + locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true))) + + assertTrue(locationDao.getArrivalGeofences(place.uid, now()).isEmpty()) + } + } + + @Test + fun ignoreDepartureForHiddenTask() { + Freeze.freezeAt(now()).thawAfter { + val place = newPlace() + locationDao.insert(place) + taskDao.createNew(newTask( + with(ID, 1), + with(DUE_TIME, newDateTime().plusMinutes(15)), + with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))) + locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true))) + + assertTrue(locationDao.getDepartureGeofences(place.uid, now()).isEmpty()) + } + } + + @Test + fun getArrivalWithElapsedHideUntil() { + Freeze.freezeAt(now()).thawAfter { + val place = newPlace() + locationDao.insert(place) + taskDao.createNew(newTask( + with(ID, 1), + with(DUE_TIME, newDateTime().minusMinutes(15)), + with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))) + val geofence = newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true)) + geofence.id = locationDao.insert(geofence) + + assertEquals(listOf(geofence), locationDao.getArrivalGeofences(place.uid, now())) + } + } + + @Test + fun getDepartureWithElapsedHideUntil() { + Freeze.freezeAt(now()).thawAfter { + val place = newPlace() + locationDao.insert(place) + taskDao.createNew(newTask( + with(ID, 1), + with(DUE_TIME, newDateTime().minusMinutes(15)), + with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME))) + val geofence = newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true)) + geofence.id = locationDao.insert(geofence) + + assertEquals(listOf(geofence), locationDao.getDepartureGeofences(place.uid, now())) + } + } + override fun inject(component: TestComponent) = component.inject(this) } diff --git a/app/src/main/java/org/tasks/data/LocationDao.java b/app/src/main/java/org/tasks/data/LocationDao.java index 08fe6a2d6..76cdbd844 100644 --- a/app/src/main/java/org/tasks/data/LocationDao.java +++ b/app/src/main/java/org/tasks/data/LocationDao.java @@ -43,13 +43,15 @@ public interface LocationDao { @Query( "SELECT geofences.* FROM geofences" + " INNER JOIN tasks ON tasks._id = geofences.task" - + " WHERE place = :place AND arrival = 1 AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.snoozeTime < :now") + + " WHERE place = :place AND arrival = 1 AND tasks.completed = 0" + + " AND tasks.deleted = 0 AND tasks.snoozeTime < :now AND tasks.hideUntil < :now") List getArrivalGeofences(String place, long now); @Query( "SELECT geofences.* FROM geofences" + " INNER JOIN tasks ON tasks._id = geofences.task" - + " WHERE place = :place AND departure = 1 AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.snoozeTime < :now") + + " WHERE place = :place AND departure = 1 AND tasks.completed = 0" + + " AND tasks.deleted = 0 AND tasks.snoozeTime < :now AND tasks.hideUntil < :now") List getDepartureGeofences(String place, long now); @Query(