Skip to content

Commit

Permalink
Directly upload Attachment when adding it to the Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Apr 30, 2024
1 parent a686d09 commit b6a6d35
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,15 @@ class NewMessageFragment : Fragment() {

private fun observeAttachments() = with(newMessageViewModel) {

var shouldRegisterToImportedAttachments = true
var isFirstTime = true

attachmentsLiveData.observe(viewLifecycleOwner) { attachments ->

if (shouldRegisterToImportedAttachments) {
shouldRegisterToImportedAttachments = false
if (isFirstTime) {
isFirstTime = false
observeImportAttachments()
} else {
saveDraft()
}

val shouldTransition = attachmentAdapter.itemCount != 0 && attachments.isEmpty()
Expand Down Expand Up @@ -521,8 +523,12 @@ class NewMessageFragment : Fragment() {
}
}

override fun onStop() = with(newMessageViewModel) {
override fun onStop() {
saveDraft()
super.onStop()
}

private fun saveDraft() = with(newMessageViewModel) {
executeDraftActionWhenStopping(
action = if (shouldSendInsteadOfSave) DraftAction.SEND else DraftAction.SAVE,
isFinishing = requireActivity().isFinishing,
Expand All @@ -531,8 +537,6 @@ class NewMessageFragment : Fragment() {
uiBodyValue = binding.bodyTextField.text.toString(),
startWorkerCallback = ::startWorker,
)

super.onStop()
}

private fun startWorker() {
Expand Down

0 comments on commit b6a6d35

Please sign in to comment.