Class NCChatUI

  • All Implemented Interfaces:

    
    public final class NCChatUI
    
                        

    NCChatUI — 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.

    
    // 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());
    
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static void initialize(InitParams params) Initializes the SDK.
      static Context getContext() Returns the Application context saved during initialization.
      static void connect(ConnectParams params, ConnectHandler handler) Connects to the server using a business token.
      static void disconnect() Disconnects from the server while keeping the push channel alive.
      static void logout() Disconnects from the server and closes the push channel.
      static BaseChannel createChannel(ChannelIdentifier identifier) Creates the appropriate BaseChannel subtype for the given ChannelIdentifier.
      static void addMessageEventListener(MessageEventListener listener) Registers a message event listener.
      static void removeMessageEventListener(MessageEventListener listener) Unregisters a previously registered message event listener.
      static List<MessageEventListener> getMessageEventListeners() Returns the list of registered message event listeners.
      static void refreshMessage(RefreshEvent event) Dispatches a message refresh event to all registered MessageEventListeners.
      static void sendMessage(ChannelIdentifier identifier, SendMessageParams params, SendMessageHandler handler) Sends a text/binary message and dispatches send-lifecycle events to all registered s.
      static void sendMediaMessage(ChannelIdentifier identifier, SendMediaMessageParams params, SendMediaMessageHandler handler) Sends a media message and dispatches send-lifecycle events to all registered s.
      static void cancelSendMediaMessage(Message message, ErrorHandler handler) Cancels an in-progress media message upload.
      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.
      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.
      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 void addChannelEventListener(ChannelEventListener listener) Registers a channel event listener.
      static void removeChannelEventListener(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 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.
      static void addCancelSendMediaMessageListener(Runnable listener) Registers a cancel-send-media listener.
      static void removeCancelSendMediaMessageListener(Runnable listener) Unregisters a cancel-send-media listener.
      static List<Runnable> getCancelSendMediaListeners() Returns the list of registered cancel-send-media listeners.
      static boolean isInitialized() Returns whether the SDK has been initialized.
      static ChatUIFragmentFactory getFragmentFactory() Returns the current ChatUIFragmentFactory.
      static void setFragmentFactory(ChatUIFragmentFactory factory) Replaces the current ChatUIFragmentFactory.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • 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 null if 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, reconnectKickEnable
        handler - 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 identifier
        params - send parameters
        handler - send result callback (may be null)
      • 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 identifier
        params - send media parameters
        handler - send result callback (may be null)
      • 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; null error means success (may be null)
      • 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 identifier
        messages - messages to delete
        handler - deletion result callback (may be null)
      • 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 identifier
        messages - messages to delete locally
        handler - deletion result callback (may be null)
      • 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 identifier
        message - message to recall
        handler - recall result callback (may be null)
      • 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 identifier
        items - messages to insert
        handler - insertion result callback (may be null)
      • 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 channel
        draft - draft content
        handler - operation result callback (may be null)
      • 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 channel
        timestamp - timestamp of the last read message's sent time
        handler - operation result callback (may be null)
      • addCancelSendMediaMessageListener

         static void addCancelSendMediaMessageListener(Runnable listener)

        Registers a cancel-send-media listener. Duplicate listeners are ignored.

      • 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:

        true if initialize has been called; false otherwise

      • 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