Merge pull request #6504 from osmandapp/TelegramDataBase

Add check for location accuracy
This commit is contained in:
vshcherb 2019-02-04 14:26:45 +02:00 committed by GitHub
commit befbb25469
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 56 deletions

View file

@ -204,13 +204,14 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
providers.add(0, providers.removeAt(passiveFirst)) providers.add(0, providers.removeAt(passiveFirst))
} }
// find location // find location
var location: net.osmand.Location? = null
for (provider in providers) { for (provider in providers) {
val location = convertLocation(service.getLastKnownLocation(provider)) val loc = convertLocation(service.getLastKnownLocation(provider))
if (location != null) { if (loc != null && (location == null || loc.hasAccuracy() && loc.accuracy < location.accuracy)) {
return location location = loc
} }
} }
return null return location
} }
private fun setupAlarm() { private fun setupAlarm() {

View file

@ -13,7 +13,7 @@ import org.json.JSONObject
private const val USER_SET_LIVE_PERIOD_DELAY_MS = 5000 // 5 sec 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) { class ShareLocationHelper(private val app: TelegramApplication) {
@ -30,8 +30,6 @@ class ShareLocationHelper(private val app: TelegramApplication) {
var lastLocationUpdateTime: Long = 0 var lastLocationUpdateTime: Long = 0
var lastMyLocationUpdateTime: Long = 0
var lastLocation: Location? = null var lastLocation: Location? = null
set(value) { set(value) {
if (lastTimeInMillis == 0L) { if (lastTimeInMillis == 0L) {
@ -52,7 +50,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
fun updateLocation(location: Location?) { fun updateLocation(location: Location?) {
lastLocation = location lastLocation = location
if (location != null) { if (location != null && location.accuracy < UPDATE_LOCATION_ACCURACY) {
lastLocationUpdateTime = System.currentTimeMillis() lastLocationUpdateTime = System.currentTimeMillis()
if (app.settings.getChatsShareInfo().isNotEmpty()) { if (app.settings.getChatsShareInfo().isNotEmpty()) {
shareLocationMessages(location, app.telegramHelper.getCurrentUserId()) shareLocationMessages(location, app.telegramHelper.getCurrentUserId())
@ -225,10 +223,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
prepareMapAndTextMessage(shareInfo, message, isBot, sharingMode) prepareMapAndTextMessage(shareInfo, message, isBot, sharingMode)
} }
} }
if (System.currentTimeMillis() - lastMyLocationUpdateTime > MY_LOCATION_UPDATE_MS) { app.locationMessages.addMyLocationMessage(location)
app.locationMessages.addMyLocationMessage(location)
lastMyLocationUpdateTime = System.currentTimeMillis()
}
if (bufferedMessagesFull) { if (bufferedMessagesFull) {
checkNetworkType() checkNetworkType()
} }

View file

@ -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? { fun userLocationsToChatItem(helper: TelegramHelper, userLocation: LocationMessages.UserLocations): LocationMessagesChatItem? {
val user = helper.getUser(userLocation.userId) val user = helper.getUser(userLocation.userId)
val chat = helper.getChat(userLocation.chatId) val chat = helper.getChat(userLocation.chatId)
@ -328,24 +302,6 @@ object TelegramUiHelper {
override fun getVisibleName() = chatTitle 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() { class LocationMessagesChatItem : ListItem() {
var userLocations: LocationMessages.UserLocations? = null var userLocations: LocationMessages.UserLocations? = null