Improve handling of errors when saving media attachments.

Improves the error handling in `SaveAttachmentUtil.saveAttachments()` to continue processing all requested attachment saves even after individual save operations fail.
This commit is contained in:
Jeffrey Starke
2025-03-10 13:50:40 -04:00
committed by Greyson Parrelli
parent 9b6f355802
commit f2950e279b
4 changed files with 118 additions and 83 deletions

View File

@@ -89,6 +89,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import kotlinx.coroutines.rx3.rxSingle
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
@@ -2443,12 +2444,12 @@ class ConversationFragment :
resources.getQuantityString(R.plurals.ConversationFragment_saving_n_attachments_to_sd_card, attachments.size, attachments.size)
).build().toBundle()
SaveAttachmentUtil.saveAttachments(attachments)
rxSingle { SaveAttachmentUtil.saveAttachments(attachments) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe { progressDialog.show(parentFragmentManager, null) }
.doOnTerminate { progressDialog.dismissAllowingStateLoss() }
.subscribeBy { it.toast(requireContext()) }
.subscribeBy { result -> Toast.makeText(context, result.getMessage(requireContext()), Toast.LENGTH_LONG).show() }
.addTo(disposables)
}