From 37ddd643ac476122cc4508ac9f450a86b638b408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sun, 9 Feb 2020 15:10:03 +0100 Subject: [PATCH] [Feedback] Hide notification when feedback is open. Fix mixing messages when a thread is open. --- .../data/firebase/SzkolnyAppFirebase.kt | 24 ++++++++++--------- .../ui/modules/feedback/FeedbackFragment.kt | 11 ++++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyAppFirebase.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyAppFirebase.kt index 85860d84..1964869b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyAppFirebase.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyAppFirebase.kt @@ -74,18 +74,20 @@ class SzkolnyAppFirebase(val app: App, val profiles: List, val message: } withContext(Dispatchers.Default) { app.db.feedbackMessageDao().add(message) - val notification = Notification( - id = System.currentTimeMillis(), - title = "Wiadomość od ${message.senderName}", - text = message.text, - type = Notification.TYPE_FEEDBACK_MESSAGE, - profileId = null, - profileName = "Wiadomość od ${message.senderName}" - ).addExtra("action", "feedbackMessage").addExtra("feedbackMessageDeviceId", message.deviceId) - app.db.notificationDao().add(notification) - PostNotifications(app, listOf(notification)) + if (!EventBus.getDefault().hasSubscriberForEvent(FeedbackMessageEvent::class.java)) { + val notification = Notification( + id = System.currentTimeMillis(), + title = "Wiadomość od ${message.senderName}", + text = message.text, + type = Notification.TYPE_FEEDBACK_MESSAGE, + profileId = null, + profileName = "Wiadomość od ${message.senderName}" + ).addExtra("action", "feedbackMessage").addExtra("feedbackMessageDeviceId", message.deviceId) + app.db.notificationDao().add(notification) + PostNotifications(app, listOf(notification)) + } + EventBus.getDefault().postSticky(FeedbackMessageEvent(message)) } - EventBus.getDefault().postSticky(FeedbackMessageEvent(message)) } private fun sharedEvent(teamCode: String, jsonStr: String, message: String) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/feedback/FeedbackFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/feedback/FeedbackFragment.kt index 400f39c4..03fc70c3 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/feedback/FeedbackFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/feedback/FeedbackFragment.kt @@ -70,9 +70,14 @@ class FeedbackFragment : Fragment(), CoroutineScope { fun onFeedbackMessageEvent(event: FeedbackMessageEvent) { EventBus.getDefault().removeStickyEvent(event) val message = event.message - val chatMessage = getChatMessage(message) - if (message.received) chatView.receive(chatMessage) - else chatView.send(chatMessage) + if (currentDeviceId != null && message.deviceId == currentDeviceId) { + val chatMessage = getChatMessage(message) + if (message.received) chatView.receive(chatMessage) + else chatView.send(chatMessage) + } + else { + Toast.makeText(context, "${message.senderName}: Nowa wiadomość w innym wątku.", Toast.LENGTH_LONG).show() + } } private val users = mutableMapOf(