Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/middleware/AppLocationManager.kt
Show All 18 Lines | |||||
import android.Manifest | import android.Manifest | ||||
import android.content.Context | import android.content.Context | ||||
import android.content.pm.PackageManager | import android.content.pm.PackageManager | ||||
import android.location.* | import android.location.* | ||||
import android.os.Bundle | import android.os.Bundle | ||||
import android.util.Log | import android.util.Log | ||||
import androidx.core.content.ContextCompat | import androidx.core.content.ContextCompat | ||||
import androidx.core.location.LocationListenerCompat | |||||
import it.reyboz.bustorino.util.LocationCriteria | import it.reyboz.bustorino.util.LocationCriteria | ||||
import it.reyboz.bustorino.util.Permissions | import it.reyboz.bustorino.util.Permissions | ||||
import java.lang.ref.WeakReference | import java.lang.ref.WeakReference | ||||
import kotlin.math.min | import kotlin.math.min | ||||
/** | /** | ||||
* Singleton class used to access location. Possibly extended with other location sources. | * Singleton class used to access location. Possibly extended with other location sources. | ||||
* | |||||
* 2024: This is far too much. We need to simplify the whole mechanism (no more singleton) | |||||
*/ | */ | ||||
class AppLocationManager private constructor(context: Context) : LocationListener { | class AppLocationManager private constructor(context: Context) : LocationListener { | ||||
private val appContext: Context | private val appContext: Context | ||||
private val locMan: LocationManager | private val locMan: LocationManager | ||||
private val BUNDLE_LOCATION = "location" | private val BUNDLE_LOCATION = "location" | ||||
private var oldGPSLocStatus = LOCATION_UNAVAILABLE | private var oldGPSLocStatus = LOCATION_UNAVAILABLE | ||||
private var minimum_time_milli = -1 | private var minimum_time_milli = -1 | ||||
private val requestersRef = ArrayList<WeakReference<LocationRequester?>>() | private val requestersRef = ArrayList<WeakReference<LocationRequester?>>() | ||||
▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | class AppLocationManager private constructor(context: Context) : LocationListener { | ||||
} | } | ||||
companion object { | companion object { | ||||
const val LOCATION_GPS_AVAILABLE = 22 | const val LOCATION_GPS_AVAILABLE = 22 | ||||
const val LOCATION_UNAVAILABLE = -22 | const val LOCATION_UNAVAILABLE = -22 | ||||
private const val DEBUG_TAG = "BUSTO LocAdapter" | private const val DEBUG_TAG = "BUSTO LocAdapter" | ||||
private var instance: AppLocationManager? = null | private var instance: AppLocationManager? = null | ||||
@JvmStatic | @JvmStatic | ||||
fun getInstance(con: Context): AppLocationManager? { | fun getInstance(con: Context): AppLocationManager { | ||||
if (instance == null) instance = AppLocationManager(con) | if (instance == null) instance = AppLocationManager(con) | ||||
return instance | return instance!! | ||||
} | } | ||||
fun checkLocationPermission(context: Context?): Boolean { | fun checkLocationPermission(context: Context?): Boolean { | ||||
return ContextCompat.checkSelfPermission( | return ContextCompat.checkSelfPermission( | ||||
context!!, | context!!, | ||||
Manifest.permission.ACCESS_FINE_LOCATION | Manifest.permission.ACCESS_FINE_LOCATION | ||||
) == PackageManager.PERMISSION_GRANTED | ) == PackageManager.PERMISSION_GRANTED | ||||
} | } | ||||
} | } | ||||
} | } |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register