From 2714a9403b0df2836ba3b2a3c3f866edc9dc595b Mon Sep 17 00:00:00 2001 From: max-klaus Date: Thu, 14 Jan 2021 17:09:54 +0300 Subject: [PATCH] Revert commented location (activity) for tracker --- .../net/osmand/telegram/TelegramLocationProvider.kt | 11 ++--------- .../src/net/osmand/telegram/TelegramSettings.kt | 9 ++++++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramLocationProvider.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramLocationProvider.kt index 55c1911caf..babaed984d 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramLocationProvider.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramLocationProvider.kt @@ -87,13 +87,12 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve @SuppressLint("MissingPermission") fun resumeAllUpdates() { - /* val service = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager if (app.isInternetConnectionAvailable) { if (System.currentTimeMillis() - agpsDataLastTimeDownloaded > AGPS_TO_REDOWNLOAD) { //force an updated check for internet connectivity here before destroying A-GPS-data if (app.isInternetConnectionAvailable(true)) { - redownloadAGPS() + //redownloadAGPS() } } } @@ -135,12 +134,11 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve } } - */ + registerOrUnregisterCompassListener(true) } private fun redownloadAGPS() { - /* try { val service = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager service.sendExtraCommand(LocationManager.GPS_PROVIDER, "delete_aiding_data", null) @@ -152,7 +150,6 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve agpsDataLastTimeDownloaded = 0L e.printStackTrace() } - */ } private fun getGpsStatusListener(service: LocationManager): GpsStatus.Listener { @@ -219,7 +216,6 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve @Synchronized fun registerOrUnregisterCompassListener(register: Boolean) { - /* if (sensorRegistered && !register) { Log.d(PlatformUtil.TAG, "Disable sensor") //$NON-NLS-1$ (app.getSystemService(Context.SENSOR_SERVICE) as SensorManager).unregisterListener(this) @@ -260,7 +256,6 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve } sensorRegistered = true } - */ } override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {} @@ -394,14 +389,12 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve } private fun stopLocationRequests() { - /* val service = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager service.removeGpsStatusListener(gpsStatusListener) service.removeUpdates(gpsListener) while (!networkListeners.isEmpty()) { service.removeUpdates(networkListeners.poll()) } - */ } fun pauseAllUpdates() { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index bece18b8f4..ae6805fae9 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -505,7 +505,6 @@ class TelegramSettings(private val app: TelegramApplication) { val currentTimeMillis = System.currentTimeMillis() val currentTime = currentTimeMillis / 1000 statusChangeTime = currentTimeMillis - val gpsEnabled = false /* val lm = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager val gpsEnabled = try { @@ -521,6 +520,14 @@ class TelegramSettings(private val app: TelegramApplication) { false } */ + val gpsEnabled = try { + val loc = app.locationProvider.lastKnownLocation + val gpsActive = loc != null && ((currentTimeMillis - loc.time) / 1000) < GPS_UPDATE_EXPIRED_TIME + val lastSentLocationExpired = ((currentTimeMillis - app.shareLocationHelper.lastLocationUpdateTime) / 1000) > GPS_UPDATE_EXPIRED_TIME + (gpsActive || !lastSentLocationExpired) + } catch (ex: Exception) { + false + } var initializing = false var sendChatsErrors = false