Add triggerNotifications for geofences

pull/1360/head
Alex Baker 4 years ago
parent e67148d793
commit 598cbba8c1

@ -6,14 +6,10 @@ import android.content.Intent
import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingEvent
import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.reminders.ReminderService
import dagger.hilt.android.AndroidEntryPoint
import org.tasks.Notifier
import org.tasks.data.LocationDao
import org.tasks.data.Place
import org.tasks.injection.InjectingJobIntentService
import org.tasks.notifications.Notification
import org.tasks.time.DateTimeUtils
import timber.log.Timber
import javax.inject.Inject
@ -53,23 +49,12 @@ class GeofenceTransitionsIntentService : InjectingJobIntentService() {
} else {
locationDao.getDepartureGeofences(place.uid!!, DateUtilities.now())
}
geofences
.map { toNotification(place, it, arrival) }
.let { notifier.triggerNotifications(it) }
notifier.triggerNotifications(place.id, geofences, arrival)
} catch (e: Exception) {
Timber.e(e, "Error triggering geofence %s: %s", requestId, e.message)
}
}
private fun toNotification(place: Place, geofence: org.tasks.data.Geofence?, arrival: Boolean): Notification {
val notification = Notification()
notification.taskId = geofence!!.task
notification.type = if (arrival) ReminderService.TYPE_GEOFENCE_ENTER else ReminderService.TYPE_GEOFENCE_EXIT
notification.timestamp = DateTimeUtils.currentTimeMillis()
notification.location = place.id
return notification
}
class Broadcast : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
enqueueWork(

@ -5,9 +5,12 @@ import android.content.Context
import androidx.core.app.NotificationCompat
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.reminders.ReminderService
import com.todoroo.astrid.reminders.ReminderService.Companion.TYPE_GEOFENCE_ENTER
import com.todoroo.astrid.reminders.ReminderService.Companion.TYPE_GEOFENCE_EXIT
import com.todoroo.astrid.voice.VoiceOutputAssistant
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.delay
import org.tasks.data.Geofence
import org.tasks.data.TaskDao
import org.tasks.intents.TaskIntents
import org.tasks.notifications.AudioManager
@ -65,6 +68,19 @@ class Notifier @Inject constructor(
notificationManager.notify(filter.listingTitle.hashCode().toLong(), builder, true, false, false)
}
suspend fun triggerNotifications(place: Long, geofences: List<Geofence>, arrival: Boolean) =
geofences
.filter { if (arrival) it.isArrival else it.isDeparture }
.map {
Notification().apply {
taskId = it.task
type = if (arrival) TYPE_GEOFENCE_ENTER else TYPE_GEOFENCE_EXIT
timestamp = DateTimeUtils.currentTimeMillis()
location = place
}
}
.let { triggerNotifications(it) }
suspend fun triggerNotifications(entries: List<Notification>) {
var ringFiveTimes = false
var ringNonstop = false

Loading…
Cancel
Save