From e6e9d201ce621a727038339dc8595c5a83f0b2a1 Mon Sep 17 00:00:00 2001 From: Mateusz Idziejczak Date: Wed, 20 Jan 2021 11:49:06 +0100 Subject: [PATCH] Show appropriate message when message does not exist (#1083) --- .../message/preview/MessagePreviewFragment.kt | 3 ++ .../preview/MessagePreviewPresenter.kt | 30 +++++++++++-------- .../message/preview/MessagePreviewView.kt | 2 ++ app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt index b35731cae..74f8f57ec 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt +++ b/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" diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewPresenter.kt index 17aba10f8..55b9631af 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewPresenter.kt +++ b/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,18 +65,24 @@ 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" }) - this@MessagePreviewPresenter.message = it.data.message - this@MessagePreviewPresenter.attachments = it.data.attachments - view?.apply { - setMessageWithAttachment(it.data) - initOptions() + if (it.data != null) { + this@MessagePreviewPresenter.message = it.data.message + this@MessagePreviewPresenter.attachments = it.data.attachments + view?.apply { + setMessageWithAttachment(it.data) + 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 -> { Timber.i("Loading message ${message.messageId} preview result: An exception occurred ") diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt index fa6d735ed..583ba6878 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt +++ b/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) diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 14c93d1a2..19e312bab 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -215,6 +215,7 @@ Temat Treść Wiadomość wysłana pomyślnie + Wiadomość nie istnieje Musisz wybrać co najmniej 1 adresata Treść wiadomości musi zawierać co najmniej 3 znaki diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 427a1eae0..9d707d094 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -223,6 +223,7 @@ Subject Content Message sent successfully + Message does not exist You need to choose at least 1 recipient The message content must be at least 3 characters