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(InitParams params)Initializes the SDK. static ContextgetContext()Returns the Application context saved during initialization. static voidconnect(ConnectParams params, 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 BaseChannelcreateChannel(ChannelIdentifier identifier)Creates the appropriate BaseChannel subtype for the given ChannelIdentifier. static voidaddMessageEventListener(MessageEventListener listener)Registers a message event listener. static voidremoveMessageEventListener(MessageEventListener listener)Unregisters a previously registered message event listener. static List<MessageEventListener>getMessageEventListeners()Returns the list of registered message event listeners. static voidrefreshMessage(RefreshEvent event)Dispatches a message refresh event to all registered MessageEventListeners. static voidsendMessage(ChannelIdentifier identifier, SendMessageParams params, SendMessageHandler handler)Sends a text/binary message and dispatches send-lifecycle events to all registered s. static voidsendMediaMessage(ChannelIdentifier identifier, SendMediaMessageParams params, SendMediaMessageHandler handler)Sends a media message and dispatches send-lifecycle events to all registered s. static voidcancelSendMediaMessage(Message message, ErrorHandler handler)Cancels an in-progress media message upload. static voiddeleteMessages(ChannelIdentifier identifier, List<Message> messages, ErrorHandler handler)Deletes messages for the current user (local + server-side for self) and dispatches a to all registered MessageEventListeners. static voiddeleteLocalMessages(ChannelIdentifier identifier, List<Message> messages, ErrorHandler handler)Deletes messages from the local database only, then dispatches a DeleteEvent so that the message list refreshes immediately. static void)>deleteMessageForAll(ChannelIdentifier identifier, Message message, OperationHandler<Message> handler)Recalls (deletes for all participants) a message and dispatches a DeleteEvent to all registered MessageEventListeners. static void)>insertMessages(ChannelIdentifier identifier, List<InsertMessageItem> items, OperationHandler<Boolean> handler)Inserts messages and dispatches an InsertEvent to all registered s. static voidaddChannelEventListener(ChannelEventListener listener)Registers a channel event listener. static voidremoveChannelEventListener(ChannelEventListener listener)Unregisters a previously registered channel event listener. static void)>saveDraft(ChannelIdentifier channelIdentifier, String draft, OperationHandler<Boolean> handler)Saves a draft for the given channel and notifies all registered ChannelEventListeners via onSaveDraft on success. static voidsyncConversationReadStatus(ChannelIdentifier channelIdentifier, long timestamp, ErrorHandler handler)Syncs the read status of a channel to the server and notifies all registered s via onClearedUnreadStatus on success. static voidaddCancelSendMediaMessageListener(Runnable listener)Registers a cancel-send-media listener. static voidremoveCancelSendMediaMessageListener(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(ChatUIFragmentFactory factory)Replaces the current ChatUIFragmentFactory. -
-
Method Detail
-
initialize
static void initialize(InitParams params)
Initializes the SDK. Must be called once in onCreate.
- Parameters:
params- initialization parameters — required: context and appKey; optional: naviServer, areaCode, logLevel, etc.
-
getContext
static Context getContext()
Returns the Application context saved during initialization.
- Returns:
the ApplicationContext, or
nullif initialize has not been called
-
connect
static void connect(ConnectParams params, 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.
-
createChannel
static BaseChannel createChannel(ChannelIdentifier identifier)
Creates the appropriate BaseChannel subtype for the given ChannelIdentifier.
- Parameters:
identifier- the channel identifier- Returns:
a typed BaseChannel instance
-
addMessageEventListener
static void addMessageEventListener(MessageEventListener listener)
Registers a message event listener. Duplicate listeners are ignored.
-
removeMessageEventListener
static void removeMessageEventListener(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(RefreshEvent event)
Dispatches a message refresh event to all registered MessageEventListeners.
- Parameters:
event- the refresh event to dispatch
-
sendMessage
static void sendMessage(ChannelIdentifier identifier, SendMessageParams params, 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(ChannelIdentifier identifier, SendMediaMessageParams params, 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(Message message, 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(ChannelIdentifier identifier, List<Message> messages, 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(ChannelIdentifier identifier, List<Message> messages, 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(ChannelIdentifier identifier, Message message, 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(ChannelIdentifier identifier, List<InsertMessageItem> items, 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(ChannelEventListener listener)
Registers a channel event listener. Duplicate listeners are ignored.
-
removeChannelEventListener
static void removeChannelEventListener(ChannelEventListener listener)
Unregisters a previously registered channel event listener.
-
saveDraft
static void )>saveDraft(ChannelIdentifier channelIdentifier, String draft, 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)
-
syncConversationReadStatus
static void syncConversationReadStatus(ChannelIdentifier channelIdentifier, long timestamp, ErrorHandler handler)
Syncs the read status of a channel to the server and notifies all registered s via onClearedUnreadStatus on success.
- Parameters:
channelIdentifier- target channeltimestamp- timestamp of the last read message's sent timehandler- operation result callback (may benull)
-
addCancelSendMediaMessageListener
static void addCancelSendMediaMessageListener(Runnable listener)
Registers a cancel-send-media listener. Duplicate listeners are ignored.
-
removeCancelSendMediaMessageListener
static void removeCancelSendMediaMessageListener(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
static ChatUIFragmentFactory getFragmentFactory()
Returns the current ChatUIFragmentFactory.
Subclass ChatUIFragmentFactory and override any
newXxxFragment()method to replace the default screen implementation.
-
setFragmentFactory
static void setFragmentFactory(ChatUIFragmentFactory factory)
Replaces the current ChatUIFragmentFactory.
- Parameters:
factory- a custom factory extending ChatUIFragmentFactory
-
-
-
-