From 71281f85b4edd31621066eb3ced90b252b176248 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 30 Jul 2019 15:03:18 +0300 Subject: [PATCH 1/2] Remove duplicate nav drawer items and disable live track for current user --- .../src/net/osmand/telegram/TelegramApplication.kt | 4 +++- .../osmand/telegram/helpers/OsmandAidlHelper.kt | 10 ++++++++++ .../net/osmand/telegram/ui/UserGpxInfoFragment.kt | 14 ++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt index ef0b2ec87d..c4681db48c 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt @@ -42,9 +42,10 @@ class TelegramApplication : Application(), OsmandHelperListener { telegramHelper.messageActiveTimeSec = settings.locHistoryTime uiUtils = UiUtils(this) osmandAidlHelper = OsmandAidlHelper(this) - osmandAidlHelper.listener = object : OsmandAidlHelper.OsmandHelperListener { + osmandAidlHelper.listener = object : OsmandHelperListener { override fun onOsmandConnectionStateChanged(connected: Boolean) { if (connected) { + val otherPackage = if (applicationContext.packageName != "net.osmand.telegram") "net.osmand.telegram" else "net.osmand.telegram.debug" osmandAidlHelper.setNavDrawerItems( applicationContext.packageName, listOf(getString(R.string.app_name_short)), @@ -52,6 +53,7 @@ class TelegramApplication : Application(), OsmandHelperListener { listOf("ic_action_location_sharing_app"), listOf(-1) ) + osmandAidlHelper.clearNavDrawerItems(otherPackage) showLocationHelper.addDirectionContextMenuButton() showLocationHelper.startShowingLocation() } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/OsmandAidlHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/OsmandAidlHelper.kt index 66ccd1bad8..dbcba978ec 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/OsmandAidlHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/OsmandAidlHelper.kt @@ -1043,6 +1043,16 @@ class OsmandAidlHelper(private val app: TelegramApplication) { return false } + fun clearNavDrawerItems(appPackage: String): Boolean { + if (mIOsmAndAidlInterface != null) { + try { + return mIOsmAndAidlInterface!!.setNavDrawerItems(SetNavDrawerItemsParams(appPackage, emptyList())) + } catch (e: RemoteException) { + e.printStackTrace() + } + } + return false + } /** * Put navigation on pause. diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/UserGpxInfoFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/UserGpxInfoFragment.kt index 44f7b95b0a..097212de97 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/UserGpxInfoFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/UserGpxInfoFragment.kt @@ -156,12 +156,14 @@ class UserGpxInfoFragment : BaseDialogFragment() { updateDateAndTimeButton() liveBtn = mainView.findViewById(R.id.live_btn).apply { - setOnClickListener { - val enabled = !liveTrackEnabled() - settings.updateLiveTrack(userId, chatId, deviceName, enabled) - updateLiveTrackBtn() - if (enabled) { - startHandler() + if (userId != telegramHelper.getCurrentUserId()) { + setOnClickListener { + val enabled = !liveTrackEnabled() + settings.updateLiveTrack(userId, chatId, deviceName, enabled) + updateLiveTrackBtn() + if (enabled) { + startHandler() + } } } } From 5ee361cd6d31f447cb79793da3db186537890565 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 30 Jul 2019 15:21:56 +0300 Subject: [PATCH 2/2] Clear old nav drawer items --- .../src/net/osmand/telegram/TelegramApplication.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt index c4681db48c..7cd50a96c0 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramApplication.kt @@ -45,7 +45,8 @@ class TelegramApplication : Application(), OsmandHelperListener { osmandAidlHelper.listener = object : OsmandHelperListener { override fun onOsmandConnectionStateChanged(connected: Boolean) { if (connected) { - val otherPackage = if (applicationContext.packageName != "net.osmand.telegram") "net.osmand.telegram" else "net.osmand.telegram.debug" + osmandAidlHelper.clearNavDrawerItems("net.osmand.telegram") + osmandAidlHelper.clearNavDrawerItems("net.osmand.telegram.debug") osmandAidlHelper.setNavDrawerItems( applicationContext.packageName, listOf(getString(R.string.app_name_short)), @@ -53,7 +54,6 @@ class TelegramApplication : Application(), OsmandHelperListener { listOf("ic_action_location_sharing_app"), listOf(-1) ) - osmandAidlHelper.clearNavDrawerItems(otherPackage) showLocationHelper.addDirectionContextMenuButton() showLocationHelper.startShowingLocation() }