Skip to content

Commit

Permalink
Fix #65
Browse files Browse the repository at this point in the history
(cherry picked from commit 1085bb6)
  • Loading branch information
BirjuVachhani committed Jun 5, 2022
1 parent b729860 commit 10a34ea
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion locus/src/main/java/com/birjuvachhani/locus/LocationProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import android.content.Context
import android.os.Looper
import androidx.lifecycle.MutableLiveData
import com.google.android.gms.location.*
import com.google.android.gms.tasks.CancellationToken
import com.google.android.gms.tasks.OnTokenCanceledListener
import java.util.concurrent.atomic.AtomicBoolean

/*
Expand Down Expand Up @@ -94,7 +96,11 @@ internal class LocationProvider(context: Context) {
onUpdate(LocusResult.error(error = error))
}
}
mFusedLocationProviderClient.lastLocation.addOnSuccessListener { location ->

mFusedLocationProviderClient.getCurrentLocation(
request.priority,
EmptyCancellationToken()
).addOnSuccessListener { location ->
location?.let { onUpdate(LocusResult.success(it)) }
}.addOnFailureListener {
logError(it)
Expand All @@ -112,4 +118,10 @@ internal class LocationProvider(context: Context) {
locationLiveData = MutableLiveData()
mFusedLocationProviderClient.removeLocationUpdates(pendingIntent)
}
}

class EmptyCancellationToken : CancellationToken() {
override fun onCanceledRequested(p0: OnTokenCanceledListener): CancellationToken = this

override fun isCancellationRequested(): Boolean = false
}

0 comments on commit 10a34ea

Please sign in to comment.