This commit is contained in:
Adam Hammer 2022-12-23 13:28:52 -08:00 коммит произвёл GitHub
Родитель d981e47e43
Коммит 63ce7ff362
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
21 изменённых файлов: 125 добавлений и 199 удалений

Просмотреть файл

@ -7,8 +7,8 @@ import com.azure.android.communication.ui.calling.CallComposite;
import com.azure.android.communication.ui.calling.CallCompositeBuilder;
import com.azure.android.communication.ui.callwithchat.models.CallWithChatCompositeLocalizationOptions;
import com.azure.android.communication.ui.callwithchat.service.CallWithChatService;
import com.azure.android.communication.ui.chat.ChatUIClient;
import com.azure.android.communication.ui.chat.ChatUIClientBuilder;
import com.azure.android.communication.ui.chat.ChatAdapter;
import com.azure.android.communication.ui.chat.ChatAdapterBuilder;
public final class CallWithChatCompositeBuilder {
@ -46,15 +46,12 @@ public final class CallWithChatCompositeBuilder {
* @return {@link CallWithChatComposite}
*/
public CallWithChatComposite build() {
final ChatUIClientBuilder chatUIClientBuilder = new ChatUIClientBuilder();
final ChatUIClient chatUIClient = chatUIClientBuilder.build();
final ChatAdapter chatAdapter = new ChatAdapterBuilder().build();
final CallCompositeBuilder callCompositeBuilder = new CallCompositeBuilder();
final CallComposite callComposite = callCompositeBuilder
.build();
return new CallWithChatComposite(new CallWithChatService(callComposite, chatUIClient));
return new CallWithChatComposite(new CallWithChatService(callComposite, chatAdapter));
}
}

Просмотреть файл

@ -14,12 +14,12 @@ import com.azure.android.communication.ui.callwithchat.models.CallWithChatCompos
import com.azure.android.communication.ui.callwithchat.models.CallWithChatCompositeLocalOptions
import com.azure.android.communication.ui.callwithchat.models.CallWithChatCompositeRemoteOptions
import com.azure.android.communication.ui.callwithchat.models.CallWithChatCompositeTeamsMeetingLinkLocator
import com.azure.android.communication.ui.chat.ChatUIClient
import com.azure.android.communication.ui.chat.ChatAdapter
import com.azure.android.communication.ui.chat.implementation.ChatServiceConfigurationImpl
internal class CallWithChatService(
private val callComposite: CallComposite,
private val chatUIClient: ChatUIClient,
private val chatAdapter: ChatAdapter,
) {
fun launch(
context: Context,

Просмотреть файл

@ -16,13 +16,13 @@ internal fun launchChatComposite() {
val communicationTokenRefreshOptions = CommunicationTokenRefreshOptions({ "token" }, true)
val communicationTokenCredential =
CommunicationTokenCredential(communicationTokenRefreshOptions)
val chatUIClient = ChatUIClientBuilder()
.context(appContext)
val chatAdapter = ChatAdapterBuilder()
.endpoint("https://acs-ui-dev.communication.azure.com/")
.credential(communicationTokenCredential)
.identity(CommunicationUserIdentifier("test"))
.threadId("19:lSNju7o5X9EYJInIIxkJQw1TMnllGMytNCtvhYCxvpE1@thread.v2")
.build()
val chatThreadAdapter = ChatThreadAdapter(chatUIClient, "19:lSNju7o5X9EYJInIIxkJQw1TMnllGMytNCtvhYCxvpE1@thread.v2")
chatThreadAdapter.launchTest(appContext,)
chatAdapter.connect(appContext)
chatAdapter.showTestCompositeUI(appContext)
}

Просмотреть файл

@ -4,42 +4,50 @@
package com.azure.android.communication.ui.chat;
import android.content.Context;
import android.content.Intent;
import com.azure.android.communication.common.CommunicationIdentifier;
import com.azure.android.communication.common.CommunicationTokenCredential;
import com.azure.android.communication.ui.chat.configuration.ChatCompositeConfiguration;
import com.azure.android.communication.ui.chat.models.ChatCompositeErrorEvent;
import com.azure.android.communication.ui.chat.models.ChatCompositeRemoteOptions;
import com.azure.android.communication.ui.chat.presentation.ChatCompositeActivityImpl;
import java9.util.concurrent.CompletableFuture;
/**
* Azure android communication chat composite component.
*
* <p><strong>Instantiating Chat Composite</strong></p>
*/
public final class ChatUIClient {
public final class ChatAdapter {
private static int instanceIdCounter = 0;
final Integer instanceId = instanceIdCounter++;
private final Context applicationContext;
private ChatContainer chatContainer;
private final String endpoint;
private final CommunicationIdentifier identity;
private final CommunicationTokenCredential credential;
private final String threadId;
private final String displayName;
private final ChatCompositeConfiguration configuration;
ChatUIClient(final Context applicationContext,
final ChatCompositeConfiguration configuration,
final String endpoint,
final CommunicationIdentifier identity,
final CommunicationTokenCredential credential,
final String displayName) {
this.applicationContext = applicationContext;
ChatAdapter(final ChatCompositeConfiguration configuration,
final String endpoint,
final CommunicationIdentifier identity,
final CommunicationTokenCredential credential,
final String threadId,
final String displayName) {
this.endpoint = endpoint;
this.identity = identity;
this.credential = credential;
this.threadId = threadId;
this.displayName = displayName;
this.configuration = configuration;
}
/**
* Add {@link ChatCompositeEventHandler}.
*
@ -74,27 +82,37 @@ public final class ChatUIClient {
configuration.getEventHandlerRepository().removeOnErrorEventHandler(errorHandler);
}
String getEndpoint() {
return endpoint;
/**
* Connects to ACS service, starts realtime notifications.
*/
public CompletableFuture<Void> connect(final Context context) {
chatContainer = new ChatContainer(this, configuration, instanceId);
launchComposite(context, threadId);
final CompletableFuture<Void> result = new CompletableFuture<>();
result.complete(null);
return result;
}
CommunicationIdentifier getIdentity() {
return identity;
/**
* Disconnects from backend services.
*/
public void disconnect() {
chatContainer.stop();
chatContainer = null;
}
CommunicationTokenCredential getCredential() {
return credential;
private void launchComposite(final Context context, final String threadId) {
final ChatCompositeRemoteOptions remoteOptions =
new ChatCompositeRemoteOptions(
endpoint, threadId, credential, identity, displayName != null ? displayName : "");
chatContainer.start(context, remoteOptions);
}
String getDisplayName() {
return displayName;
}
ChatCompositeConfiguration getConfiguration() {
return configuration;
}
Context getApplicationContextContext() {
return applicationContext;
void showTestCompositeUI(final Context context) {
final Intent intent = new Intent(context, ChatCompositeActivityImpl.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ChatCompositeActivityImpl.Companion.setChatAdapter(this);
context.startActivity(intent);
}
}

Просмотреть файл

@ -3,32 +3,31 @@
package com.azure.android.communication.ui.chat;
import android.content.Context;
import com.azure.android.communication.common.CommunicationIdentifier;
import com.azure.android.communication.common.CommunicationTokenCredential;
import com.azure.android.communication.ui.chat.configuration.ChatCompositeConfiguration;
/**
* Builder for creating {@link ChatUIClient}.
* Builder for creating {@link ChatAdapter}.
*
* <p>Used to build a {@link ChatUIClient} which is then used to start a chat.</p>
* <p>Used to build a {@link ChatAdapter} which is then used to start a chat.</p>
* <p>This class can be used to specify a locale to be used by the Chat Composite</p>
*/
public final class ChatUIClientBuilder {
public final class ChatAdapterBuilder {
private String endpoint;
private CommunicationIdentifier identity;
private CommunicationTokenCredential credential;
private String displayName;
private Context applicationContext;
private String threadId;
/**
* Sets Azure Communication Service endpoint.
* @param endpoint
* @return
*/
public ChatUIClientBuilder endpoint(final String endpoint) {
public ChatAdapterBuilder endpoint(final String endpoint) {
this.endpoint = endpoint;
return this;
}
@ -38,7 +37,7 @@ public final class ChatUIClientBuilder {
* @param identity
* @return
*/
public ChatUIClientBuilder identity(final CommunicationIdentifier identity) {
public ChatAdapterBuilder identity(final CommunicationIdentifier identity) {
this.identity = identity;
return this;
}
@ -48,7 +47,7 @@ public final class ChatUIClientBuilder {
* @param credential
* @return
*/
public ChatUIClientBuilder credential(final CommunicationTokenCredential credential) {
public ChatAdapterBuilder credential(final CommunicationTokenCredential credential) {
this.credential = credential;
return this;
}
@ -58,28 +57,28 @@ public final class ChatUIClientBuilder {
* @param displayName
* @return
*/
public ChatUIClientBuilder displayName(final String displayName) {
public ChatAdapterBuilder displayName(final String displayName) {
this.displayName = displayName;
return this;
}
/**
* Sets android context.
* @param context
* Sets chat thread Id
* @param threadId
* @return
*/
public ChatUIClientBuilder context(final Context context) {
this.applicationContext = context.getApplicationContext();
public ChatAdapterBuilder threadId(final String threadId) {
this.threadId = threadId;
return this;
}
/**
* Builds the {@link ChatUIClient} class.
* Builds the {@link ChatAdapter} class.
*
* @return {@link ChatUIClient}
* @return {@link ChatAdapter}
*/
public ChatUIClient build() {
public ChatAdapter build() {
final ChatCompositeConfiguration config = new ChatCompositeConfiguration();
return new ChatUIClient(applicationContext, config, endpoint, identity, credential, displayName);
return new ChatAdapter(config, endpoint, identity, credential, threadId, displayName);
}
}

Просмотреть файл

@ -7,7 +7,7 @@ package com.azure.android.communication.ui.chat;
* {@link ChatCompositeEventHandler}&lt;T&gt;
*
* <p>A generic handler for call composite events.</p>
* <p> - {@link ChatUIClient#addOnErrorEventHandler(ChatCompositeEventHandler)} for Error Handling</p>
* <p> - {@link ChatAdapter#addOnErrorEventHandler(ChatCompositeEventHandler)} for Error Handling</p>
* for Remote Participant Join Notifications</p>
*
* @param <T> The callback event Type.

Просмотреть файл

@ -3,6 +3,6 @@
package com.azure.android.communication.ui.chat
internal fun ChatUIClient.instanceIdAccessor(): Int {
internal fun ChatAdapter.instanceIdAccessor(): Int {
return instanceId
}

Просмотреть файл

@ -43,7 +43,7 @@ import com.azure.android.communication.ui.chat.utilities.announceForAccessibilit
import com.jakewharton.threetenabp.AndroidThreeTen
internal class ChatContainer(
private val chatUIClient: ChatUIClient,
private val chatAdapter: ChatAdapter,
private val configuration: ChatCompositeConfiguration,
private val instanceId: Int,
) {
@ -98,7 +98,7 @@ internal class ChatContainer(
val messageRepository = MessageRepository.createSkipListBackedRepository()
addTypedBuilder { chatUIClient }
addTypedBuilder { chatAdapter }
addTypedBuilder { messageRepository }

Просмотреть файл

@ -1,75 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.android.communication.ui.chat;
import android.content.Context;
import android.content.Intent;
import com.azure.android.communication.ui.chat.models.ChatCompositeRemoteOptions;
import com.azure.android.communication.ui.chat.presentation.ChatCompositeActivityImpl;
/**
* Azure android communication chat thread adapter.
*/
public class ChatThreadAdapter {
private final ChatUIClient chatUIClient;
private final String threadId;
private final String topic = null;
/**
* Creates {@link ChatThreadAdapter}
* @param chatUIClient
* @param threadId
*/
public ChatThreadAdapter(final ChatUIClient chatUIClient, final String threadId) {
this.chatUIClient = chatUIClient;
this.threadId = threadId;
String displayName = chatUIClient.getDisplayName();
if (displayName == null) {
displayName = "";
}
final ChatCompositeRemoteOptions remoteOptions = new ChatCompositeRemoteOptions(
chatUIClient.getEndpoint(),
threadId,
chatUIClient.getCredential(),
chatUIClient.getIdentity(),
displayName);
final ChatContainer chatContainer =
new ChatContainer(chatUIClient, chatUIClient.getConfiguration(), chatUIClient.instanceId);
chatContainer.start(chatUIClient.getApplicationContextContext(), remoteOptions);
}
/**
* Get chat thread Id.
* @return
*/
public String getThreadId() {
return threadId;
}
/**
* Get chat thread topic.
* @return
*/
public String getTopic() {
return topic;
}
ChatUIClient getChatUIClient() {
return chatUIClient;
}
void launchTest(final Context context) {
final Intent intent = new Intent(context, ChatCompositeActivityImpl.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ChatCompositeActivityImpl.Companion.setChatUIClient(chatUIClient);
context.startActivity(intent);
}
}

Просмотреть файл

@ -1,8 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.android.communication.ui.chat
internal fun ChatThreadAdapter.getChatUIClient(): ChatUIClient {
return this.chatUIClient
}

Просмотреть файл

@ -3,10 +3,10 @@
package com.azure.android.communication.ui.chat.models;
import com.azure.android.communication.ui.chat.ChatUIClient;
import com.azure.android.communication.ui.chat.ChatAdapter;
/**
* Chat locator to join chat experience using {@link ChatUIClient}.
* Chat locator to join chat experience using {@link ChatAdapter}.
*/
final class ChatCompositeJoinLocator {

Просмотреть файл

@ -3,8 +3,6 @@
package com.azure.android.communication.ui.chat.models;
import com.azure.android.communication.ui.chat.ChatUIClient;
/**
* ChatCompositeLocalOptions for ChatComposite.launch.
*
@ -28,7 +26,6 @@ import com.azure.android.communication.ui.chat.ChatUIClient;
* chatComposite.launch&#40;.., .., localOptions&#41
* </pre>
*
* @see ChatUIClient
*/
final class ChatCompositeLocalOptions {
private ChatCompositeParticipantViewData participantViewData;

Просмотреть файл

@ -4,14 +4,14 @@
package com.azure.android.communication.ui.chat.models;
import com.azure.android.communication.ui.chat.ChatUIClient;
import com.azure.android.communication.ui.chat.ChatAdapter;
import java.util.Locale;
/**
* Localization configuration to provide for {@link ChatUIClient}.
* Localization configuration to provide for {@link ChatAdapter}.
*
* @see ChatUIClient
* @see ChatAdapter
*/
final class ChatCompositeLocalizationOptions {
private final Locale locale;

Просмотреть файл

@ -6,7 +6,7 @@ package com.azure.android.communication.ui.chat.models;
import android.graphics.Bitmap;
import android.widget.ImageView;
import com.azure.android.communication.ui.chat.ChatUIClient;
import com.azure.android.communication.ui.chat.ChatAdapter;
/**
* ChatCompositeParticipantViewData for participant.
@ -37,7 +37,7 @@ final class ChatCompositeParticipantViewData {
/**
* Get scaleType.
* <p>
* Will not take affect if called after {@link ChatCompositeParticipantViewData} passed to {@link ChatUIClient}
* Will not take affect if called after {@link ChatCompositeParticipantViewData} passed to {@link ChatAdapter}
*
* @return The {@link ImageView.ScaleType};
*/
@ -48,7 +48,7 @@ final class ChatCompositeParticipantViewData {
/**
* Set scaleType.
* <p>
* Will not take affect if called after {@link ChatCompositeParticipantViewData} passed to {@link ChatUIClient}
* Will not take affect if called after {@link ChatCompositeParticipantViewData} passed to {@link ChatAdapter}
*
* @return The {@link ChatCompositeParticipantViewData};
*/
@ -88,7 +88,7 @@ final class ChatCompositeParticipantViewData {
/**
* Set avatar Bitmap.
* <p>
* Will not take affect if called after {@link ChatCompositeParticipantViewData} passed to {@link ChatUIClient}
* Will not take affect if called after {@link ChatCompositeParticipantViewData} passed to {@link ChatAdapter}
*
* @return The {@link ChatCompositeParticipantViewData};
*/

Просмотреть файл

@ -4,14 +4,14 @@
package com.azure.android.communication.ui.chat.models;
import com.azure.android.communication.common.CommunicationIdentifier;
import com.azure.android.communication.ui.chat.ChatUIClient;
import com.azure.android.communication.ui.chat.ChatAdapter;
import com.azure.android.core.util.ExpandableStringEnum;
import java.util.Collection;
/**
* Result values for
* {@link ChatUIClient#setRemoteParticipantViewData(CommunicationIdentifier, ChatCompositeParticipantViewData)}.
* {@link ChatAdapter#setRemoteParticipantViewData(CommunicationIdentifier, ChatCompositeParticipantViewData)}.
*/
final class ChatCompositeSetParticipantViewDataResult
extends ExpandableStringEnum<ChatCompositeSetParticipantViewDataResult> {

Просмотреть файл

@ -6,7 +6,7 @@ package com.azure.android.communication.ui.chat.presentation;
import android.content.Context;
import android.content.Intent;
import com.azure.android.communication.ui.chat.ChatUIClient;
import com.azure.android.communication.ui.chat.ChatAdapter;
class ChatCompositeActivity {
private final Context context;
@ -15,9 +15,9 @@ class ChatCompositeActivity {
this.context = context;
}
public void launch(final ChatUIClient chatUIClient) {
public void launch(final ChatAdapter chatAdapter) {
final Intent intent = new Intent(context, ChatCompositeActivityImpl.class);
ChatCompositeActivityImpl.Companion.setChatUIClient(chatUIClient);
ChatCompositeActivityImpl.Companion.setChatAdapter(chatAdapter);
context.startActivity(intent);
}
}

Просмотреть файл

@ -5,18 +5,18 @@ package com.azure.android.communication.ui.chat.presentation
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.azure.android.communication.ui.chat.ChatUIClient
import com.azure.android.communication.ui.chat.ChatAdapter
import com.azure.android.communication.ui.chat.presentation.ui.container.ChatCompositeViewImpl
internal class ChatCompositeActivityImpl : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(ChatCompositeViewImpl(this, chatUIClient!!, true))
setContentView(ChatCompositeViewImpl(this, chatAdapter!!, true))
actionBar?.hide()
supportActionBar?.hide()
}
companion object {
var chatUIClient: ChatUIClient? = null
var chatAdapter: ChatAdapter? = null
}
}

Просмотреть файл

@ -7,9 +7,7 @@ import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import com.azure.android.communication.ui.chat.ChatThreadAdapter;
import com.azure.android.communication.ui.chat.ChatThreadAdapterExtensionsKt;
import com.azure.android.communication.ui.chat.ChatUIClient;
import com.azure.android.communication.ui.chat.ChatAdapter;
import com.azure.android.communication.ui.chat.presentation.ui.container.ChatCompositeViewImpl;
/**
@ -28,11 +26,11 @@ public final class ChatThreadView extends FrameLayout {
/**
* Creates {@link ChatThreadView}
* @param context
* @param chatThreadAdapter
* @param chatAdapter
*/
public ChatThreadView(final Context context, final ChatThreadAdapter chatThreadAdapter) {
public ChatThreadView(final Context context, final ChatAdapter chatAdapter) {
super(context);
setChatAdapter(chatThreadAdapter);
setChatAdapter(chatAdapter);
}
/**
@ -48,15 +46,14 @@ public final class ChatThreadView extends FrameLayout {
* Creates {@link ChatThreadView}
* @param context
* @param attrs
* @param chatThreadAdapter
* @param chatAdapter
*/
public ChatThreadView(final Context context, final AttributeSet attrs, final ChatThreadAdapter chatThreadAdapter) {
public ChatThreadView(final Context context, final AttributeSet attrs, final ChatAdapter chatAdapter) {
super(context, attrs);
setChatAdapter(chatThreadAdapter);
setChatAdapter(chatAdapter);
}
void setChatAdapter(final ChatThreadAdapter chatThreadAdapter) {
final ChatUIClient chatUiClient = ChatThreadAdapterExtensionsKt.getChatUIClient(chatThreadAdapter);
addView(new ChatCompositeViewImpl(this.getContext(), chatUiClient, false));
void setChatAdapter(final ChatAdapter chatAdapter) {
addView(new ChatCompositeViewImpl(this.getContext(), chatAdapter, false));
}
}

Просмотреть файл

@ -8,7 +8,7 @@ import android.widget.FrameLayout
import androidx.compose.ui.platform.ComposeView
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.azure.android.communication.ui.chat.ChatUIClient
import com.azure.android.communication.ui.chat.ChatAdapter
import com.azure.android.communication.ui.chat.instanceIdAccessor
import com.azure.android.communication.ui.chat.locator.ServiceLocator
import com.azure.android.communication.ui.chat.models.ChatCompositeRemoteOptions
@ -28,11 +28,11 @@ import com.azure.android.communication.ui.chat.repository.MessageRepository
internal class ChatCompositeViewImpl(
context: Context,
private val chatUIClient: ChatUIClient,
private val chatAdapter: ChatAdapter,
private val showActionBar: Boolean = false,
) : FrameLayout(context) {
private val composeView = ComposeView(context)
private val locator get() = ServiceLocator.getInstance(chatUIClient.instanceIdAccessor())
private val locator get() = ServiceLocator.getInstance(chatAdapter.instanceIdAccessor())
private val dispatch: Dispatch by lazy { locator.locate() }
private lateinit var reduxViewModelGenerator: ReduxViewModelGenerator<ReduxState, ChatScreenViewModel>

Просмотреть файл

@ -12,16 +12,18 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.inputmethod.InputMethodManager
import android.webkit.URLUtil
import androidx.activity.addCallback
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.azure.android.communication.ui.callingcompositedemoapp.BuildConfig
import com.azure.android.communication.ui.callingcompositedemoapp.R
import com.azure.android.communication.ui.callingcompositedemoapp.databinding.ActivityChatLauncherBinding
import com.azure.android.communication.ui.chat.ChatUIClient
import com.azure.android.communication.ui.chat.ChatAdapter
import com.azure.android.communication.ui.chat.models.ChatCompositeErrorEvent
import com.azure.android.communication.ui.chat.presentation.ChatThreadView
import com.azure.android.communication.ui.chatdemoapp.features.AdditionalFeatures
@ -146,10 +148,10 @@ class ChatLauncherActivity : AppCompatActivity() {
}
private fun showChatUI() {
val chatThreadAdapter = chatLauncherViewModel.chatThreadAdapter!!
val chatAdapter = chatLauncherViewModel.chatAdapter!!
// Create Chat Composite View
chatView = ChatThreadView(this, chatThreadAdapter)
chatView = ChatThreadView(this, chatAdapter)
binding.setupScreen.visibility = View.GONE
addContentView(
@ -162,7 +164,7 @@ class ChatLauncherActivity : AppCompatActivity() {
}
private fun showChatUIActivity() {
val chatAdapter = chatLauncherViewModel.chatUIClient!!
val chatAdapter = chatLauncherViewModel.chatAdapter!!
val activityLauncherClass =
Class.forName("com.azure.android.communication.ui.chat.presentation.ChatCompositeActivity")
@ -170,7 +172,7 @@ class ChatLauncherActivity : AppCompatActivity() {
constructor.isAccessible = true
val instance = constructor.newInstance(this)
val launchMethod =
activityLauncherClass.getDeclaredMethod("launch", ChatUIClient::class.java)
activityLauncherClass.getDeclaredMethod("launch", ChatAdapter::class.java)
launchMethod.isAccessible = true
launchMethod.invoke(instance, chatAdapter)
}
@ -248,4 +250,10 @@ class ChatLauncherActivity : AppCompatActivity() {
showAlert("${errorEvent.errorCode} : ${errorEvent.cause}")
Log.e("ChatCompositeDemoApp", "====================================================================")
}
override fun onResume() {
super.onResume()
val window: Window = this@ChatLauncherActivity.window
window.navigationBarColor = ContextCompat.getColor(this@ChatLauncherActivity, R.color.white)
}
}

Просмотреть файл

@ -4,23 +4,20 @@
package com.azure.android.communication.ui.chatdemoapp
import android.content.Context
import android.webkit.URLUtil
import androidx.lifecycle.ViewModel
import com.azure.android.communication.common.CommunicationTokenCredential
import com.azure.android.communication.common.CommunicationTokenRefreshOptions
import com.azure.android.communication.common.CommunicationUserIdentifier
import com.azure.android.communication.ui.chat.ChatAdapter
import com.azure.android.communication.ui.chat.ChatAdapterBuilder
import com.azure.android.communication.ui.chat.ChatCompositeEventHandler
import com.azure.android.communication.ui.chat.ChatThreadAdapter
import com.azure.android.communication.ui.chat.ChatUIClient
import com.azure.android.communication.ui.chat.ChatUIClientBuilder
import com.azure.android.communication.ui.chat.models.ChatCompositeErrorEvent
import java.util.concurrent.Callable
class ChatLauncherViewModel : ViewModel() {
private var token: String? = null
var chatUIClient: ChatUIClient? = null
var chatThreadAdapter: ChatThreadAdapter? = null
var chatAdapter: ChatAdapter? = null
private fun getTokenFetcher(acsToken: String?): Callable<String> {
val tokenRefresher = when {
@ -51,26 +48,22 @@ class ChatLauncherViewModel : ViewModel() {
val communicationTokenCredential =
CommunicationTokenCredential(communicationTokenRefreshOptions)
val chatUIClient = ChatUIClientBuilder()
.context(context)
val chatAdapter = ChatAdapterBuilder()
.endpoint(endpoint)
.credential(communicationTokenCredential)
.identity(CommunicationUserIdentifier(acsIdentity))
.displayName(userName)
.threadId(threadId)
.build()
chatUIClient.addOnErrorEventHandler(errorHandler)
chatAdapter.addOnErrorEventHandler(errorHandler)
val chatThreadAdapter = ChatThreadAdapter(chatUIClient, threadId)
chatAdapter.connect(context)
this.chatUIClient = chatUIClient
this.chatThreadAdapter = chatThreadAdapter
this.chatAdapter = chatAdapter
}
private fun urlIsValid(url: String) = url.isNotBlank() && URLUtil.isValidUrl(url.trim())
fun closeChatComposite() {
chatUIClient = null
chatAdapter = null
}
}