This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Wrapper class for handling Location related methods | |
*/ | |
class HuaweiLocationManager constructor(private val context : Context) { | |
//region vars | |
private val mFusedLocationProviderClient: FusedLocationProviderClient by lazy { | |
LocationServices.getFusedLocationProviderClient(context) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun checkLocationSettingsAndShowPopup( | |
activity: Activity, | |
onSuccess: ((locationSettingsResponse: LocationSettingsResponse?) -> Unit)? = null | |
) { | |
val builder = LocationSettingsRequest.Builder() | |
val locationRequest = LocationRequest() | |
builder.addLocationRequest(locationRequest) | |
val locationSettingsRequest = builder.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun unregisterLocationUpdates() { | |
mLocationCallback?.let { locationCallback -> | |
mFusedLocationProviderClient.removeLocationUpdates(locationCallback) | |
.addOnSuccessListener { | |
// Requesting location updates is stopped successfully. | |
LogUtils.d("LocationKit -> Stop Listening Location Successfully") | |
} | |
.addOnFailureListener { | |
// Failed to stop requesting location updates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun registerLocationUpdates( | |
interval: Long = 10000, | |
onSuccess: ((location: Location?) -> Unit)? = null, | |
onFail: ((locationAvailability: LocationAvailability?) -> Unit)? = null | |
) { | |
val mLocationRequest = LocationRequest() | |
// Set the location update interval (in milliseconds). | |
mLocationRequest.interval = interval | |
// Set the weight. | |
mLocationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun createLocationCallback( | |
onSuccess: ((location: Location?) -> Unit)? = null, | |
onFail: ((locationAvailability: LocationAvailability?) -> Unit)? = null | |
): LocationCallback { | |
return object : LocationCallback() { | |
override fun onLocationResult(locationResult: LocationResult) { | |
val currentLatLng = LatLng( | |
locationResult.lastLocation.latitude, | |
locationResult.lastLocation.longitude | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getLastKnownLocation( | |
onSuccess: ((lastKnownLocation: Location?) -> Unit)? = null, | |
onFail: ((exception: Exception) -> Unit)? = null | |
) { | |
val task: Task<Location> = mFusedLocationProviderClient.lastLocation | |
task.addOnSuccessListener { lastKnowLocation -> | |
if (lastKnowLocation == null) { | |
LogUtils.d("LocationKit -> Last Known Location is empty") | |
} else { |
NewerOlder