diff --git a/commons/src/main/AndroidManifest.xml b/commons/src/main/AndroidManifest.xml index 6c8c73cf91e..ca0581910d4 100644 --- a/commons/src/main/AndroidManifest.xml +++ b/commons/src/main/AndroidManifest.xml @@ -1,6 +1,9 @@ + Unit, ) { if (hasPermission()) { - locationListener = object : LocationListener { + locationListener = object : LocationListenerCompat { override fun onLocationChanged(location: Location) { onNewLocation(location) } @@ -67,15 +67,10 @@ open class LocationProviderImpl(val context: Context) : LocationProvider { override fun onProviderDisabled(provider: String) { onLocationProviderChanged() } - - @Deprecated("Deprecated in Java") - override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) { - // Need implementation for compatibility - } } locationManager.requestLocationUpdates( - LocationManager.GPS_PROVIDER, + LocationManager.NETWORK_PROVIDER, 500, 0f, requireNotNull(locationListener), diff --git a/dhis2_android_maps/src/main/java/org/dhis2/maps/managers/MapManager.kt b/dhis2_android_maps/src/main/java/org/dhis2/maps/managers/MapManager.kt index 2ad58dab762..9ac0e010480 100644 --- a/dhis2_android_maps/src/main/java/org/dhis2/maps/managers/MapManager.kt +++ b/dhis2_android_maps/src/main/java/org/dhis2/maps/managers/MapManager.kt @@ -2,9 +2,9 @@ package org.dhis2.maps.managers import android.annotation.SuppressLint import android.app.Activity -import android.location.LocationListener import android.os.Bundle import androidx.core.content.ContextCompat +import androidx.core.location.LocationListenerCompat import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleOwner @@ -79,7 +79,7 @@ abstract class MapManager( fun init( mapStyles: List, - locationListener: LocationListener? = null, + locationListener: LocationListenerCompat? = null, onInitializationFinished: () -> Unit = {}, onMissingPermission: (PermissionsManager?) -> Unit, ) { @@ -237,7 +237,7 @@ abstract class MapManager( private fun enableLocationComponent( style: Style, onMissingPermission: (PermissionsManager?) -> Unit, - locationListener: LocationListener?, + locationListener: LocationListenerCompat?, ) { map?.locationComponent?.apply { if (PermissionsManager.areLocationPermissionsGranted(mapView.context)) { diff --git a/dhis2_android_maps/src/main/java/org/dhis2/maps/views/MapSelectorActivity.kt b/dhis2_android_maps/src/main/java/org/dhis2/maps/views/MapSelectorActivity.kt index 88b474234e2..1bb6c3f784b 100644 --- a/dhis2_android_maps/src/main/java/org/dhis2/maps/views/MapSelectorActivity.kt +++ b/dhis2_android_maps/src/main/java/org/dhis2/maps/views/MapSelectorActivity.kt @@ -3,7 +3,6 @@ package org.dhis2.maps.views import android.annotation.SuppressLint import android.content.Context import android.content.Intent -import android.location.LocationListener import android.os.Bundle import androidx.activity.compose.setContent import androidx.activity.viewModels @@ -13,6 +12,7 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.core.location.LocationListenerCompat import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle @@ -39,7 +39,7 @@ class MapSelectorActivity : AppCompatActivity() { private val locationProvider = MapLocationEngine(this) - private val locationListener = LocationListener { location -> + private val locationListener = LocationListenerCompat { location -> mapSelectorViewModel.onNewLocation( SelectedLocation.GPSResult( location.latitude,