diff --git a/OsmAnd-telegram/res/values/strings.xml b/OsmAnd-telegram/res/values/strings.xml index 05b27552e7..55a6800e83 100644 --- a/OsmAnd-telegram/res/values/strings.xml +++ b/OsmAnd-telegram/res/values/strings.xml @@ -1,5 +1,6 @@ + OsmAnd Tracker status Select time zone to show in your location messages. Time zone Units & formats diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt index a448ef714a..ba38c0f10f 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt @@ -154,6 +154,7 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis if (shouldCleanupResources) { app.cleanupResources() } + app().showLocationHelper.updateStatusWidget(-1) // remove notification stopForeground(java.lang.Boolean.TRUE) @@ -194,6 +195,7 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis updateShareInfoHandler?.postDelayed({ if (isUsedByMyLocation(usedBy)) { app().shareLocationHelper.updateSendLiveMessages() + app().showLocationHelper.updateStatusWidget(app().locationMessages.getBufferedMessagesCount()) startShareInfoUpdates() } }, UPDATE_LIVE_MESSAGES_INTERVAL_MS) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index b5dac721f1..c56545b72e 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -43,6 +43,11 @@ class ShowLocationHelper(private val app: TelegramApplication) { const val GPX_COLORS_COUNT = 10 + private const val STATUS_WIDGET_ID = "status_widget" + private const val STATUS_WIDGET_MENU_ICON = "ic_action_speed" + private const val STATUS_WIDGET_DAY_ICON = "widget_speed_day" + private const val STATUS_WIDGET_NIGHT_ICON = "widget_speed_night" + val GPX_COLORS = arrayOf( "red", "orange", "lightblue", "blue", "purple", "translucent_red", "translucent_orange", "translucent_lightblue", @@ -198,6 +203,31 @@ class ShowLocationHelper(private val app: TelegramApplication) { } } + fun updateStatusWidget(count: Int) { + val text = when { + count > 0 -> count.toString() + count == 0 -> "ON" + else -> "OFF" + } + val bufferText = when { + count > 0 -> count.toString() + else -> "" + } + osmandAidlHelper.addMapWidget( + STATUS_WIDGET_ID, + STATUS_WIDGET_MENU_ICON, + app.getString(R.string.status_widget_title), + STATUS_WIDGET_DAY_ICON, + STATUS_WIDGET_NIGHT_ICON, + text, bufferText, 50, getStatusWidgetIntent()) + } + + private fun getStatusWidgetIntent(): Intent { + val startIntent = app.packageManager.getLaunchIntentForPackage(app.packageName) + startIntent.addCategory(Intent.CATEGORY_LAUNCHER) + return startIntent + } + private fun getALatLonFromMessage(content: TdApi.MessageContent): ALatLon? { return when (content) { is TdApi.MessageLocation -> ALatLon(content.location.latitude, content.location.longitude)