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
    • Constructor Detail

    • 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.
      • getContext

        @Nullable() static Context getContext()

        Returns the Application context saved during initialization.

        Returns:

        the ApplicationContext, or null if initialize has not been called

      • getVersion

        @NonNull() static String getVersion()

        Returns the ChatUI SDK version.

        The value comes from UNIVERSAL_NEXCONN_VERSION and 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, 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

        @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
      • 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 identifier
        params - send parameters
        handler - send result callback (may be null)
      • 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 identifier
        params - send media parameters
        handler - send result callback (may be null)
      • 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; null error means success (may be null)
      • 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 identifier
        messages - messages to delete
        handler - deletion result callback (may be null)
      • 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 identifier
        messages - messages to delete locally
        handler - deletion result callback (may be null)
      • 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 identifier
        message - message to recall
        handler - recall result callback (may be null)
      • 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 identifier
        items - messages to insert
        handler - insertion result callback (may be null)
      • 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 channel
        draft - draft content
        handler - operation result callback (may be null)
      • syncConversationReadStatus

         static void syncConversationReadStatus(@NonNull() ChannelIdentifier channelIdentifier, long timestamp, @Nullable() 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)
      • isInitialized

         static boolean isInitialized()

        Returns whether the SDK has been initialized.

        Returns:

        true if initialize has been called; false otherwise