From cb01b1ffe66dfeca3f590511ce695f73fb7d7d22 Mon Sep 17 00:00:00 2001 From: rapterjet2004 Date: Mon, 28 Oct 2024 08:27:34 -0500 Subject: [PATCH 1/2] Shows if no offline messages are saved Signed-off-by: rapterjet2004 --- .../com/nextcloud/talk/chat/ChatActivity.kt | 24 +++++++++--- .../talk/chat/data/ChatMessageRepository.kt | 6 +++ .../network/OfflineFirstChatRepository.kt | 7 ++++ .../talk/chat/viewmodels/ChatViewModel.kt | 2 + app/src/main/res/layout/activity_chat.xml | 6 +++ .../res/layout/no_saved_messages_view.xml | 37 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/layout/no_saved_messages_view.xml diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index e76fd7f713..80d44b8381 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -194,6 +194,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -444,7 +445,7 @@ class ChatActivity : this.lifecycleScope.launch { delay(DELAY_TO_SHOW_PROGRESS_BAR) - if (adapter?.isEmpty == true) { + if (adapter?.isEmpty == true && networkMonitor.isOnline.first()) { binding.progressBar.visibility = View.VISIBLE } } @@ -939,6 +940,20 @@ class ChatActivity : .collect() } + this.lifecycleScope.launch { + chatViewModel.getGeneralUIFlow.onEach { key -> + when (key) { + NO_OFFLINE_MESSAGES_FOUND -> { + if (networkMonitor.isOnline.first().not()) { + binding.offline.root.visibility = View.VISIBLE + } + } + + else -> {} + } + }.collect() + } + chatViewModel.reactionDeletedViewState.observe(this) { state -> when (state) { is ChatViewModel.ReactionDeletedSuccessState -> { @@ -2810,14 +2825,10 @@ class ChatActivity : message1.timestamp ) val isLessThan5Min = timeDifference > FIVE_MINUTES_IN_SECONDS - if (isSameDayMessages(message2, message1) && + return isSameDayMessages(message2, message1) && (message2.actorId == message1.actorId) && (!isLessThan5Min) && (message2.lastEditTimestamp == 0L || message1.lastEditTimestamp == 0L) - ) { - return true - } - return false } private fun determinePreviousMessageIds(chatMessageList: List) { @@ -3848,5 +3859,6 @@ class ChatActivity : private const val DELAY_TO_SHOW_PROGRESS_BAR = 1000L private const val FIVE_MINUTES_IN_SECONDS: Long = 300 const val CONVERSATION_INTERNAL_ID = "CONVERSATION_INTERNAL_ID" + const val NO_OFFLINE_MESSAGES_FOUND = "NO_OFFLINE_MESSAGES_FOUND" } } diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/ChatMessageRepository.kt b/app/src/main/java/com/nextcloud/talk/chat/data/ChatMessageRepository.kt index 860da6c21f..5cbf39efe7 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/ChatMessageRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/ChatMessageRepository.kt @@ -35,6 +35,12 @@ interface ChatMessageRepository : LifecycleAwareManager { val lastReadMessageFlow: Flow + /** + * Used for informing the user of the underlying processing behind offline support, [String] is the key + * which is handled in a switch statement in ChatActivity. + */ + val generalUIFlow: Flow + fun setData(conversationModel: ConversationModel, credentials: String, urlForChatting: String) fun loadInitialMessages(withNetworkParams: Bundle): Job diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt index 361f40ce09..e29628866d 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt @@ -10,6 +10,7 @@ package com.nextcloud.talk.chat.data.network import android.os.Bundle import android.util.Log +import com.nextcloud.talk.chat.ChatActivity import com.nextcloud.talk.chat.data.ChatMessageRepository import com.nextcloud.talk.chat.data.model.ChatMessage import com.nextcloud.talk.data.database.dao.ChatBlocksDao @@ -91,6 +92,11 @@ class OfflineFirstChatRepository @Inject constructor( private val _lastReadMessageFlow: MutableSharedFlow = MutableSharedFlow() + override val generalUIFlow: Flow + get() = _generalUIFlow + + private val _generalUIFlow: MutableSharedFlow = MutableSharedFlow() + private var newXChatLastCommonRead: Int? = null private var itIsPaused = false private val scope = CoroutineScope(Dispatchers.IO) @@ -133,6 +139,7 @@ class OfflineFirstChatRepository @Inject constructor( } else { if (!weAlreadyHaveSomeOfflineMessages) { Log.d(TAG, "An online request for newest 100 messages is made because offline chat is empty") + _generalUIFlow.emit(ChatActivity.NO_OFFLINE_MESSAGES_FOUND) } else { Log.d( TAG, diff --git a/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt b/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt index 7ec377bc1b..1798d7403b 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt @@ -137,6 +137,8 @@ class ChatViewModel @Inject constructor( _getRoomViewState.value = GetRoomErrorState } + val getGeneralUIFlow = chatRepository.generalUIFlow + sealed interface ViewState object GetReminderStartState : ViewState diff --git a/app/src/main/res/layout/activity_chat.xml b/app/src/main/res/layout/activity_chat.xml index c6d5e791be..23e4c9de81 100644 --- a/app/src/main/res/layout/activity_chat.xml +++ b/app/src/main/res/layout/activity_chat.xml @@ -98,6 +98,12 @@ android:layout_height="0dp" android:layout_weight="1"> + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0e5244921a..700af1ab21 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -834,6 +834,7 @@ How to translate with transifex: Archived Once a conversation is archived, it will be hidden by default. Select the filter \"Archived\" to view archived conversations. Direct mentions will still be received. Once a conversation is unarchived, it will be shown by default again. + No offline messages saved Previously set Failed to set conversation Read-only Status Reverted From a0d6442205c575c0d318e82fde054c24848eee3f Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 3 Dec 2024 10:21:10 +0100 Subject: [PATCH 2/2] fix Duplicate ids in xml Signed-off-by: Marcel Hibbe --- app/src/main/res/layout/no_saved_messages_view.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/layout/no_saved_messages_view.xml b/app/src/main/res/layout/no_saved_messages_view.xml index 2d470e068a..da22be860c 100644 --- a/app/src/main/res/layout/no_saved_messages_view.xml +++ b/app/src/main/res/layout/no_saved_messages_view.xml @@ -7,15 +7,15 @@ -->