Aperture: Avoid null asserts
Change-Id: I50fc1241476f76f5e8720f601219c5d2a6ac396f
diff --git a/app/src/main/java/org/lineageos/aperture/MainActivity.kt b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
index f43f9b0..e5a9a18 100644
--- a/app/src/main/java/org/lineageos/aperture/MainActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
@@ -178,10 +178,15 @@
private var location: Location? = null
private val locationListener = object : LocationListener {
- override fun onLocationChanged(it: Location) {
- if (location == null || location!!.accuracy >= it.accuracy) {
- location = it
- }
+ override fun onLocationChanged(location: Location) {
+ val mainActivity = this@MainActivity
+ mainActivity.location = mainActivity.location?.let {
+ if (it.accuracy >= location.accuracy) {
+ location
+ } else {
+ mainActivity.location
+ }
+ } ?: location
}
@SuppressLint("MissingPermission")