on logout clear all settings and internal state

This commit is contained in:
Chumva 2018-08-20 15:07:08 +03:00
parent cade49f764
commit a3d5cd8567
3 changed files with 14 additions and 1 deletions

View file

@ -162,6 +162,13 @@ class TelegramSettings(private val app: TelegramApplication) {
fun getShowOnMapChatsCount() = showOnMapChats.size
fun clear() {
stopSharingLocationToChats()
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
val edit = prefs.edit()
edit.clear().apply()
}
fun save() {
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
val edit = prefs.edit()

View file

@ -35,11 +35,15 @@ class MessagesDbHelper(val app: TelegramApplication) {
}
fun saveMessages() {
sqliteHelper.clearMessages()
clearMessages()
synchronized(messages) {
sqliteHelper.addMessages(messages)
}
}
fun clearMessages() {
sqliteHelper.clearMessages()
}
private fun addMessage(chatId: Long, messageId: Long) {
synchronized(messages) {

View file

@ -271,6 +271,8 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
fun logoutTelegram(silent: Boolean = false) {
if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) {
if (app.isInternetConnectionAvailable) {
app.messagesDbHelper.clearMessages()
settings.clear()
telegramHelper.logout()
} else {
Toast.makeText(this, R.string.logout_no_internet_msg, Toast.LENGTH_SHORT).show()