Ignore geofence trigger if task is snoozed

pull/996/head
Alex Baker 4 years ago
parent ebe84e74f3
commit cc632a4271

@ -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)
}

@ -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<Geofence> 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) {

@ -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<Geofence> getArrivalGeofences(String place);
+ " WHERE place = :place AND arrival = 1 AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.snoozeTime < :now")
List<Geofence> 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<Geofence> getDepartureGeofences(String place);
+ " WHERE place = :place AND departure = 1 AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.snoozeTime < :now")
List<Geofence> getDepartureGeofences(String place, long now);
@Query(
"SELECT * FROM geofences"

Loading…
Cancel
Save