From db583742ff8a42c822bc0ac8c229656d5054f7c7 Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Fri, 10 Jan 2020 10:19:53 +0200 Subject: [PATCH] Fixed run actions which change the message state in MessageDetailsActivity.| #793 --- .../jetpack/viewmodel/MsgDetailsViewModel.kt | 4 ++++ .../ui/activity/MessageDetailsActivity.kt | 19 +++++++++++++++++++ .../fragment/MessageDetailsFragment.kt | 9 --------- 3 files changed, 23 insertions(+), 9 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 01652ac27d..a75d6f46f1 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 @@ -7,6 +7,7 @@ package com.flowcrypt.email.jetpack.viewmodel import android.app.Application import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.flowcrypt.email.api.email.model.LocalFolder import com.flowcrypt.email.api.email.model.MessageFlag @@ -28,6 +29,8 @@ class MsgDetailsViewModel(val localFolder: LocalFolder, val msgEntity: MessageEn var msgLiveData: LiveData = roomDatabase.msgDao().getMsgLiveData(msgEntity.email, msgEntity.folder, msgEntity.uid) + val msgStatesLiveData = MutableLiveData() + fun setSeenStatus(isSeen: Boolean) { val freshMsgEntity = msgLiveData.value freshMsgEntity?.let { msgEntity -> @@ -72,6 +75,7 @@ class MsgDetailsViewModel(val localFolder: LocalFolder, val msgEntity: MessageEn } roomDatabase.msgDao().updateSuspend(candidate) + msgStatesLiveData.postValue(newMsgState) } } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/MessageDetailsActivity.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/MessageDetailsActivity.kt index 9175a31067..a34d66b92d 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/MessageDetailsActivity.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/MessageDetailsActivity.kt @@ -386,6 +386,25 @@ class MessageDetailsActivity : BaseBackStackSyncActivity(), LoaderManager.Loader msgDetailsViewModel = ViewModelProvider(this, MsgDetailsViewModelFactory(localFolder, messageEntity, application)).get(MsgDetailsViewModel::class.java) msgDetailsViewModel.msgLiveData.observe(this, genMsgObserver()) + msgDetailsViewModel.msgStatesLiveData.observe(this, Observer { + var finishActivity = true + when (it) { + MessageState.PENDING_ARCHIVING -> archiveMsgs() + MessageState.PENDING_DELETING -> deleteMsgs() + MessageState.PENDING_MOVE_TO_INBOX -> moveMsgsToINBOX() + MessageState.PENDING_MARK_UNREAD -> changeMsgsReadState() + MessageState.PENDING_MARK_READ -> { + changeMsgsReadState() + finishActivity = false + } + else -> { + } + } + + if (finishActivity) { + finish() + } + }) } /** 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 47b5548ca7..b7d545546a 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 @@ -60,7 +60,6 @@ import com.flowcrypt.email.service.attachment.AttachmentDownloadManagerService import com.flowcrypt.email.ui.activity.CreateMessageActivity import com.flowcrypt.email.ui.activity.ImportPrivateKeyActivity import com.flowcrypt.email.ui.activity.MessageDetailsActivity -import com.flowcrypt.email.ui.activity.base.BaseSyncActivity import com.flowcrypt.email.ui.activity.fragment.base.BaseSyncFragment import com.flowcrypt.email.ui.activity.fragment.dialog.ChoosePublicKeyDialogFragment import com.flowcrypt.email.ui.widget.EmailWebView @@ -213,8 +212,6 @@ class MessageDetailsFragment : BaseSyncFragment(), View.OnClickListener { return when (item.itemId) { R.id.menuActionArchiveMessage -> { msgDetailsViewModel?.changeMsgState(MessageState.PENDING_ARCHIVING) - (activity as? BaseSyncActivity)?.archiveMsgs() - activity?.finish() true } @@ -233,23 +230,17 @@ class MessageDetailsFragment : BaseSyncFragment(), View.OnClickListener { } else { msgDetailsViewModel?.changeMsgState(MessageState.PENDING_DELETING) - (activity as? BaseSyncActivity)?.deleteMsgs() } - activity?.finish() true } R.id.menuActionMoveToInbox -> { msgDetailsViewModel?.changeMsgState(MessageState.PENDING_MOVE_TO_INBOX) - (activity as? BaseSyncActivity)?.moveMsgsToINBOX() - activity?.finish() true } R.id.menuActionMarkUnread -> { msgDetailsViewModel?.changeMsgState(MessageState.PENDING_MARK_UNREAD) - (activity as? BaseSyncActivity)?.changeMsgsReadState() - activity?.finish() true }