From 1631a788571e33682c83d94a060cb36e67448c51 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Wed, 15 Aug 2018 17:02:20 +0300 Subject: [PATCH] Show Welcome screen after log out --- OsmAnd-telegram/res/values/strings.xml | 1 + .../src/net/osmand/telegram/ui/MainActivity.kt | 13 +++++++++++-- .../osmand/telegram/ui/SettingsDialogFragment.kt | 15 +++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/OsmAnd-telegram/res/values/strings.xml b/OsmAnd-telegram/res/values/strings.xml index 24d6e5811e..c9f67c4aff 100644 --- a/OsmAnd-telegram/res/values/strings.xml +++ b/OsmAnd-telegram/res/values/strings.xml @@ -1,4 +1,5 @@ + To properly log out from your Telegram account, the Internet is needed. Close To invoke access from OsmAnd, open Telegram, go to Settings - Privacy and Security - Sessions and terminate that session. How to disconnect OsmAnd Location Sharing from the Telegram account diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt index 71842c5326..23c6307cf7 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt @@ -184,6 +184,11 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene runOnUi { val fm = supportFragmentManager when (newTelegramAuthorizationState) { + TelegramAuthorizationState.LOGGING_OUT -> LoginDialogFragment.showWelcomeDialog(fm) + TelegramAuthorizationState.CLOSED -> { + telegramHelper.init() + telegramHelper.requestAuthorizationState() + } TelegramAuthorizationState.READY -> LoginDialogFragment.dismiss(fm) else -> Unit } @@ -258,9 +263,13 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene // FIXME: update UI } - private fun logoutTelegram(silent: Boolean = false) { + fun logoutTelegram(silent: Boolean = false) { if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) { - telegramHelper.logout() + if (app.isInternetConnectionAvailable) { + telegramHelper.logout() + } else { + Toast.makeText(this, R.string.logout_no_internet_msg, Toast.LENGTH_SHORT).show() + } } else if (!silent) { Toast.makeText(this, R.string.not_logged_in, Toast.LENGTH_SHORT).show() } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt index 46333e0bde..b08612f1b6 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt @@ -11,10 +11,12 @@ import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.* +import android.widget.ArrayAdapter +import android.widget.ImageView +import android.widget.RadioButton +import android.widget.TextView import net.osmand.telegram.* import net.osmand.telegram.helpers.OsmandAidlHelper -import net.osmand.telegram.helpers.TelegramHelper import net.osmand.telegram.helpers.TelegramUiHelper import net.osmand.telegram.utils.AndroidUtils import net.osmand.telegram.utils.OsmandFormatter @@ -156,12 +158,9 @@ class SettingsDialogFragment : DialogFragment() { } } - private fun logoutTelegram(silent: Boolean = false) { - if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) { - telegramHelper.logout() - } else if (!silent) { - Toast.makeText(context, R.string.not_logged_in, Toast.LENGTH_SHORT).show() - } + private fun logoutTelegram() { + val act = activity ?: return + (act as MainActivity).logoutTelegram() } private inner class SendMyLocPref : DurationPref(