From 93e5bce77887cb29ed13e1947b66d27df975818f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 8 Feb 2020 23:12:32 +0100 Subject: [PATCH] [Feedback] Fix showing wrong names, improve messages filtering by device id. --- .../ui/modules/feedback/FeedbackFragment.kt | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) 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 81531cdb..400f39c4 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 @@ -22,14 +22,11 @@ import kotlinx.coroutines.* import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode -import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.MainActivity -import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.data.api.events.FeedbackMessageEvent import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi import pl.szczodrzynski.edziennik.data.db.entity.FeedbackMessage import pl.szczodrzynski.edziennik.databinding.FragmentFeedbackBinding -import pl.szczodrzynski.edziennik.onClick import pl.szczodrzynski.edziennik.utils.Themes import pl.szczodrzynski.edziennik.utils.Utils import pl.szczodrzynski.edziennik.utils.Utils.openUrl @@ -82,7 +79,7 @@ class FeedbackFragment : Fragment(), CoroutineScope { 0 to User(0, "Ja", null) ) private fun getUser(message: FeedbackMessage): User { - val userId = message.devId ?: if (message.received) 1 else 0 + val userId = message.devId ?: if (message.received) -message.senderName.crc16() else 0 return users[userId] ?: run { User(userId, message.senderName, message.devImage).also { users[userId] = it } } @@ -118,13 +115,11 @@ class FeedbackFragment : Fragment(), CoroutineScope { } private suspend fun loadMessages(messageList: List? = null) { - /*if (messageList != null && messageList.isNotEmpty()) - return*/ - val messages = messageList ?: withContext(Dispatchers.Default) { + val messages = withContext(Dispatchers.Default) { if (currentDeviceId == null) - app.db.feedbackMessageDao().allNow + messageList ?: app.db.feedbackMessageDao().allNow else - app.db.feedbackMessageDao().getByDeviceIdNow(currentDeviceId!!) + messageList?.filter { it.deviceId == currentDeviceId } ?: app.db.feedbackMessageDao().getByDeviceIdNow(currentDeviceId!!) } if (messages.isNotEmpty()) { @@ -172,14 +167,14 @@ class FeedbackFragment : Fragment(), CoroutineScope { } if (isDev) { - messages.firstOrNull { it.received }?.let { + messages.firstOrNull { it.received && it.devId == null }?.let { currentDeviceId = it.deviceId b.targetDeviceDropDown.setText("${it.senderName} (${it.deviceId}) - ${it.deviceName}") } // handle notification intent arguments?.getString("feedbackMessageDeviceId")?.let { deviceId -> - currentDeviceId = deviceId - messages.firstOrNull { it.received && it.deviceId == deviceId }?.let { + messages.firstOrNull { it.received && it.deviceId == deviceId && it.devId == null }?.let { + currentDeviceId = deviceId b.targetDeviceDropDown.setText("${it.senderName} (${it.deviceId}) - ${it.deviceName}") } }