Forráskód Böngészése

minor cleanup in OfflineFirstChatRepository

fix to show unreadMessagesPopup at bottom (typingIndicatorWrapper must not be gone but invisible)

align unreadMessagesPopup to not overlap typingIndicator

fix to hide scrollDown button when unreadMessagesPopup is shown

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 10 hónapja
szülő
commit
5bccdada7c

+ 4 - 3
app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt

@@ -989,7 +989,8 @@ class ChatActivity :
                 super.onScrollStateChanged(recyclerView, newState)
 
                 if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
-                    if (layoutManager!!.findFirstCompletelyVisibleItemPosition() > 0) {
+                    if (layoutManager!!.findFirstCompletelyVisibleItemPosition() > 0 &&
+                        !binding.unreadMessagesPopup.isShown) {
                         binding.scrollDownButton.visibility = View.VISIBLE
                     } else {
                         binding.scrollDownButton.visibility = View.GONE
@@ -999,7 +1000,7 @@ class ChatActivity :
                         if (layoutManager!!.findFirstCompletelyVisibleItemPosition() < newMessagesCount) {
                             newMessagesCount = 0
 
-                            if (binding.unreadMessagesPopup.isShown == true) {
+                            if (binding.unreadMessagesPopup.isShown) {
                                 binding.unreadMessagesPopup.hide()
                             }
                         }
@@ -1280,7 +1281,7 @@ class ChatActivity :
                     .setInterpolator(AccelerateDecelerateInterpolator())
                     .duration = TYPING_INDICATOR_ANIMATION_DURATION
             } else {
-                binding.typingIndicatorWrapper.visibility = View.GONE
+                binding.typingIndicatorWrapper.visibility = View.INVISIBLE
                 binding.typingIndicatorWrapper.y += DisplayUtils.convertDpToPixel(18f, context)
             }
         }

+ 5 - 39
app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt

@@ -89,7 +89,6 @@ class OfflineFirstChatRepository @Inject constructor(
         this.conversationModel = conversationModel
         this.credentials = credentials
         this.urlForChatting = urlForChatting
-        // internalConversationId = userProvider.currentUser.blockingGet().id!!.toString() + "@" + conversationModel.token
         internalConversationId = conversationModel.internalId
     }
 
@@ -134,26 +133,11 @@ class OfflineFirstChatRepository @Inject constructor(
                 lastKnown = beforeMessageId.toInt()
             )
             withNetworkParams.putSerializable(BundleKeys.KEY_FIELD_MAP, fieldMap)
-            // withNetworkParams.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken)
 
             val loadFromServer = hasToLoadPreviousMessagesFromServer(beforeMessageId)
 
-            if (loadFromServer) {
-                if (monitor.isOnline.first()) {
-                    sync(withNetworkParams)
-                } else {
-                    // TODO: handle how user is informed about gaps when being offline. Something like:
-                    // val offlineChatMessage = ChatMessage(
-                    //     message = "you are offline. Some messages might be missing here."
-                    // )
-                    // val list = mutableListOf<ChatMessage>()
-                    // list.add(offlineChatMessage)
-                    //
-                    // if (list.isNotEmpty()) {
-                    //     val pair = Pair(false, list)
-                    //     _messageFlow.emit(pair)
-                    // }
-                }
+            if (loadFromServer && monitor.isOnline.first()) {
+                sync(withNetworkParams)
             }
 
             showLast100MessagesBefore(internalConversationId, beforeMessageId)
@@ -161,8 +145,6 @@ class OfflineFirstChatRepository @Inject constructor(
 
     override fun initMessagePolling(): Job =
         scope.launch {
-            // monitor.isOnline.onEach { online ->
-
             Log.d(TAG, "---- initMessagePolling ------------")
 
             val initialMessageId = chatDao.getNewestMessageId(internalConversationId).toInt()
@@ -180,15 +162,10 @@ class OfflineFirstChatRepository @Inject constructor(
             while (!itIsPaused) {
                 if (!monitor.isOnline.first()) Thread.sleep(500)
 
-                // sync database with server ( This is a long blocking call b/c long polling is set )
+                // sync database with server (This is a long blocking call because long polling (lookIntoFuture) is set)
                 networkParams.putSerializable(BundleKeys.KEY_FIELD_MAP, fieldMap)
-                // withNetworkParams.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken)
-
-                // this@OfflineFirstChatRepository.sync(withNetworkParams)
-                // sync(withNetworkParams)
 
                 val resultsFromSync = sync(networkParams)
-                // TODO: load from DB?! at least make sure no changes are made here that are not saved to DB then!
 
                 Log.d(TAG, "got result from longpolling")
                 if (!resultsFromSync.isNullOrEmpty()) {
@@ -209,18 +186,16 @@ class OfflineFirstChatRepository @Inject constructor(
                 //     return@map chatMessage
                 // }
 
-                val newestMessage2 = chatDao.getNewestMessageId(internalConversationId).toInt()
-                Log.d(TAG, "newestMessage in loop: $newestMessage2")
+                val newestMessage = chatDao.getNewestMessageId(internalConversationId).toInt()
 
                 // update field map vars for next cycle
                 fieldMap = getFieldMap(
                     lookIntoFuture = true,
                     includeLastKnown = false,
                     setReadMarker = true,
-                    lastKnown = newestMessage2
+                    lastKnown = newestMessage
                 )
             }
-            // }.flowOn(Dispatchers.IO).collect()
         }
 
     private suspend fun hasToLoadPreviousMessagesFromServer(
@@ -282,11 +257,6 @@ class OfflineFirstChatRepository @Inject constructor(
         return fieldMap
     }
 
-    private suspend fun getMessagesFrom(messageIds: List<Long>): List<ChatMessage> =
-        chatDao.getMessagesFromIds(messageIds).map {
-            it.map(ChatMessageEntity::asModel)
-        }.first()
-
     override suspend fun getMessage(messageId: Long, bundle: Bundle):
         Flow<ChatMessage> {
 
@@ -314,8 +284,6 @@ class OfflineFirstChatRepository @Inject constructor(
     @Suppress("UNCHECKED_CAST")
     private fun getMessagesFromServer(bundle: Bundle): Pair<Int, List<ChatMessageJson>>? {
         Log.d(TAG, "An online request is made!!!!!!!!!!!!!!!!!!!!")
-        // val credentials = bundle.getString(BundleKeys.KEY_CREDENTIALS)
-        // val url = bundle.getString(BundleKeys.KEY_CHAT_URL)
         val fieldMap = bundle.getSerializable(BundleKeys.KEY_FIELD_MAP) as HashMap<String, Int>
 
         try {
@@ -393,7 +361,6 @@ class OfflineFirstChatRepository @Inject constructor(
         val lookIntoFuture = fieldMap["lookIntoFuture"] == 1
 
         val statusCode = result.first
-        // val statusCode = result.first
 
         val hasHistory = getHasHistory(statusCode, lookIntoFuture)
 
@@ -487,7 +454,6 @@ class OfflineFirstChatRepository @Inject constructor(
                     // We scroll up and load the system message. Deleting everything is not an option as we
                     // would loose the messages that we want to keep. We only want to
                     // delete the messages and chatBlocks older than the system message.
-
                     chatDao.deleteMessagesOlderThan(internalConversationId, messageJson.id)
                     chatBlocksDao.deleteChatBlocksOlderThan(internalConversationId, messageJson.id)
                 }

+ 1 - 1
app/src/main/res/layout/activity_chat.xml

@@ -166,7 +166,7 @@
             android:layout_marginStart="64dp"
             android:layout_marginTop="16dp"
             android:layout_marginEnd="64dp"
-            android:layout_marginBottom="26dp"
+            android:layout_marginBottom="45dp"
             android:layout_toStartOf="@+id/scrollDownButton"
             android:ellipsize="middle"
             android:minHeight="@dimen/min_size_clickable_area"