Skip to content

Commit d5e4e47

Browse files
committed
Apply the rest of the code review changes
1 parent 8356428 commit d5e4e47

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageFragment.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class NewMessageFragment : Fragment() {
339339

340340
private fun initEditorUi() = with(binding) {
341341
editor.apply {
342-
enableAlgorithmicDarkening(true)
342+
enableAlgorithmicDarkening(isEnabled = true)
343343
if (context.isNightModeEnabled()) editor.addCss(context.readRawResource(R.raw.custom_dark_mode))
344344

345345
addCss(context.readRawResource(R.raw.style))
@@ -599,13 +599,12 @@ class NewMessageFragment : Fragment() {
599599
}
600600

601601
override fun onStop() {
602-
/**
603-
* When the Activity is being stopped, we save the Draft.
604-
* We then need the up-to-date subject & body values.
605-
*/
602+
// When the Activity is being stopped, we save the Draft. To do this, we need to know the subject and body values but
603+
// these values might not be accessible anymore by then. We store them right now before potentially loosing access to them
604+
// in case we need to save the Draft when they're inaccessible.
606605
val subject = binding.subjectTextField.text.toString()
607606
binding.editor.exportHtml { html ->
608-
newMessageViewModel.saveBodyAndSubject(subject, html)
607+
newMessageViewModel.storeBodyAndSubject(subject, html)
609608
}
610609

611610
super.onStop()

app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageViewModel.kt

+7-8
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class NewMessageViewModel @Inject constructor(
295295
if (remoteBody.isEmpty()) return
296296

297297
val (body, signature, quote) = when (draft.mimeType) {
298-
Utils.TEXT_PLAIN -> Triple(BodyContentPayload(remoteBody, BodyContentType.TEXT_PLAIN_WITHOUT_HTML), null, null)
298+
Utils.TEXT_PLAIN -> BodyData(BodyContentPayload(remoteBody, BodyContentType.TEXT_PLAIN_WITHOUT_HTML), null, null)
299299
Utils.TEXT_HTML -> splitSignatureAndQuoteFromHtml(remoteBody)
300300
else -> error("Cannot load an email which is not of type text/plain or text/html")
301301
}
@@ -307,7 +307,7 @@ class NewMessageViewModel @Inject constructor(
307307
}
308308
}
309309

310-
private fun splitSignatureAndQuoteFromHtml(draftBody: String): Triple<BodyContentPayload, String?, String?> {
310+
private fun splitSignatureAndQuoteFromHtml(draftBody: String): BodyData {
311311

312312
fun Document.split(divClassName: String, defaultValue: String): Pair<String, String?> {
313313
return getElementsByClass(divClassName).firstOrNull()?.let {
@@ -335,7 +335,7 @@ class NewMessageViewModel @Inject constructor(
335335
doc.split(MessageBodyUtils.INFOMANIAK_FORWARD_QUOTE_HTML_CLASS_NAME, bodyWithQuote)
336336
}
337337

338-
return Triple(BodyContentPayload(body, BodyContentType.HTML_UNSANITIZED), signature, quote)
338+
return BodyData(BodyContentPayload(body, BodyContentType.HTML_UNSANITIZED), signature, quote)
339339
}
340340

341341
private fun populateWithExternalMailDataIfNeeded(draft: Draft, intent: Intent) {
@@ -774,7 +774,7 @@ class NewMessageViewModel @Inject constructor(
774774
}.onFailure(Sentry::captureException)
775775
}
776776

777-
fun saveBodyAndSubject(subject: String, html: String) {
777+
fun storeBodyAndSubject(subject: String, html: String) {
778778
globalCoroutineScope.launch(ioDispatcher) {
779779
_subjectAndBodyChannel.send(SubjectAndBodyData(subject, html, channelExpirationIdTarget))
780780
}
@@ -863,7 +863,7 @@ class NewMessageViewModel @Inject constructor(
863863

864864
val signature = uiSignatureLiveData.value
865865
val quote = uiQuoteLiveData.value
866-
body = assembleWholeBody(uiBodyValue, signature, quote)
866+
body = uiBodyValue + (signature ?: "") + (quote ?: "")
867867

868868
/**
869869
* If we are opening for the 1st time an existing Draft created somewhere else
@@ -927,9 +927,6 @@ class NewMessageViewModel @Inject constructor(
927927
SentryDebug.addAttachmentsBreadcrumb(draft = this, step)
928928
}
929929

930-
private fun assembleWholeBody(body: String, signature: String?, quote: String?): String =
931-
body + (signature ?: "") + (quote ?: "")
932-
933930
private fun isSnapshotTheSame(subjectValue: String?, uiBodyValue: String): Boolean {
934931
return snapshot?.let { draftSnapshot ->
935932
draftSnapshot.identityId == fromLiveData.value?.signature?.id?.toString() &&
@@ -1024,6 +1021,8 @@ class NewMessageViewModel @Inject constructor(
10241021

10251022
private data class SubjectAndBodyData(val subject: String, val body: String, val expirationId: Int)
10261023

1024+
private data class BodyData(val body: BodyContentPayload, val signature: String?, val quote: String?)
1025+
10271026
companion object {
10281027
private val TAG = NewMessageViewModel::class.java.simpleName
10291028
private const val ATTACHMENTS_MAX_SIZE = 25L * 1_024L * 1_024L // 25 MB

0 commit comments

Comments
 (0)