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

This commit is contained in:
Mateusz Idziejczak 2021-01-20 11:49:06 +01:00 committed by GitHub
parent 9128e0b55f
commit e6e9d201ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 12 deletions

View File

@ -65,6 +65,9 @@ class MessagePreviewFragment :
override val printHTML: String override val printHTML: String
get() = requireContext().assets.open("message-print-page.html").bufferedReader().use { it.readText() } 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 { companion object {
const val MESSAGE_ID_KEY = "message_id" const val MESSAGE_ID_KEY = "message_id"

View File

@ -10,8 +10,8 @@ import io.github.wulkanowy.data.repositories.MessageRepository
import io.github.wulkanowy.data.repositories.StudentRepository import io.github.wulkanowy.data.repositories.StudentRepository
import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.BasePresenter
import io.github.wulkanowy.ui.base.ErrorHandler import io.github.wulkanowy.ui.base.ErrorHandler
import io.github.wulkanowy.utils.AppInfo
import io.github.wulkanowy.utils.AnalyticsHelper import io.github.wulkanowy.utils.AnalyticsHelper
import io.github.wulkanowy.utils.AppInfo
import io.github.wulkanowy.utils.afterLoading import io.github.wulkanowy.utils.afterLoading
import io.github.wulkanowy.utils.flowWithResource import io.github.wulkanowy.utils.flowWithResource
import io.github.wulkanowy.utils.flowWithResourceIn import io.github.wulkanowy.utils.flowWithResourceIn
@ -65,18 +65,24 @@ class MessagePreviewPresenter @Inject constructor(
Status.LOADING -> Timber.i("Loading message ${message.messageId} preview started") Status.LOADING -> Timber.i("Loading message ${message.messageId} preview started")
Status.SUCCESS -> { Status.SUCCESS -> {
Timber.i("Loading message ${message.messageId} preview result: 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.message = it.data.message
this@MessagePreviewPresenter.attachments = it.data.attachments this@MessagePreviewPresenter.attachments = it.data.attachments
view?.apply { view?.apply {
setMessageWithAttachment(it.data) setMessageWithAttachment(it.data)
initOptions() initOptions()
}
analytics.logEvent(
"load_item",
"type" to "message_preview",
"length" to it.data.message.content.length
)
} else {
view?.run {
showMessage(messageNotExists)
popView()
}
} }
analytics.logEvent(
"load_item",
"type" to "message_preview",
"length" to it.data.message.content.length
)
} }
Status.ERROR -> { Status.ERROR -> {
Timber.i("Loading message ${message.messageId} preview result: An exception occurred ") Timber.i("Loading message ${message.messageId} preview result: An exception occurred ")

View File

@ -14,6 +14,8 @@ interface MessagePreviewView : BaseView {
val printHTML: String val printHTML: String
val messageNotExists: String
fun initView() fun initView()
fun setMessageWithAttachment(item: MessageWithAttachment) fun setMessageWithAttachment(item: MessageWithAttachment)

View File

@ -215,6 +215,7 @@
<string name="message_subject">Temat</string> <string name="message_subject">Temat</string>
<string name="message_content">Treść</string> <string name="message_content">Treść</string>
<string name="message_send_successful">Wiadomość wysłana pomyślnie</string> <string name="message_send_successful">Wiadomość wysłana pomyślnie</string>
<string name="message_not_exists">Wiadomość nie istnieje</string>
<string name="message_required_recipients">Musisz wybrać co najmniej 1 adresata</string> <string name="message_required_recipients">Musisz wybrać co najmniej 1 adresata</string>
<string name="message_content_min_length">Treść wiadomości musi zawierać co najmniej 3 znaki</string> <string name="message_content_min_length">Treść wiadomości musi zawierać co najmniej 3 znaki</string>
<plurals name="message_number_item"> <plurals name="message_number_item">

View File

@ -223,6 +223,7 @@
<string name="message_subject">Subject</string> <string name="message_subject">Subject</string>
<string name="message_content">Content</string> <string name="message_content">Content</string>
<string name="message_send_successful">Message sent successfully</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_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> <string name="message_content_min_length">The message content must be at least 3 characters</string>
<plurals name="message_number_item"> <plurals name="message_number_item">