Use coroutines in geofence api

pull/1055/head
Alex Baker 4 years ago
parent 20353023d8
commit 789836058d

@ -2,7 +2,7 @@ package com.todoroo.astrid.reminders
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.data.Task
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
@ -38,7 +38,7 @@ import javax.inject.Inject
@HiltAndroidTest
class ReminderServiceTest : InjectingTestCase() {
@Inject lateinit var preferences: Preferences
@Inject lateinit var taskDao: TaskDaoBlocking
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var jobs: NotificationQueue
private lateinit var service: ReminderService

@ -8,7 +8,7 @@ import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingRequest
import com.google.android.gms.location.LocationServices
import dagger.hilt.android.qualifiers.ApplicationContext
import org.tasks.data.LocationDaoBlocking
import org.tasks.data.LocationDao
import org.tasks.data.MergedGeofence
import org.tasks.data.Place
import org.tasks.preferences.PermissionChecker
@ -18,16 +18,16 @@ import javax.inject.Inject
class GeofenceApi @Inject constructor(
@param:ApplicationContext private val context: Context,
private val permissionChecker: PermissionChecker,
private val locationDao: LocationDaoBlocking) {
private val locationDao: LocationDao) {
fun registerAll() = locationDao.getPlacesWithGeofences().forEach(this::update)
suspend fun registerAll() = locationDao.getPlacesWithGeofences().forEach { update(it) }
fun update(taskId: Long) = locationDao.getPlaceForTask(taskId).apply(this::update)
suspend fun update(taskId: Long) = update(locationDao.getPlaceForTask(taskId))
fun update(place: String) = locationDao.getPlace(place).apply(this::update)
suspend fun update(place: String) = update(locationDao.getPlace(place))
@SuppressLint("MissingPermission")
fun update(place: Place?) {
suspend fun update(place: Place?) {
if (place == null || !permissionChecker.canAccessLocation()) {
return
}
@ -63,5 +63,4 @@ class GeofenceApi @Inject constructor(
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.build()
}
}

@ -12,8 +12,10 @@ import com.todoroo.astrid.service.Upgrader
import dagger.Lazy
import dagger.hilt.android.HiltAndroidApp
import dagger.hilt.android.qualifiers.ApplicationContext
import io.reactivex.Completable
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import org.tasks.billing.BillingClient
import org.tasks.billing.Inventory
import org.tasks.files.FileHelper
@ -33,6 +35,7 @@ import javax.inject.Inject
@HiltAndroidApp
class Tasks : Application(), Configuration.Provider {
@Inject @ApplicationContext lateinit var context: Context
@Inject lateinit var preferences: Preferences
@Inject lateinit var buildSetup: BuildSetup
@ -54,7 +57,7 @@ class Tasks : Application(), Configuration.Provider {
ThemeBase.getThemeBase(preferences, inventory, null).setDefaultNightMode()
localBroadcastManager.registerRefreshReceiver(RefreshBroadcastReceiver())
Locale.getInstance(this).createConfigurationContext(applicationContext)
Completable.fromAction { doInBackground() }.subscribeOn(Schedulers.io()).subscribe()
backgroundWork()
}
private fun upgrade() {
@ -69,14 +72,16 @@ class Tasks : Application(), Configuration.Provider {
}
}
private fun doInBackground() {
private fun backgroundWork() = CoroutineScope(Dispatchers.IO + SupervisorJob()).launch {
NotificationSchedulerIntentService.enqueueWork(context, false)
CalendarNotificationIntentService.enqueueWork(context)
refreshScheduler.get().scheduleAll()
workManager.get().updateBackgroundSync()
workManager.get().scheduleMidnightRefresh()
workManager.get().scheduleBackup()
workManager.get().scheduleConfigRefresh()
workManager.get().apply {
updateBackgroundSync()
scheduleMidnightRefresh()
scheduleBackup()
scheduleConfigRefresh()
}
geofenceApi.get().registerAll()
FileHelper.delete(context, preferences.cacheDirectory)
billingClient.get().queryPurchases()

Loading…
Cancel
Save