Skip to content

Commit

Permalink
Fixed run actions which change the message state in MessageDetailsAct…
Browse files Browse the repository at this point in the history
…ivity.| #793
  • Loading branch information
DenBond7 committed Jan 10, 2020
1 parent a4c930a commit db58374
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +29,8 @@ class MsgDetailsViewModel(val localFolder: LocalFolder, val msgEntity: MessageEn
var msgLiveData: LiveData<MessageEntity?> = roomDatabase.msgDao().getMsgLiveData(msgEntity.email,
msgEntity.folder, msgEntity.uid)

val msgStatesLiveData = MutableLiveData<MessageState>()

fun setSeenStatus(isSeen: Boolean) {
val freshMsgEntity = msgLiveData.value
freshMsgEntity?.let { msgEntity ->
Expand Down Expand Up @@ -72,6 +75,7 @@ class MsgDetailsViewModel(val localFolder: LocalFolder, val msgEntity: MessageEn
}

roomDatabase.msgDao().updateSuspend(candidate)
msgStatesLiveData.postValue(newMsgState)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit db58374

Please sign in to comment.