Skip to content

Commit

Permalink
[NO ISSUE] Solved issue where none of the location permissions where …
Browse files Browse the repository at this point in the history
…granted returned an error (#364)

* [NO ISSUE] Solved issue where none of the location permissions where granted returned an error

* ktlint issue

* changed patch version
  • Loading branch information
ferranpons authored Sep 29, 2022
1 parent 82d994e commit bf2531a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx2048m
org.gradle.configureondemand=false
android.useAndroidX=true
libGroup=com.adevinta.android
libVersion=10.0.0
libVersion=10.0.1
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.adevinta.leku.utils

import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.location.Location
import androidx.annotation.RequiresPermission
import androidx.core.content.ContextCompat
import com.google.android.gms.location.LocationServices
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
Expand All @@ -15,16 +18,22 @@ class ReactiveLocationProvider(
anyOf = ["android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"]
)
suspend fun getLastKnownLocation(): Location? = suspendCoroutine { task ->
LocationServices.getFusedLocationProviderClient(context)
.lastLocation
.addOnCompleteListener { locTask ->
task.resume(locTask.result)
}
.addOnCanceledListener {
task.resume(null)
}
.addOnFailureListener {
task.resume(null)
}
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
) {
LocationServices.getFusedLocationProviderClient(context)
.lastLocation
.addOnCompleteListener { locTask ->
task.resume(locTask.result)
}
.addOnCanceledListener {
task.resume(null)
}
.addOnFailureListener {
task.resume(null)
}
} else {
task.resume(null)
}
}
}

0 comments on commit bf2531a

Please sign in to comment.