TUIKit_Android/├── atomic_x/ # Base UI component library (required by Chat)├── call/│ └── tuicallkit-kt/ # Audio/video call component (required by Chat)└── chat/├── demo/ # Chat View Demo project└── uikit/ # Chat View UI component library
chat, atomic_x, and optionally call folders from the repository root to your project root directory. The directory structure after copying is as follows:YourApplication/├── app/ # Your app module├── atomic_x/ # Base UI component library (required)├── call/ # Audio/video call component (optional)│ └── tuicallkit-kt/├── chat/ # Chat source code│ ├── demo/ # Demo project (for reference, optional)│ └── uikit/ # Chat UIKit component library (required)├── settings.gradle.kts└── build.gradle.kts
settings.gradle.kts. Adjust the relative paths based on where you actually place the source code:// settings.gradle.kts// Include the Chat UIKit component library (required)include(":uikit")project(":uikit").projectDir = file("${settingsDir.path}/chat/uikit")// Include the AtomicX base UI component library (required)include(":atomic_x")project(":atomic_x").projectDir = file("${settingsDir.path}/atomic_x")// Include the audio/video call component (optional, required for audio/video calls)include(":tuicallkit-kt")project(":tuicallkit-kt").projectDir = file("${settingsDir.path}/call/tuicallkit-kt")
// settings.gradle// Include the Chat UIKit component library (required)include ':uikit'project(':uikit').projectDir = new File(settingsDir, 'chat/uikit')// Include the AtomicX base UI component library (required)include ':atomic_x'project(':atomic_x').projectDir = new File(settingsDir, 'atomic_x')// Include the audio/video call component (optional, required for audio/video calls)include ':tuicallkit-kt'project(':tuicallkit-kt').projectDir = new File(settingsDir, 'call/tuicallkit-kt')
build.gradle.kts:// app/build.gradle.ktsdependencies {// TUIKit component library (required)implementation(project(":uikit"))implementation(project(":atomic_x"))// Audio/video call (optional)implementation(project(":tuicallkit-kt"))}
// app/build.gradledependencies {// TUIKit component library (required)implementation project(':uikit')implementation project(':atomic_x')// Audio/video call (optional)implementation project(':tuicallkit-kt')}

login API of LoginStore and pass in the sdkAppID, userID, and userSig obtained above for login authentication:import io.trtc.tuikit.atomicxcore.api.CompletionHandlerimport io.trtc.tuikit.atomicxcore.api.login.LoginStoreLoginStore.shared.login(context,sdkAppID, // Int, obtained from the ConsoleuserID, // StringuserSig, // String, generated in the Console or on your serverobject : CompletionHandler {override fun onSuccess() {// Login succeeded. You can navigate to the conversation list or chat page.}override fun onFailure(code: Int, desc: String) {// Login failed. You can show an error dialog.}})
ConversationsPageView and add it to your layout. It automatically reads recent conversations from local storage. When a conversation is tapped, the onConversationClick callback returns the conversation's conversationID, which you can use to navigate to the chat UI.import android.os.Bundleimport androidx.appcompat.app.AppCompatActivityimport io.trtc.tuikit.chat.uikit.pages.ConversationsPageViewclass ConversationActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)val conversationsPage = ConversationsPageView(this)conversationsPage.setHeaderTitle("Messages")// Conversation tap callback. conversationID already includes the c2c_ or group_ prefix.conversationsPage.onConversationClick = { conversationID ->// Navigate to your chat UI and pass in conversationID. See ChatActivity in Step 4.}// Optional callbacks for search, starting one-to-one chats, and creating groups.conversationsPage.onSearchClick = { /* Navigate to the search page */ }conversationsPage.onStartChatClick = { /* Start a one-to-one chat */ }conversationsPage.onCreateGroupClick = { /* Create a group */ }// Set the conversation list as the page content.setContentView(conversationsPage)}}
ChatPageView to display and send or receive messages. Pass conversationID through setup. The conversationID format is c2c_<peer UserID> for one-to-one chats and group_<GroupID> for group chats.import android.content.Contextimport android.content.Intentimport android.os.Bundleimport androidx.appcompat.app.AppCompatActivityimport io.trtc.tuikit.chat.uikit.pages.ChatPageViewclass ChatActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {// Material Components theme is required, otherwise ChatPageView may crash at runtime.setTheme(com.google.android.material.R.style.Theme_MaterialComponents_Light_NoActionBar)super.onCreate(savedInstanceState)// conversationID format: "c2c_<peer UserID>" for one-to-one chats, "group_<GroupID>" for group chats.val conversationID = intent.getStringExtra("conversationID") ?: returnval chatPageView = ChatPageView(this)chatPageView.setup(conversationID = conversationID)setContentView(chatPageView)}companion object {fun start(context: Context, conversationID: String) {context.startActivity(Intent(context, ChatActivity::class.java).apply {putExtra("conversationID", conversationID)})}}}
setTheme(com.google.android.material.R.style.Theme_MaterialComponents_Light_NoActionBar). Otherwise, Material controls used inside ChatPageView may crash at runtime because required theme attributes are missing.ChatActivity, a chat page encapsulated based on ChatPageView with a title bar, unread badges, group event handling, and more. You can reuse it directly or refer to its implementation for customization: ChatActivity.start(context, conversationID).ContactsPageView to display friend lists, group lists, and more. Set click callbacks through setup. When a contact or group is tapped, navigate to the corresponding chat UI.import android.os.Bundleimport androidx.appcompat.app.AppCompatActivityimport io.trtc.tuikit.chat.uikit.pages.ContactsPageViewclass ContactActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)val contactsPage = ContactsPageView(this)contactsPage.setHeaderTitle("Contacts")contactsPage.setup(onContactClick = { contactInfo ->// Navigate to your chat UI. The one-to-one conversation ID is "c2c_" + contactInfo.userID.},onGroupClick = { contactInfo ->// Navigate to your chat UI. The group conversation ID is "group_" + contactInfo.userID.})setContentView(contactsPage)}}
ThemeStore to support primary color settings and light/dark theme switching.import io.trtc.tuikit.atomicx.theme.Themeimport io.trtc.tuikit.atomicx.theme.ThemeStore// Set primary color.ThemeStore.shared(context).setPrimaryColor("#1C66E5")// Switch between light and dark themes.ThemeStore.shared(context).setTheme(Theme.lightTheme(context))// ThemeStore.shared(context).setTheme(Theme.darkTheme(context))

피드백