mirror of https://github.com/tasks/tasks
parent
0e728152c9
commit
90bc28c91c
@ -1,21 +0,0 @@
|
|||||||
package org.tasks.location
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
|
||||||
import com.google.android.gms.location.LocationServices
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
|
||||||
|
|
||||||
class PlayLocationProvider(private val context: Context) : LocationProvider {
|
|
||||||
@SuppressLint("MissingPermission")
|
|
||||||
override suspend fun currentLocation(): MapPosition = withContext(Dispatchers.IO) {
|
|
||||||
suspendCoroutine { cont ->
|
|
||||||
LocationServices.getFusedLocationProviderClient(context).lastLocation
|
|
||||||
.addOnSuccessListener {
|
|
||||||
cont.resumeWith(Result.success(MapPosition(it.latitude, it.longitude)))
|
|
||||||
}
|
|
||||||
.addOnFailureListener { cont.resumeWith(Result.failure(it)) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
package org.tasks.location
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.app.PendingIntent
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.location.LocationManager
|
|
||||||
import android.net.Uri
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import org.tasks.data.MergedGeofence
|
|
||||||
import org.tasks.data.Place
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@Suppress("unused")
|
|
||||||
class AndroidGeofencing @Inject constructor(
|
|
||||||
@ApplicationContext private val context: Context
|
|
||||||
): Geofencing {
|
|
||||||
private val client = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
|
||||||
override fun addGeofences(geofence: MergedGeofence) {
|
|
||||||
client.addProximityAlert(
|
|
||||||
geofence.latitude,
|
|
||||||
geofence.longitude,
|
|
||||||
geofence.radius.toFloat(),
|
|
||||||
-1,
|
|
||||||
createPendingIntent(geofence.place.id)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun removeGeofences(place: Place) {
|
|
||||||
client.removeProximityAlert(createPendingIntent(place.id))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createPendingIntent(place: Long) =
|
|
||||||
PendingIntent.getBroadcast(
|
|
||||||
context,
|
|
||||||
0,
|
|
||||||
Intent(context, AndroidGeofenceTransitionIntentService.Broadcast::class.java)
|
|
||||||
.setData(Uri.parse("tasks://geofence/$place")),
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,7 +1,17 @@
|
|||||||
package org.tasks.location
|
package org.tasks.location
|
||||||
|
|
||||||
|
import android.app.PendingIntent
|
||||||
import android.location.Location
|
import android.location.Location
|
||||||
|
|
||||||
interface LocationManager {
|
interface LocationManager {
|
||||||
val lastKnownLocations: List<Location>
|
val lastKnownLocations: List<Location>
|
||||||
|
|
||||||
|
fun addProximityAlert(
|
||||||
|
latitude: Double,
|
||||||
|
longitude: Double,
|
||||||
|
radius: Float,
|
||||||
|
intent: PendingIntent
|
||||||
|
)
|
||||||
|
|
||||||
|
fun removeProximityAlert(intent: PendingIntent)
|
||||||
}
|
}
|
||||||
@ -1,5 +0,0 @@
|
|||||||
package org.tasks.location
|
|
||||||
|
|
||||||
interface LocationProvider {
|
|
||||||
suspend fun currentLocation(): MapPosition?
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue