Class NCChatUI
-
- All Implemented Interfaces:
public final class NCChatUINCChatUI — the main entry point for the ChatUI SDK.
Wraps nexconn-chat initialization and connection, provides a ChatUIFragmentFactory for all UI screens, and exposes an internal event bus for message and channel events.
- Call initialize once in onCreate.
- Call connect after a successful user login.
- Use getFragmentFactory (or setFragmentFactory) to launch any screen.
// 1. Initialize in Application.onCreate NCChatUI.initialize(new InitParams(context, "your-app-key")); // 2. Connect after login NCChatUI.connect(new ConnectParams("user-token"), (userId, error) -> { if (error == null) { // connected } }); // 3. Replace any screen with a custom Fragment NCChatUI.setFragmentFactory(new MyCustomFragmentFactory());
-
-
Method Summary
Modifier and Type Method Description static voidinitialize(@NonNull() InitParams params)Initializes the SDK. static voidensureContext(@NonNull() Context context)Stores an application context for built-in Chat UI pages when the host app initialized only the lower Chat SDK entry point. static ContextgetContext()Returns the Application context saved during initialization. static StringgetVersion()Returns the ChatUI SDK version. static voidconnect(@NonNull() ConnectParams params, @Nullable() ConnectHandler handler)Connects to the server using a business token. static voiddisconnect()Disconnects from the server while keeping the push channel alive. static voidlogout()Disconnects from the server and closes the push channel. static voidsetEnableSendCombineMessage(boolean enable)Sets whether combined message forwarding is enabled. static booleanisEnableSendCombineMessage()Returns whether combined message forwarding is enabled. static BaseChannelcreateChannel(@NonNull() ChannelIdentifier identifier)Creates the appropriate BaseChannel subtype for the given ChannelIdentifier. static voidremoveMessageFromUI(@NonNull() Message message)Removes a message from the UI by posting a DeleteEvent. static voidaddMessageEventListener(@NonNull() MessageEventListener listener)Registers a message event listener. static voidremoveMessageEventListener(@NonNull() MessageEventListener listener)Unregisters a previously registered message event listener. static List<MessageEventListener>getMessageEventListeners()Returns the list of registered message event listeners. static voidrefreshMessage(@NonNull() RefreshEvent event)Dispatches a message refresh event to all registered MessageEventListeners. static voidnotifyChannelMessagesCleared(@NonNull() ChannelIdentifier identifier)Notifies all registered MessageEventListeners that all messages in the given channel have been cleared locally (e.g. static voidsendMessage(@NonNull() ChannelIdentifier identifier, @NonNull() SendMessageParams params, @Nullable() SendMessageHandler handler)Sends a text/binary message and dispatches send-lifecycle events to all registered s. static voidsendMediaMessage(@NonNull() ChannelIdentifier identifier, @NonNull() SendMediaMessageParams params, @Nullable() SendMediaMessageHandler handler)Sends a media message and dispatches send-lifecycle events to all registered s. static voidcancelSendMediaMessage(@NonNull() Message message, @Nullable() ErrorHandler handler)Cancels an in-progress media message upload. static voiddeleteMessages(@NonNull() ChannelIdentifier identifier, @NonNull() List<Message> messages, @Nullable() ErrorHandler handler)Deletes messages for the current user (local + server-side for self) and dispatches a to all registered MessageEventListeners. static voiddeleteLocalMessages(@NonNull() ChannelIdentifier identifier, @NonNull() List<Message> messages, @Nullable() ErrorHandler handler)Deletes messages from the local database only, then dispatches a DeleteEvent so that the message list refreshes immediately. static voiddeleteMessageForAll(@NonNull() ChannelIdentifier identifier, @NonNull() Message message, @Nullable() OperationHandler<Message> handler)Recalls (deletes for all participants) a message and dispatches a DeleteEvent to all registered MessageEventListeners. static voidinsertMessages(@NonNull() ChannelIdentifier identifier, @NonNull() List<InsertMessageItem> items, @Nullable() OperationHandler<Boolean> handler)Inserts messages and dispatches an InsertEvent to all registered s. static voidaddChannelEventListener(@NonNull() ChannelEventListener listener)Registers a channel event listener. static voidremoveChannelEventListener(@NonNull() ChannelEventListener listener)Unregisters a previously registered channel event listener. static voidsaveDraft(@NonNull() ChannelIdentifier channelIdentifier, @NonNull() String draft, @Nullable() OperationHandler<Boolean> handler)Saves a draft for the given channel and notifies all registered ChannelEventListeners via onSaveDraft on success. static voidclearUnreadCount(@NonNull() ChannelIdentifier channelIdentifier, @Nullable() OperationHandler<Boolean> handler)Clears unread count for a channel and notifies all registered ChannelEventListeners via onClearedUnreadStatus on success. static voidaddCancelSendMediaMessageListener(@NonNull() Runnable listener)Registers a cancel-send-media listener. static voidremoveCancelSendMediaMessageListener(@NonNull() Runnable listener)Unregisters a cancel-send-media listener. static List<Runnable>getCancelSendMediaListeners()Returns the list of registered cancel-send-media listeners. static booleanisInitialized()Returns whether the SDK has been initialized. static ChatUIFragmentFactorygetFragmentFactory()Returns the current ChatUIFragmentFactory. static voidsetFragmentFactory(@NonNull() ChatUIFragmentFactory factory)Replaces the current ChatUIFragmentFactory. -
-
Method Detail
-
initialize
static void initialize(@NonNull() InitParams params)
Initializes the SDK. Must be called once in onCreate.
- Parameters:
params- initialization parameters — required: context and appKey; optional: naviServer, areaCode, logLevel, etc.
-
ensureContext
static void ensureContext(@NonNull() Context context)
Stores an application context for built-in Chat UI pages when the host app initialized only the lower Chat SDK entry point.
This is only a crash guard for page startup and does not replace initialize.
-
getContext
@Nullable() static Context getContext()
Returns the Application context saved during initialization.
- Returns:
the ApplicationContext, or
nullif initialize has not been called
-
getVersion
@NonNull() static String getVersion()
Returns the ChatUI SDK version.
The value comes from
UNIVERSAL_NEXCONN_VERSIONand is injected into VERSION_NAME at build time.
-
connect
static void connect(@NonNull() ConnectParams params, @Nullable() ConnectHandler handler)
Connects to the server using a business token.
Must be called after initialize.
- Parameters:
params- connection parameters — required: token; optional: timeout, reconnectKickEnablehandler- connection result callback; delivers userId on success or an error on failure
-
disconnect
static void disconnect()
Disconnects from the server while keeping the push channel alive.
Call this when the user logs out but still wants to receive push notifications. Use logout to also close the push channel.
-
logout
static void logout()
Disconnects from the server and closes the push channel.
-
setEnableSendCombineMessage
static void setEnableSendCombineMessage(boolean enable)
Sets whether combined message forwarding is enabled.
Default is
false. When enabled, messages can be forwarded as combined messages. Currently supported only in direct and group channels.- Parameters:
enable-trueto show the combined forwarding option
-
isEnableSendCombineMessage
static boolean isEnableSendCombineMessage()
Returns whether combined message forwarding is enabled.
- Returns:
trueif combined forwarding is enabled
-
createChannel
@NonNull() static BaseChannel createChannel(@NonNull() ChannelIdentifier identifier)
Creates the appropriate BaseChannel subtype for the given ChannelIdentifier.
- Parameters:
identifier- the channel identifier- Returns:
a typed BaseChannel instance
-
removeMessageFromUI
static void removeMessageFromUI(@NonNull() Message message)
Removes a message from the UI by posting a DeleteEvent. This is used internally when a message needs to be removed from the UI, such as when a resent message creates a new message object.
- Parameters:
message- the message to remove from UI
-
addMessageEventListener
static void addMessageEventListener(@NonNull() MessageEventListener listener)
Registers a message event listener. Duplicate listeners are ignored.
-
removeMessageEventListener
static void removeMessageEventListener(@NonNull() MessageEventListener listener)
Unregisters a previously registered message event listener.
-
getMessageEventListeners
static List<MessageEventListener> getMessageEventListeners()
Returns the list of registered message event listeners.
-
refreshMessage
static void refreshMessage(@NonNull() RefreshEvent event)
Dispatches a message refresh event to all registered MessageEventListeners.
- Parameters:
event- the refresh event to dispatch
-
notifyChannelMessagesCleared
static void notifyChannelMessagesCleared(@NonNull() ChannelIdentifier identifier)
Notifies all registered MessageEventListeners that all messages in the given channel have been cleared locally (e.g. via
deleteMessagesForMeByTimestamp). Any open chat page bound to that channel will drop its cached messages and reload the list so the UI reflects the cleared state immediately instead of waiting for the next fresh entry.- Parameters:
identifier- target channel whose messages have been cleared
-
sendMessage
static void sendMessage(@NonNull() ChannelIdentifier identifier, @NonNull() SendMessageParams params, @Nullable() SendMessageHandler handler)
Sends a text/binary message and dispatches send-lifecycle events to all registered s.
- Parameters:
identifier- target channel identifierparams- send parametershandler- send result callback (may benull)
-
sendMediaMessage
static void sendMediaMessage(@NonNull() ChannelIdentifier identifier, @NonNull() SendMediaMessageParams params, @Nullable() SendMediaMessageHandler handler)
Sends a media message and dispatches send-lifecycle events to all registered s.
- Parameters:
identifier- target channel identifierparams- send media parametershandler- send result callback (may benull)
-
cancelSendMediaMessage
static void cancelSendMediaMessage(@NonNull() Message message, @Nullable() ErrorHandler handler)
Cancels an in-progress media message upload.
On success, all listeners registered via addCancelSendMediaMessageListener are notified so the UI can update the progress indicator.
- Parameters:
message- the message to cancel (must be an object returned by sendMediaMessage)handler- cancellation result callback;nullerror means success (may benull)
-
deleteMessages
static void deleteMessages(@NonNull() ChannelIdentifier identifier, @NonNull() List<Message> messages, @Nullable() ErrorHandler handler)
Deletes messages for the current user (local + server-side for self) and dispatches a to all registered MessageEventListeners.
- Parameters:
identifier- target channel identifiermessages- messages to deletehandler- deletion result callback (may benull)
-
deleteLocalMessages
static void deleteLocalMessages(@NonNull() ChannelIdentifier identifier, @NonNull() List<Message> messages, @Nullable() ErrorHandler handler)
Deletes messages from the local database only, then dispatches a DeleteEvent so that the message list refreshes immediately.
- Parameters:
identifier- target channel identifiermessages- messages to delete locallyhandler- deletion result callback (may benull)
-
deleteMessageForAll
static void deleteMessageForAll(@NonNull() ChannelIdentifier identifier, @NonNull() Message message, @Nullable() OperationHandler<Message> handler)
Recalls (deletes for all participants) a message and dispatches a DeleteEvent to all registered MessageEventListeners.
- Parameters:
identifier- target channel identifiermessage- message to recallhandler- recall result callback (may benull)
-
insertMessages
static void insertMessages(@NonNull() ChannelIdentifier identifier, @NonNull() List<InsertMessageItem> items, @Nullable() OperationHandler<Boolean> handler)
Inserts messages and dispatches an InsertEvent to all registered s.
- Parameters:
identifier- target channel identifieritems- messages to inserthandler- insertion result callback (may benull)
-
addChannelEventListener
static void addChannelEventListener(@NonNull() ChannelEventListener listener)
Registers a channel event listener. Duplicate listeners are ignored.
-
removeChannelEventListener
static void removeChannelEventListener(@NonNull() ChannelEventListener listener)
Unregisters a previously registered channel event listener.
-
saveDraft
static void saveDraft(@NonNull() ChannelIdentifier channelIdentifier, @NonNull() String draft, @Nullable() OperationHandler<Boolean> handler)
Saves a draft for the given channel and notifies all registered ChannelEventListeners via onSaveDraft on success.
- Parameters:
channelIdentifier- target channeldraft- draft contenthandler- operation result callback (may benull)
-
clearUnreadCount
static void clearUnreadCount(@NonNull() ChannelIdentifier channelIdentifier, @Nullable() OperationHandler<Boolean> handler)
Clears unread count for a channel and notifies all registered ChannelEventListeners via onClearedUnreadStatus on success.
- Parameters:
channelIdentifier- target channelhandler- operation result callback (may benull)
-
addCancelSendMediaMessageListener
static void addCancelSendMediaMessageListener(@NonNull() Runnable listener)
Registers a cancel-send-media listener. Duplicate listeners are ignored.
-
removeCancelSendMediaMessageListener
static void removeCancelSendMediaMessageListener(@NonNull() Runnable listener)
Unregisters a cancel-send-media listener.
-
getCancelSendMediaListeners
static List<Runnable> getCancelSendMediaListeners()
Returns the list of registered cancel-send-media listeners.
-
isInitialized
static boolean isInitialized()
Returns whether the SDK has been initialized.
- Returns:
trueif initialize has been called;falseotherwise
-
getFragmentFactory
@NonNull() static ChatUIFragmentFactory getFragmentFactory()
Returns the current ChatUIFragmentFactory.
Subclass ChatUIFragmentFactory and override any
newXxxFragment()method to replace the default screen implementation.
-
setFragmentFactory
static void setFragmentFactory(@NonNull() ChatUIFragmentFactory factory)
Replaces the current ChatUIFragmentFactory.
- Parameters:
factory- a custom factory extending ChatUIFragmentFactory
-
-
-
-