Merge pull request #6504 from osmandapp/TelegramDataBase
Add check for location accuracy
This commit is contained in:
commit
befbb25469
3 changed files with 8 additions and 56 deletions
|
@ -204,13 +204,14 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
|
|||
providers.add(0, providers.removeAt(passiveFirst))
|
||||
}
|
||||
// find location
|
||||
var location: net.osmand.Location? = null
|
||||
for (provider in providers) {
|
||||
val location = convertLocation(service.getLastKnownLocation(provider))
|
||||
if (location != null) {
|
||||
return location
|
||||
val loc = convertLocation(service.getLastKnownLocation(provider))
|
||||
if (loc != null && (location == null || loc.hasAccuracy() && loc.accuracy < location.accuracy)) {
|
||||
location = loc
|
||||
}
|
||||
}
|
||||
return null
|
||||
return location
|
||||
}
|
||||
|
||||
private fun setupAlarm() {
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.json.JSONObject
|
|||
|
||||
private const val USER_SET_LIVE_PERIOD_DELAY_MS = 5000 // 5 sec
|
||||
|
||||
private const val MY_LOCATION_UPDATE_MS = 15000 // 15 sec
|
||||
private const val UPDATE_LOCATION_ACCURACY = 150 // 150 meters
|
||||
|
||||
class ShareLocationHelper(private val app: TelegramApplication) {
|
||||
|
||||
|
@ -30,8 +30,6 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
|
||||
var lastLocationUpdateTime: Long = 0
|
||||
|
||||
var lastMyLocationUpdateTime: Long = 0
|
||||
|
||||
var lastLocation: Location? = null
|
||||
set(value) {
|
||||
if (lastTimeInMillis == 0L) {
|
||||
|
@ -52,7 +50,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
fun updateLocation(location: Location?) {
|
||||
lastLocation = location
|
||||
|
||||
if (location != null) {
|
||||
if (location != null && location.accuracy < UPDATE_LOCATION_ACCURACY) {
|
||||
lastLocationUpdateTime = System.currentTimeMillis()
|
||||
if (app.settings.getChatsShareInfo().isNotEmpty()) {
|
||||
shareLocationMessages(location, app.telegramHelper.getCurrentUserId())
|
||||
|
@ -225,10 +223,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
prepareMapAndTextMessage(shareInfo, message, isBot, sharingMode)
|
||||
}
|
||||
}
|
||||
if (System.currentTimeMillis() - lastMyLocationUpdateTime > MY_LOCATION_UPDATE_MS) {
|
||||
app.locationMessages.addMyLocationMessage(location)
|
||||
lastMyLocationUpdateTime = System.currentTimeMillis()
|
||||
}
|
||||
app.locationMessages.addMyLocationMessage(location)
|
||||
if (bufferedMessagesFull) {
|
||||
checkNetworkType()
|
||||
}
|
||||
|
|
|
@ -226,32 +226,6 @@ object TelegramUiHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private fun gpxToGpxChatItem(
|
||||
helper: TelegramHelper,
|
||||
gpx: GPXFile
|
||||
): GpxChatItem? {
|
||||
val user = helper.getUser(gpx.userId) ?: return null
|
||||
val chat = helper.getChat(gpx.chatId) ?: return null
|
||||
return GpxChatItem().apply {
|
||||
chatId = chat.id
|
||||
chatTitle = chat.title
|
||||
gpxFile = gpx
|
||||
name = TelegramUiHelper.getUserName(user)
|
||||
if (helper.isGroup(chat)) {
|
||||
photoPath = helper.getUserPhotoPath(user)
|
||||
groupPhotoPath = chat.photo?.small?.local?.path
|
||||
} else {
|
||||
photoPath = user.profilePhoto?.small?.local?.path
|
||||
}
|
||||
grayscalePhotoPath = helper.getUserGreyPhotoPath(user)
|
||||
placeholderId = R.drawable.img_user_picture
|
||||
userId = user.id
|
||||
privateChat = helper.isPrivateChat(chat) || helper.isSecretChat(chat)
|
||||
chatWithBot = helper.isBot(userId)
|
||||
lastUpdated = (gpx.modifiedTime / 1000).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
fun userLocationsToChatItem(helper: TelegramHelper, userLocation: LocationMessages.UserLocations): LocationMessagesChatItem? {
|
||||
val user = helper.getUser(userLocation.userId)
|
||||
val chat = helper.getChat(userLocation.chatId)
|
||||
|
@ -328,24 +302,6 @@ object TelegramUiHelper {
|
|||
override fun getVisibleName() = chatTitle
|
||||
}
|
||||
|
||||
class GpxChatItem : ListItem() {
|
||||
|
||||
var gpxFile: GPXFile? = null
|
||||
internal set
|
||||
var groupPhotoPath: String? = null
|
||||
internal set
|
||||
var privateChat: Boolean = false
|
||||
internal set
|
||||
var chatWithBot: Boolean = false
|
||||
internal set
|
||||
|
||||
override fun canBeOpenedOnMap() = latLon != null
|
||||
|
||||
override fun getMapPointId() = "${chatId}_$userId"
|
||||
|
||||
override fun getVisibleName() = chatTitle
|
||||
}
|
||||
|
||||
class LocationMessagesChatItem : ListItem() {
|
||||
|
||||
var userLocations: LocationMessages.UserLocations? = null
|
||||
|
|
Loading…
Reference in a new issue