Skip to content

Commit bba2c23

Browse files
committed
fix: override abstract methods in location listener
Some `LocationListener` methods don't have default implementations on Android 10 and older versions, and that leads to a crash. Refs: #177
1 parent 68f7a85 commit bba2c23

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

app/src/main/kotlin/org/fossify/camera/helpers/SimpleLocationManager.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.Manifest
44
import android.location.Location
55
import android.location.LocationListener
66
import android.location.LocationManager
7+
import android.os.Bundle
78
import androidx.annotation.RequiresPermission
89
import org.fossify.camera.extensions.checkLocationPermission
910
import org.fossify.commons.activities.BaseSimpleActivity
@@ -15,12 +16,21 @@ class SimpleLocationManager(private val activity: BaseSimpleActivity) {
1516
private const val LOCATION_UPDATE_MIN_DISTANCE_M = 10F
1617
}
1718

19+
private var location: Location? = null
20+
1821
private val locationManager = activity.getSystemService(LocationManager::class.java)!!
19-
private val locationListener = LocationListener { location ->
20-
this@SimpleLocationManager.location = location
21-
}
22+
private val locationListener = object: LocationListener {
23+
override fun onLocationChanged(location: Location) {
24+
this@SimpleLocationManager.location = location
25+
}
2226

23-
private var location: Location? = null
27+
// No-op methods that must be overridden.
28+
// See https://github.com/FossifyOrg/Camera/issues/177
29+
@Suppress("DEPRECATION")
30+
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {}
31+
override fun onProviderEnabled(provider: String) {}
32+
override fun onProviderDisabled(provider: String) {}
33+
}
2434

2535
fun getLocation(): Location? {
2636
if (location == null) {

0 commit comments

Comments
 (0)