on logout clear all settings and internal state
This commit is contained in:
parent
cade49f764
commit
a3d5cd8567
3 changed files with 14 additions and 1 deletions
|
@ -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()
|
||||
|
|
|
@ -35,12 +35,16 @@ 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) {
|
||||
messages.add(Message(chatId, messageId))
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue