From 3f52aebedd704ae6201e13eaed09f14be84090ec Mon Sep 17 00:00:00 2001 From: crimean Date: Tue, 19 Jun 2018 16:33:15 +0300 Subject: [PATCH] Fix sending location right after checkbox switched --- .../src/net/osmand/telegram/TelegramApplication.kt | 4 ++++ OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt | 5 +++++ .../src/net/osmand/telegram/helpers/ShareLocationHelper.kt | 2 ++ 3 files changed, 11 insertions(+) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt index 0e7b64a226..2116ca483d 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt @@ -127,6 +127,10 @@ class TelegramApplication : Application(), OsmandHelperListener { telegramService?.stopIfNeeded(this, TelegramService.USED_BY_MY_LOCATION) } + fun forceUpdateMyLocation() { + telegramService?.forceLocationUpdate() + } + fun startUserLocationService() { startTelegramService(TelegramService.USED_BY_USERS_LOCATIONS) } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt index 1b57419a48..0bcabf45d9 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt @@ -130,6 +130,11 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis stopForeground(java.lang.Boolean.TRUE) } + fun forceLocationUpdate() { + val location = getFirstTimeRunDefaultLocation() + app().shareLocationHelper.updateLocation(location) + } + private fun initLocationUpdates() { val firstLocation = getFirstTimeRunDefaultLocation() app().shareLocationHelper.updateLocation(firstLocation) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt index 09f3bc5499..196d32bf04 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShareLocationHelper.kt @@ -58,6 +58,8 @@ class ShareLocationHelper(private val app: TelegramApplication) { app.startMyLocationService() refreshNotification() + } else { + app.forceUpdateMyLocation() } }