From ca876dbd84690d26c066ce93597e5447e81ca1de Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 30 May 2019 16:08:40 +0300 Subject: [PATCH] Fix gps on after sharing finished --- .../net/osmand/telegram/TelegramService.kt | 31 ++++++++++--------- .../net/osmand/telegram/ui/MainActivity.kt | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt index 904aa83b7e..480766d85e 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt @@ -64,25 +64,30 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis if (usedBy and usageIntent > 0) { usedBy -= usageIntent } - if (usedBy == 0) { - shouldCleanupResources = false - val serviceIntent = Intent(ctx, TelegramService::class.java) - ctx.stopService(serviceIntent) - } else if (isUsedByMyLocation(usedBy)) { - val app = app() - if (app.settings.sendMyLocInterval >= OFF_INTERVAL_THRESHOLD && serviceOffInterval == 0L) { - serviceOffInterval = app.settings.sendMyLocInterval - setupServiceErrorInterval() - setupAlarm() + when { + usedBy == 0 -> { + shouldCleanupResources = false + val serviceIntent = Intent(ctx, TelegramService::class.java) + ctx.stopService(serviceIntent) } - app.notificationHelper.refreshNotification(NotificationType.LOCATION) + isUsedByMyLocation(usedBy) -> { + val app = app() + if (app.settings.sendMyLocInterval >= OFF_INTERVAL_THRESHOLD && serviceOffInterval == 0L) { + serviceOffInterval = app.settings.sendMyLocInterval + setupServiceErrorInterval() + setupAlarm() + } + app.notificationHelper.refreshNotification(NotificationType.LOCATION) + } + isUsedByUsersLocations(usedBy) -> removeLocationUpdates() } } override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { val app = app() handler = Handler() - usedBy = intent.getIntExtra(USAGE_INTENT, 0) + val usageIntent = intent.getIntExtra(USAGE_INTENT, 0) + usedBy = usageIntent or usedBy serviceOffInterval = intent.getLongExtra(USAGE_OFF_INTERVAL, 0) sendLocationInterval = intent.getLongExtra(SEND_LOCATION_INTERVAL, 0) @@ -259,10 +264,8 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis Toast.makeText(this, getString(R.string.location_service_no_gps_available), Toast.LENGTH_LONG).show() } - override fun onProviderEnabled(provider: String) {} - override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {} override fun onTaskRemoved(rootIntent: Intent) { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt index faa5076456..8126832651 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt @@ -45,7 +45,7 @@ private const val TIMELINE_TAB_POS = 2 class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListener, TelegramIncomingMessagesListener { - private val log = PlatformUtil.getLog(TelegramHelper::class.java) + private val log = PlatformUtil.getLog(MainActivity::class.java) private var telegramAuthorizationRequestHandler: TelegramAuthorizationRequestHandler? = null private var paused: Boolean = false