Skip to content

Commit 24c70a1

Browse files
committed
Apply the rest of the code review changes
1 parent a7e3dd4 commit 24c70a1

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) {
@@ -767,7 +767,7 @@ class NewMessageViewModel @Inject constructor(
767767
}.onFailure(Sentry::captureException)
768768
}
769769

770-
fun saveBodyAndSubject(subject: String, html: String) {
770+
fun storeBodyAndSubject(subject: String, html: String) {
771771
globalCoroutineScope.launch(ioDispatcher) {
772772
_subjectAndBodyChannel.send(SubjectAndBodyData(subject, html, channelExpirationIdTarget))
773773
}
@@ -853,7 +853,7 @@ class NewMessageViewModel @Inject constructor(
853853

854854
val signature = uiSignatureLiveData.value
855855
val quote = uiQuoteLiveData.value
856-
body = assembleWholeBody(uiBodyValue, signature, quote)
856+
body = uiBodyValue + (signature ?: "") + (quote ?: "")
857857

858858
/**
859859
* If we are opening for the 1st time an existing Draft created somewhere else
@@ -915,9 +915,6 @@ class NewMessageViewModel @Inject constructor(
915915
}
916916
}
917917

918-
private fun assembleWholeBody(body: String, signature: String?, quote: String?): String =
919-
body + (signature ?: "") + (quote ?: "")
920-
921918
private fun isSnapshotTheSame(subjectValue: String?, uiBodyValue: String): Boolean {
922919
return snapshot?.let { draftSnapshot ->
923920
draftSnapshot.identityId == fromLiveData.value?.signature?.id?.toString() &&
@@ -1012,6 +1009,8 @@ class NewMessageViewModel @Inject constructor(
10121009

10131010
private data class SubjectAndBodyData(val subject: String, val body: String, val expirationId: Int)
10141011

1012+
private data class BodyData(val body: BodyContentPayload, val signature: String?, val quote: String?)
1013+
10151014
companion object {
10161015
private val TAG = NewMessageViewModel::class.java.simpleName
10171016
private const val ATTACHMENTS_MAX_SIZE = 25L * 1_024L * 1_024L // 25 MB

0 commit comments

Comments
 (0)