From 1d33880b43e204b6498da1f6e82504c6e53dfd94 Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Mon, 13 Jan 2020 18:14:13 +0200 Subject: [PATCH] Fixed a bug of updating the outbox messages count when a user delete a message from the message details screen.| #793 --- .../email/jetpack/viewmodel/MsgDetailsViewModel.kt | 11 +++++++++++ .../ui/activity/fragment/MessageDetailsFragment.kt | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MsgDetailsViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MsgDetailsViewModel.kt index a75d6f46f1..622f03e9e8 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MsgDetailsViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MsgDetailsViewModel.kt @@ -9,6 +9,7 @@ import android.app.Application import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope +import com.flowcrypt.email.api.email.JavaEmailConstants import com.flowcrypt.email.api.email.model.LocalFolder import com.flowcrypt.email.api.email.model.MessageFlag import com.flowcrypt.email.database.FlowCryptRoomDatabase @@ -85,6 +86,16 @@ class MsgDetailsViewModel(val localFolder: LocalFolder, val msgEntity: MessageEn freshMsgEntity?.let { msgEntity -> viewModelScope.launch { roomDatabase.msgDao().deleteSuspend(msgEntity) + + if (JavaEmailConstants.FOLDER_OUTBOX.equals(localFolder.fullName, ignoreCase = true)) { + val outgoingMsgCount = roomDatabase.msgDao().getOutboxMsgsExceptSentSuspend(msgEntity.email).size + val outboxLabel = roomDatabase.labelDao().getLabelSuspend(msgEntity.email, + JavaEmailConstants.FOLDER_OUTBOX) + + outboxLabel?.let { + roomDatabase.labelDao().updateSuspend(it.copy(msgsCount = outgoingMsgCount)) + } + } } } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt index 521a1af0c5..b5e96a6d84 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt @@ -223,7 +223,7 @@ class MessageDetailsFragment : BaseSyncFragment(), View.OnClickListener { } R.id.menuActionDeleteMessage -> { - if (JavaEmailConstants.FOLDER_OUTBOX.equals(msgEntity!!.folder, ignoreCase = true)) { + if (JavaEmailConstants.FOLDER_OUTBOX.equals(msgEntity?.folder, ignoreCase = true)) { val msgEntity = msgDetailsViewModel?.msgLiveData?.value msgEntity?.let { @@ -234,7 +234,6 @@ class MessageDetailsFragment : BaseSyncFragment(), View.OnClickListener { Toast.makeText(context, R.string.message_was_deleted, Toast.LENGTH_SHORT).show() } } - } else { msgDetailsViewModel?.changeMsgState(MessageState.PENDING_DELETING) }