Listen to page events
Chat UI supports listening to click and long-press events on the channel list page and channel page. Applications can intercept these events in the corresponding methods and implement custom requirements.
Listen to channel list page events
Chat UI provides the channel list listener ChannelListBehaviorListener, which can listen to long-press and click events on channel items and channel portraits in the channel list.
Use NCChatUIConfig.channelListConfig().setBehaviorListener(...) to set the listener.
NCChatUIConfig.channelListConfig().setBehaviorListener(listener);
Long press channel event
The following method is triggered when a channel item is long-pressed in the channel list. By default, the SDK displays a menu with options.
boolean onConversationLongClick(Context context, View view, BaseUiChannel conversation)
| Parameter | Type | Description |
|---|---|---|
| context | Context | Context |
| view | View | View that triggered the click |
| conversation | BaseUiChannel | Long-pressed channel |
Return true to handle this long-press event with custom logic; otherwise, return false to continue with the SDK default behavior.
Click channel event
The following method is triggered when a channel item is clicked in the channel list. When this click event is triggered, the SDK default navigation logic is as follows:
- If it is a gathered channel, navigate to the gathered channel list page.
- If it is a non-gathered channel, navigate to the channel page.
boolean onConversationClick(Context context, View view, BaseUiChannel conversation)
| Parameter | Type | Description |
|---|---|---|
| context | Context | Context |
| view | View | View that triggered the click |
| conversation | BaseUiChannel | Clicked channel |
Return true to handle this click event with custom logic; otherwise, return false to continue with the SDK default behavior.
Click channel portrait event
The following method is triggered when a channel portrait (icon) is clicked. By default, the SDK does not handle this event.
boolean onConversationPortraitClick(Context context, ChannelType conversationType, String targetId)
| Parameter | Type | Description |
|---|---|---|
| context | Context | Context |
| conversationType | ChannelType | Channel type |
| targetId | String | Channel ID |
Return true to handle this click event with custom logic. Otherwise, return false and the event is not handled.
Long press channel portrait event
The following method is triggered when a channel portrait (icon) is long-pressed. By default, the SDK does not handle this event and returns the result directly to the system.
boolean onConversationPortraitLongClick(Context context, ChannelType conversationType, String targetId)
| Parameter | Type | Description |
|---|---|---|
| context | Context | Context |
| conversationType | ChannelType | Channel type |
| targetId | String | Channel ID |
Return true to handle this long-press event with custom logic. Otherwise, return false and the event is not handled.
Listen to channel page events
Chat UI provides the channel listener ChannelClickListener, which can listen to long-press and click events on message items and message portraits on the channel page.
Use NCChatUIConfig.channelConfig().setChannelClickListener(...) to set the listener.
NCChatUIConfig.channelConfig().setChannelClickListener(listener);
Click message event
boolean onMessageClick(Context context, View view, Message message);
| Parameter | Type | Description |
|---|---|---|
| context | Context | Context |
| view | View | View that triggered the click |
| message | Message | Clicked message entity |
Return true if you handle the click logic yourself; otherwise, return false to continue with the SDK default behavior.
Long press message event
boolean onMessageLongClick(Context context, View view, Message message);
| Parameter | Type | Description |
|---|---|---|
| context | Context | Context |
| view | View | View that triggered the click |
| message | Message | Long-pressed message entity |
Return true if you handle the long-press logic yourself; otherwise, return false to continue with the SDK default behavior.
Click user portrait on message event
boolean onUserPortraitClick(
Context context,
ChannelType conversationType,
UserInfo user,
String targetId);
| Parameter | Type | Description |
|---|---|---|
| context | Context | Context |
| conversationType | ChannelType | Channel type |
| user | UserInfo | Clicked user info |
| targetId | String | Channel ID |
Return true if you handle the click logic yourself; otherwise, return false to continue with the SDK default behavior.
Long press user portrait on message event
The following method is triggered when a user portrait (icon) on a message is long-pressed. By default, the SDK navigates to the user selection interface for the @ mention feature.
boolean onUserPortraitLongClick(
Context context,
ChannelType conversationType,
UserInfo user,
String targetId);
| Parameter | Type | Description |
|---|---|---|
| context | Context | Context |
| conversationType | ChannelType | Channel type |
| user | UserInfo | Long-pressed user info |
| targetId | String | Channel ID |
Return true if you handle the long-press logic yourself; otherwise, return false to continue with the SDK default behavior.
Click message hyperlink event
boolean onMessageLinkClick(Context context, String link, Message message);
| Parameter | Type | Description |
|---|---|---|
| context | Context | Context |
| link | String | Clicked link |
| message | Message | Clicked message entity |
Return true if you handle the click logic yourself; otherwise, return false to continue with the SDK default behavior.
Click read receipt status event
boolean onReadReceiptStateClick(Context context, Message message);
| Parameter | Type | Description |
|---|---|---|
| context | Context | Context |
| message | Message | Clicked message entity |
Return true if you handle the click logic yourself; otherwise, return false to continue with the SDK default behavior.
Click quick reply button event
If you have enabled the Chat UI quick reply feature, a quick reply panel appears when the user clicks the quick reply button on the channel page. To intercept this click event, return true and you can customize the logic after clicking the quick reply button; otherwise, return false to continue with the SDK default behavior.
default boolean onQuickReplyClick(Context context) {
return false;
}