Show appropriate message when message does not exist
MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt
app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt
@@ -65,6 +65,9 @@ class MessagePreviewFragment :
override val printHTML: String
get() = requireContext().assets.open("message-print-page.html").bufferedReader().use { it.readText() }
+ override val messageNotExists: String
+ get() = getString(R.string.message_not_exists)
+
companion object {
const val MESSAGE_ID_KEY = "message_id"

MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewPresenter.kt
app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewPresenter.kt
@@ -10,8 +10,8 @@ import io.github.wulkanowy.data.repositories.MessageRepository
import io.github.wulkanowy.data.repositories.StudentRepository
import io.github.wulkanowy.ui.base.BasePresenter
import io.github.wulkanowy.ui.base.ErrorHandler
-import io.github.wulkanowy.utils.AppInfo
import io.github.wulkanowy.utils.AnalyticsHelper
+import io.github.wulkanowy.utils.AppInfo
import io.github.wulkanowy.utils.afterLoading
import io.github.wulkanowy.utils.flowWithResource
import io.github.wulkanowy.utils.flowWithResourceIn
@@ -65,7 +65,7 @@ class MessagePreviewPresenter @Inject constructor(
Status.LOADING -> Timber.i("Loading message ${message.messageId} preview started")
Status.SUCCESS -> {
Timber.i("Loading message ${message.messageId} preview result: Success ")
- checkNotNull(it.data, { "Can't find message in local db! Probably no longer exist in this folder" })
+ if (it.data != null) {
this@MessagePreviewPresenter.message = it.data.message
this@MessagePreviewPresenter.attachments = it.data.attachments
view?.apply {
@@ -77,6 +77,12 @@ class MessagePreviewPresenter @Inject constructor(
"type" to "message_preview",
"length" to it.data.message.content.length
)
+ } else {
+ view?.run {
+ showMessage(messageNotExists)
+ popView()
+ }
+ }
}
Status.ERROR -> {
Timber.i("Loading message ${message.messageId} preview result: An exception occurred ")

MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt
app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt
@@ -14,6 +14,8 @@ interface MessagePreviewView : BaseView {
val printHTML: String
+ val messageNotExists: String
+
fun initView()
fun setMessageWithAttachment(item: MessageWithAttachment)

MODIFY
app/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
<string name="message_subject">Subject</string>
<string name="message_content">Content</string>
<string name="message_send_successful">Message sent successfully</string>
+ <string name="message_not_exists">Message does not exist</string>
<string name="message_required_recipients">You need to choose at least 1 recipient</string>
<string name="message_content_min_length">The message content must be at least 3 characters</string>
<plurals name="message_number_item">

Show appropriate message when message does not exist (#1083)