Replace "logout" menu item with "exit" item

This commit is contained in:
Alex Sytnyk 2018-08-28 20:10:59 +03:00
parent c571408815
commit d788d036f7
4 changed files with 31 additions and 10 deletions

View file

@ -1,4 +1,5 @@
<resources>
<string name="shared_string_exit">Exit</string>
<string name="time_ago">ago</string>
<string name="last_response">Last response</string>
<string name="shared_string_group">Group</string>

View file

@ -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) {

View file

@ -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<String>()
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()
}

View file

@ -183,9 +183,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
setOnCheckedChangeListener { _, isChecked ->
if (!isChecked) {
sharingMode = isChecked
settings.stopSharingLocationToChats()
shareLocationHelper.stopSharingLocation()
telegramHelper.stopSendingLiveLocationMessages()
activity.stopSharingLocation()
updateContent()
}
}