ChannelFragment not refreshing list of messages

I’m having issues with ChannelFragment not updating the messages list.

In my own fragment, I’m adding a ChannelFragment like so:

Once it’s being displayed in the foreground, I send messages from a different device/user and the ChannelFragment doesn’t refresh it’s content.

I’m seeing this in the logs in the screenshot however, which probably means that the message is correctly being delivered to the device, just not displayed on the UI.

It’s worth mentioning that if I re-enter this screen, all the messages are properly loaded and displayed, so it seems to be an issue of refreshing while it’s being displayed.

Should the ChannelFragment just work out of the box? Am I missing something here to make this work all the time?

Thanks in advance.

Hi, @robertoestivill
I think you should debug your conversationAdapter.
How did you implement it?

You should follow this link.

and our UIKit is Open source. You can see the source code!

Thanks for the speedy reply @Doo_Rim.
I have clone the uikit sources repo and actually used it as a based for my adapter.
Below it’s an example of how the adapter is organized to support 3 custom types messages.
I don’t think there’s nothing extremely complex about it, but maybe I’m missing something or miss-using some api.

package com.example.myapp

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import com.sendbird.android.GroupChannel
import com.sendbird.uikit.activities.adapter.MessageListAdapter
import com.sendbird.uikit.activities.viewholder.MessageViewHolder

class ExampleAdapter(
    private val context: Context,
    private val groupChannel: GroupChannel,
) : MessageListAdapter(groupChannel) {

    private val layoutInflater = LayoutInflater.from(context)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageViewHolder {
        return when (viewType) {
            VIEW_TYPE_CUSTOM_1 -> createViewHolderCustom1(parent)
            VIEW_TYPE_CUSTOM_2 -> createViewHolderCustom2(parent)
            VIEW_TYPE_CUSTOM_3 -> createViewHolderCustom3(parent)
            else -> super.onCreateViewHolder(parent, viewType)
        }
    }

    override fun getItemViewType(position: Int): Int {
        val message = getItem(position)
        return when (message.customType) {
            MESSAGE_CUSTOM_TYPE_1 -> VIEW_TYPE_CUSTOM_1
            MESSAGE_CUSTOM_TYPE_3 -> VIEW_TYPE_CUSTOM_3
            MESSAGE_CUSTOM_TYPE_2 -> VIEW_TYPE_CUSTOM_2
            else -> super.getItemViewType(position)
        }
    }

    private fun createViewHolderCustom1(parent: ViewGroup): MessageViewHolder {
        ...
    }

    private fun createViewHolderCustom2(parent: ViewGroup): MessageViewHolder {
        ...
    }

    private fun createViewHolderCustom3(parent: ViewGroup): MessageViewHolder {
        ...
    }

    companion object {
        private const val MESSAGE_CUSTOM_TYPE_1 = "custom_message_1"
        private const val MESSAGE_CUSTOM_TYPE_2 = "custom_message_2"
        private const val MESSAGE_CUSTOM_TYPE_3 = "custom_message_3"

        private const val VIEW_TYPE_CUSTOM_1 = 13235
        private const val VIEW_TYPE_CUSTOM_2 = 42395
        private const val VIEW_TYPE_CUSTOM_3 = 89543
    }
}

Again, note that most of the time everything works fine, however sometimes, it just doesn’t refresh the message list (almost like if there was no connectivity, but obviously there is as I see the log messages)

Thanks for the help.

Following your logs, runnable=null means your app is on the background.
If your app comes back to the foreground, our UIKit retrieves the changelog of the message list.
Could you give us the repeatable scenario?!

Well that’s interesting.
The app was definitely in the foreground, as I was wondering why it wouldn’t update.
I can not consistently reproduce it though, so I will make sure that I try to isolate the issue when I encounter it again.

1 Like

Okay! Thank you! If you encounter it, let me know!