Revert "Improve tracker location update"
This reverts commit 1867b3d07d
.
This commit is contained in:
parent
b61dff48d6
commit
481feec24d
2 changed files with 7 additions and 15 deletions
|
@ -4,7 +4,7 @@ import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.hardware.*
|
import android.hardware.*
|
||||||
import android.location.Location
|
import android.location.Location
|
||||||
import android.os.HandlerThread
|
import android.os.Looper
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.google.android.gms.location.*
|
import com.google.android.gms.location.*
|
||||||
import net.osmand.PlatformUtil
|
import net.osmand.PlatformUtil
|
||||||
|
@ -43,12 +43,11 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
|
||||||
var lastKnownLocation: net.osmand.Location? = null
|
var lastKnownLocation: net.osmand.Location? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
private val locationUpdateHandlerThread = HandlerThread("LocationProviderUpdateHandlerThread")
|
|
||||||
private var fusedLocationProviderClient: FusedLocationProviderClient? = null
|
private var fusedLocationProviderClient: FusedLocationProviderClient? = null
|
||||||
private val locationRequest = LocationRequest().apply {
|
private val locationRequest = LocationRequest().apply {
|
||||||
interval = 1000
|
interval = 1000
|
||||||
//fastestInterval = 500
|
fastestInterval = 500
|
||||||
maxWaitTime = 0
|
maxWaitTime = 2000
|
||||||
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
|
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
|
||||||
}
|
}
|
||||||
private val locationCallback = object : LocationCallback() {
|
private val locationCallback = object : LocationCallback() {
|
||||||
|
@ -82,10 +81,6 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
|
||||||
fun updateCompassValue(value: Float)
|
fun updateCompassValue(value: Float)
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
|
||||||
locationUpdateHandlerThread.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun resumeAllUpdates() {
|
fun resumeAllUpdates() {
|
||||||
if (AndroidUtils.isLocationPermissionAvailable(app) && fusedLocationProviderClient == null) {
|
if (AndroidUtils.isLocationPermissionAvailable(app) && fusedLocationProviderClient == null) {
|
||||||
|
@ -94,7 +89,7 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fusedLocationProviderClient?.requestLocationUpdates(
|
fusedLocationProviderClient?.requestLocationUpdates(
|
||||||
locationRequest, locationCallback, locationUpdateHandlerThread.looper)
|
locationRequest, locationCallback, Looper.myLooper())
|
||||||
} catch (unlikely: SecurityException) {
|
} catch (unlikely: SecurityException) {
|
||||||
Log.d(PlatformUtil.TAG, "Lost location permissions. Couldn't request updates. $unlikely")
|
Log.d(PlatformUtil.TAG, "Lost location permissions. Couldn't request updates. $unlikely")
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ class TelegramService : Service(), TelegramIncomingMessagesListener,
|
||||||
private var updateWidgetHandler: Handler? = null
|
private var updateWidgetHandler: Handler? = null
|
||||||
private var updateWidgetThread = HandlerThread("WidgetUpdateServiceThread")
|
private var updateWidgetThread = HandlerThread("WidgetUpdateServiceThread")
|
||||||
|
|
||||||
private var locationUpdateHandlerThread = HandlerThread("LocationUpdateServiceThread")
|
|
||||||
// FusedLocationProviderClient - Main class for receiving location updates.
|
// FusedLocationProviderClient - Main class for receiving location updates.
|
||||||
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient
|
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient
|
||||||
|
|
||||||
|
@ -63,7 +62,6 @@ class TelegramService : Service(), TelegramIncomingMessagesListener,
|
||||||
mHandlerThread.start()
|
mHandlerThread.start()
|
||||||
tracksHandlerThread.start()
|
tracksHandlerThread.start()
|
||||||
updateWidgetThread.start()
|
updateWidgetThread.start()
|
||||||
locationUpdateHandlerThread.start()
|
|
||||||
updateShareInfoHandler = Handler(mHandlerThread.looper)
|
updateShareInfoHandler = Handler(mHandlerThread.looper)
|
||||||
updateTracksHandler = Handler(tracksHandlerThread.looper)
|
updateTracksHandler = Handler(tracksHandlerThread.looper)
|
||||||
updateWidgetHandler = Handler(updateWidgetThread.looper)
|
updateWidgetHandler = Handler(updateWidgetThread.looper)
|
||||||
|
@ -84,11 +82,11 @@ class TelegramService : Service(), TelegramIncomingMessagesListener,
|
||||||
|
|
||||||
// Sets the fastest rate for active location updates. This interval is exact, and your
|
// Sets the fastest rate for active location updates. This interval is exact, and your
|
||||||
// application will never receive updates more frequently than this value.
|
// application will never receive updates more frequently than this value.
|
||||||
//fastestInterval = 500
|
fastestInterval = 500
|
||||||
|
|
||||||
// Sets the maximum time when batched location updates are delivered. Updates may be
|
// Sets the maximum time when batched location updates are delivered. Updates may be
|
||||||
// delivered sooner than this interval.
|
// delivered sooner than this interval.
|
||||||
maxWaitTime = 0
|
maxWaitTime = 2000
|
||||||
|
|
||||||
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
|
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
|
||||||
}
|
}
|
||||||
|
@ -168,7 +166,6 @@ class TelegramService : Service(), TelegramIncomingMessagesListener,
|
||||||
tracksHandlerThread.quit()
|
tracksHandlerThread.quit()
|
||||||
mHandlerThread.quit()
|
mHandlerThread.quit()
|
||||||
updateWidgetThread.quit()
|
updateWidgetThread.quit()
|
||||||
locationUpdateHandlerThread.quit()
|
|
||||||
app().showLocationHelper.addOrUpdateStatusWidget(-1, false)
|
app().showLocationHelper.addOrUpdateStatusWidget(-1, false)
|
||||||
|
|
||||||
usedBy = 0
|
usedBy = 0
|
||||||
|
@ -201,7 +198,7 @@ class TelegramService : Service(), TelegramIncomingMessagesListener,
|
||||||
// request location updates
|
// request location updates
|
||||||
try {
|
try {
|
||||||
fusedLocationProviderClient.requestLocationUpdates(
|
fusedLocationProviderClient.requestLocationUpdates(
|
||||||
locationRequest, locationCallback, locationUpdateHandlerThread.looper)
|
locationRequest, locationCallback, Looper.myLooper())
|
||||||
} catch (unlikely: SecurityException) {
|
} catch (unlikely: SecurityException) {
|
||||||
Toast.makeText(this, R.string.no_location_permission, Toast.LENGTH_LONG).show()
|
Toast.makeText(this, R.string.no_location_permission, Toast.LENGTH_LONG).show()
|
||||||
Log.d(PlatformUtil.TAG, "Lost location permissions. Couldn't request updates. $unlikely")
|
Log.d(PlatformUtil.TAG, "Lost location permissions. Couldn't request updates. $unlikely")
|
||||||
|
|
Loading…
Reference in a new issue