diff --git a/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt b/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt index 4f9a92edb..4b838b65c 100644 --- a/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt +++ b/app/src/androidTest/java/org/tasks/data/LocationDaoTest.kt @@ -2,10 +2,12 @@ package org.tasks.data 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 org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith +import org.tasks.Freeze import org.tasks.caldav.GeoUtils.toLikeString import org.tasks.date.DateTimeUtils.newDateTime import org.tasks.injection.InjectingTestCase @@ -108,6 +110,56 @@ class LocationDaoTest : InjectingTestCase() { assertNull(locationDao.getGeofencesByPlace(place.uid)) } + @Test + fun ignoreArrivalForSnoozedTask() { + Freeze.freezeAt(now()).thawAfter { + val place = newPlace() + locationDao.insert(place) + taskDao.createNew(newTask(with(ID, 1), with(SNOOZE_TIME, newDateTime().plusMinutes(15)))) + locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true))) + + assertTrue(locationDao.getArrivalGeofences(place.uid, now()).isEmpty()) + } + } + + @Test + fun ignoreDepartureForSnoozedTask() { + Freeze.freezeAt(now()).thawAfter { + val place = newPlace() + locationDao.insert(place) + taskDao.createNew(newTask(with(ID, 1), with(SNOOZE_TIME, newDateTime().plusMinutes(15)))) + locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true))) + + assertTrue(locationDao.getDepartureGeofences(place.uid, now()).isEmpty()) + } + } + + @Test + fun getArrivalWithElapsedSnooze() { + Freeze.freezeAt(now()).thawAfter { + val place = newPlace() + locationDao.insert(place) + taskDao.createNew(newTask(with(ID, 1), with(SNOOZE_TIME, newDateTime().minusMinutes(15)))) + 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 getDepartureWithElapsedSnooze() { + Freeze.freezeAt(now()).thawAfter { + val place = newPlace() + locationDao.insert(place) + taskDao.createNew(newTask(with(ID, 1), with(SNOOZE_TIME, newDateTime().minusMinutes(15)))) + 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/googleplay/java/org/tasks/location/GeofenceTransitionsIntentService.java b/app/src/googleplay/java/org/tasks/location/GeofenceTransitionsIntentService.java index 6c8eb7e0e..d5502cbfa 100644 --- a/app/src/googleplay/java/org/tasks/location/GeofenceTransitionsIntentService.java +++ b/app/src/googleplay/java/org/tasks/location/GeofenceTransitionsIntentService.java @@ -2,6 +2,7 @@ package org.tasks.location; import static com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER; import static com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_EXIT; +import static com.todoroo.andlib.utility.DateUtilities.now; import static com.todoroo.astrid.reminders.ReminderService.TYPE_GEOFENCE_ENTER; import static com.todoroo.astrid.reminders.ReminderService.TYPE_GEOFENCE_EXIT; import static org.tasks.time.DateTimeUtils.currentTimeMillis; @@ -65,8 +66,8 @@ public class GeofenceTransitionsIntentService extends InjectingJobIntentService return; } List geofences = arrival - ? locationDao.getArrivalGeofences(place.getUid()) - : locationDao.getDepartureGeofences(place.getUid()); + ? locationDao.getArrivalGeofences(place.getUid(), now()) + : locationDao.getDepartureGeofences(place.getUid(), now()); notifier.triggerNotifications( Lists.transform(geofences, g -> toNotification(place, g, arrival))); } catch (Exception e) { diff --git a/app/src/main/java/org/tasks/data/LocationDao.java b/app/src/main/java/org/tasks/data/LocationDao.java index b030373db..08fe6a2d6 100644 --- a/app/src/main/java/org/tasks/data/LocationDao.java +++ b/app/src/main/java/org/tasks/data/LocationDao.java @@ -43,14 +43,14 @@ 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") - List getArrivalGeofences(String place); + + " WHERE place = :place AND arrival = 1 AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.snoozeTime < :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") - List getDepartureGeofences(String place); + + " WHERE place = :place AND departure = 1 AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.snoozeTime < :now") + List getDepartureGeofences(String place, long now); @Query( "SELECT * FROM geofences"