From d788d036f70a0e1f717e43a27f381f380306e0e5 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Tue, 28 Aug 2018 20:10:59 +0300 Subject: [PATCH] Replace "logout" menu item with "exit" item --- OsmAnd-telegram/res/values/strings.xml | 1 + .../net/osmand/telegram/TelegramSettings.kt | 4 +++ .../net/osmand/telegram/ui/MainActivity.kt | 32 +++++++++++++++---- .../telegram/ui/MyLocationTabFragment.kt | 4 +-- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/OsmAnd-telegram/res/values/strings.xml b/OsmAnd-telegram/res/values/strings.xml index 2901ad49fc..b17c8b9ff2 100644 --- a/OsmAnd-telegram/res/values/strings.xml +++ b/OsmAnd-telegram/res/values/strings.xml @@ -1,4 +1,5 @@ + Exit ago Last response Group diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index 35063c8a82..5400f49995 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -146,6 +146,10 @@ class TelegramSettings(private val app: TelegramApplication) { this.chatShareLocStartSec.clear() } + fun clearShowOnMapChats() { + showOnMapChats = emptySet() + } + fun showChatOnMap(chatId: Long, show: Boolean) { val showOnMapChats = showOnMapChats.toMutableList() if (show) { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt index 9f66f3de4c..721f428776 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt @@ -288,6 +288,25 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene settings.removeNonexistingChats(presentChatTitles) } + fun stopSharingLocation() { + settings.stopSharingLocationToChats() + app.shareLocationHelper.stopSharingLocation() + telegramHelper.stopSendingLiveLocationMessages() + } + + fun stopShowingChatsOnMap() { + settings.getShowOnMapChats().forEach { app.showLocationHelper.hideChatMessages(it) } + settings.clearShowOnMapChats() + app.showLocationHelper.stopShowingLocation() + } + + private fun closeApp() { + stopSharingLocation() + stopShowingChatsOnMap() + finish() + android.os.Process.killProcess(android.os.Process.myPid()) + } + fun loginTelegram() { if (telegramHelper.getTelegramAuthorizationState() != TelegramAuthorizationState.CLOSED) { telegramHelper.logout() @@ -318,18 +337,17 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene imageView.setOnClickListener { showOptionsPopupMenu(imageView) } } - fun showOptionsPopupMenu(anchor: View) { + private fun showOptionsPopupMenu(anchor: View) { val menuList = ArrayList() val settings = getString(R.string.shared_string_settings) - val logout = getString(R.string.shared_string_logout) val login = getString(R.string.shared_string_login) + val exit = getString(R.string.shared_string_exit) menuList.add(settings) - @Suppress("NON_EXHAUSTIVE_WHEN") - when (telegramHelper.getTelegramAuthorizationState()) { - TelegramHelper.TelegramAuthorizationState.READY -> menuList.add(logout) - TelegramHelper.TelegramAuthorizationState.CLOSED -> menuList.add(login) + if (telegramHelper.getTelegramAuthorizationState() == TelegramAuthorizationState.CLOSED) { + menuList.add(login) } + menuList.add(exit) ListPopupWindow(this@MainActivity).apply { isModal = true @@ -342,8 +360,8 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene menuList.indexOf(settings) -> { supportFragmentManager?.also { SettingsDialogFragment.showInstance(it) } } - menuList.indexOf(logout) -> logoutTelegram() menuList.indexOf(login) -> loginTelegram() + menuList.indexOf(exit) -> closeApp() } dismiss() } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index f8d233369a..92ccb35ed3 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -183,9 +183,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { setOnCheckedChangeListener { _, isChecked -> if (!isChecked) { sharingMode = isChecked - settings.stopSharingLocationToChats() - shareLocationHelper.stopSharingLocation() - telegramHelper.stopSendingLiveLocationMessages() + activity.stopSharingLocation() updateContent() } }