Fix unnecessary marker updates
This commit is contained in:
parent
9186687004
commit
3000c7f914
2 changed files with 12 additions and 7 deletions
|
@ -230,6 +230,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
if (shareInfo.pendingTdLibText >= MAX_MESSAGES_IN_TDLIB_PER_CHAT || shareInfo.pendingTdLibMap >= MAX_MESSAGES_IN_TDLIB_PER_CHAT) {
|
||||
bufferedMessagesFull = true
|
||||
}
|
||||
checkAndSendBufferMessagesToChat(shareInfo.chatId)
|
||||
when (app.settings.shareTypeValue) {
|
||||
SHARE_TYPE_MAP -> {
|
||||
val message = BufferMessage(shareInfo.chatId, latitude, longitude, altitude, speed, accuracy, bearing, time, LocationMessages.TYPE_MAP, deviceName)
|
||||
|
@ -246,7 +247,6 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
prepareTextMessage(shareInfo, messageText, isBot)
|
||||
}
|
||||
}
|
||||
checkAndSendBufferMessagesToChat(shareInfo.chatId)
|
||||
}
|
||||
if (bufferedMessagesFull) {
|
||||
checkNetworkType()
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.osmand.telegram.utils.OsmandLocationUtils.MessageUserLocation
|
|||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class ShowLocationHelper(private val app: TelegramApplication) {
|
||||
|
@ -37,8 +38,8 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
private val osmandAidlHelper = app.osmandAidlHelper
|
||||
private val executor = Executors.newSingleThreadExecutor()
|
||||
|
||||
private val points = mutableMapOf<String, TdApi.Message>()
|
||||
private val markers = mutableMapOf<String, AMapMarker>()
|
||||
private val points = ConcurrentHashMap<String, TdApi.Message>()
|
||||
private val markers = ConcurrentHashMap<String, AMapMarker>()
|
||||
|
||||
var showingLocation: Boolean = false
|
||||
private set
|
||||
|
@ -49,7 +50,7 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
app.osmandAidlHelper.setContextMenuButtonsListener(object : ContextMenuButtonsListener {
|
||||
|
||||
override fun onContextMenuButtonClicked(buttonId: Int, pointId: String, layerId: String) {
|
||||
updateDirectionMarker(pointId)
|
||||
updateDirectionMarker(pointId, true)
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -61,7 +62,7 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
|
||||
private fun updateDirectionMarker(pointId: String) {
|
||||
private fun updateDirectionMarker(pointId: String, forceAdd: Boolean = false) {
|
||||
val message = points[pointId]
|
||||
if (message != null) {
|
||||
val aLatLon = getALatLonFromMessage(message.content)
|
||||
|
@ -73,8 +74,12 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
if (markerPrev != null) {
|
||||
markerUpdated = app.osmandAidlHelper.updateMapMarker(markerPrev, marker)
|
||||
if (!markerUpdated) {
|
||||
app.osmandAidlHelper.removeMapMarker(markerPrev.latLon.latitude, markerPrev.latLon.longitude, name)
|
||||
markerUpdated = app.osmandAidlHelper.addMapMarker(marker)
|
||||
if (forceAdd) {
|
||||
app.osmandAidlHelper.removeMapMarker(markerPrev.latLon.latitude, markerPrev.latLon.longitude, name)
|
||||
markerUpdated = app.osmandAidlHelper.addMapMarker(marker)
|
||||
} else {
|
||||
markers.remove(pointId)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
markerUpdated = app.osmandAidlHelper.addMapMarker(marker)
|
||||
|
|
Loading…
Reference in a new issue