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.hardware.*
|
||||
import android.location.Location
|
||||
import android.os.HandlerThread
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import com.google.android.gms.location.*
|
||||
import net.osmand.PlatformUtil
|
||||
|
@ -43,12 +43,11 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
|
|||
var lastKnownLocation: net.osmand.Location? = null
|
||||
private set
|
||||
|
||||
private val locationUpdateHandlerThread = HandlerThread("LocationProviderUpdateHandlerThread")
|
||||
private var fusedLocationProviderClient: FusedLocationProviderClient? = null
|
||||
private val locationRequest = LocationRequest().apply {
|
||||
interval = 1000
|
||||
//fastestInterval = 500
|
||||
maxWaitTime = 0
|
||||
fastestInterval = 500
|
||||
maxWaitTime = 2000
|
||||
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
|
||||
}
|
||||
private val locationCallback = object : LocationCallback() {
|
||||
|
@ -82,10 +81,6 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
|
|||
fun updateCompassValue(value: Float)
|
||||
}
|
||||
|
||||
init {
|
||||
locationUpdateHandlerThread.start()
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun resumeAllUpdates() {
|
||||
if (AndroidUtils.isLocationPermissionAvailable(app) && fusedLocationProviderClient == null) {
|
||||
|
@ -94,7 +89,7 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
|
|||
|
||||
try {
|
||||
fusedLocationProviderClient?.requestLocationUpdates(
|
||||
locationRequest, locationCallback, locationUpdateHandlerThread.looper)
|
||||
locationRequest, locationCallback, Looper.myLooper())
|
||||
} catch (unlikely: SecurityException) {
|
||||
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 updateWidgetThread = HandlerThread("WidgetUpdateServiceThread")
|
||||
|
||||
private var locationUpdateHandlerThread = HandlerThread("LocationUpdateServiceThread")
|
||||
// FusedLocationProviderClient - Main class for receiving location updates.
|
||||
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient
|
||||
|
||||
|
@ -63,7 +62,6 @@ class TelegramService : Service(), TelegramIncomingMessagesListener,
|
|||
mHandlerThread.start()
|
||||
tracksHandlerThread.start()
|
||||
updateWidgetThread.start()
|
||||
locationUpdateHandlerThread.start()
|
||||
updateShareInfoHandler = Handler(mHandlerThread.looper)
|
||||
updateTracksHandler = Handler(tracksHandlerThread.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
|
||||
// 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
|
||||
// delivered sooner than this interval.
|
||||
maxWaitTime = 0
|
||||
maxWaitTime = 2000
|
||||
|
||||
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
|
||||
}
|
||||
|
@ -168,7 +166,6 @@ class TelegramService : Service(), TelegramIncomingMessagesListener,
|
|||
tracksHandlerThread.quit()
|
||||
mHandlerThread.quit()
|
||||
updateWidgetThread.quit()
|
||||
locationUpdateHandlerThread.quit()
|
||||
app().showLocationHelper.addOrUpdateStatusWidget(-1, false)
|
||||
|
||||
usedBy = 0
|
||||
|
@ -201,7 +198,7 @@ class TelegramService : Service(), TelegramIncomingMessagesListener,
|
|||
// request location updates
|
||||
try {
|
||||
fusedLocationProviderClient.requestLocationUpdates(
|
||||
locationRequest, locationCallback, locationUpdateHandlerThread.looper)
|
||||
locationRequest, locationCallback, Looper.myLooper())
|
||||
} catch (unlikely: SecurityException) {
|
||||
Toast.makeText(this, R.string.no_location_permission, Toast.LENGTH_LONG).show()
|
||||
Log.d(PlatformUtil.TAG, "Lost location permissions. Couldn't request updates. $unlikely")
|
||||
|
|
Loading…
Reference in a new issue