From cc676a39acb7b1c73c1a54e0d33da68f8f642276 Mon Sep 17 00:00:00 2001 From: Chumva Date: Sat, 2 Feb 2019 13:14:57 +0200 Subject: [PATCH 1/2] Add check for location accuracy --- .../src/net/osmand/telegram/TelegramService.kt | 9 +++++---- .../net/osmand/telegram/helpers/ShareLocationHelper.kt | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt index 31dbfb0bbe..e1fc26e463 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt @@ -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() { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt index 39f765aef6..a4114b2b9a 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt @@ -15,6 +15,8 @@ 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 = 30 // 30 meters + class ShareLocationHelper(private val app: TelegramApplication) { private val log = PlatformUtil.getLog(ShareLocationHelper::class.java) @@ -52,7 +54,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()) From 84ac49e09b3605f30bda1e9f12ddab858b421b57 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 4 Feb 2019 13:47:17 +0200 Subject: [PATCH 2/2] Increase location accuracy threshold and remove 15 sec check for my location --- .../telegram/helpers/ShareLocationHelper.kt | 11 +---- .../telegram/helpers/TelegramUiHelper.kt | 44 ------------------- 2 files changed, 2 insertions(+), 53 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt index a4114b2b9a..17ee84eec9 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt @@ -13,9 +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 = 30 // 30 meters +private const val UPDATE_LOCATION_ACCURACY = 150 // 150 meters class ShareLocationHelper(private val app: TelegramApplication) { @@ -32,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) { @@ -227,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() } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt index d86f2df7af..4b846dc88d 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt @@ -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