diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/ChatAdapter.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/ChatAdapter.kt index d75f0871f..13e3f49ea 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/ChatAdapter.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/ChatAdapter.kt @@ -37,6 +37,7 @@ import com.glia.widgets.chat.model.OperatorStatusItem import com.glia.widgets.chat.model.SystemChatItem import com.glia.widgets.chat.model.VisitorAttachmentItem import com.glia.widgets.chat.model.VisitorMessageItem +import com.glia.widgets.databinding.ChatAttachmentOperatorFileLayoutBinding import com.glia.widgets.databinding.ChatAttachmentOperatorImageLayoutBinding import com.glia.widgets.databinding.ChatAttachmentVisitorFileLayoutBinding import com.glia.widgets.databinding.ChatAttachmentVisitorImageLayoutBinding @@ -125,11 +126,7 @@ internal class ChatAdapter( OPERATOR_FILE_VIEW_TYPE -> { OperatorFileAttachmentViewHolder( - inflater.inflate( - R.layout.chat_attachment_operator_file_layout, - parent, - false - ), + ChatAttachmentOperatorFileLayoutBinding.inflate(inflater, parent, false), uiTheme ) } diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/holder/fileattachment/OperatorFileAttachmentViewHolder.java b/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/holder/fileattachment/OperatorFileAttachmentViewHolder.java deleted file mode 100644 index 87d49fcb7..000000000 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/holder/fileattachment/OperatorFileAttachmentViewHolder.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.glia.widgets.chat.adapter.holder.fileattachment; - -import android.text.format.Formatter; -import android.view.View; - -import androidx.annotation.NonNull; -import androidx.core.view.AccessibilityDelegateCompat; -import androidx.core.view.ViewCompat; -import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; - -import com.glia.widgets.R; -import com.glia.widgets.StringKey; -import com.glia.widgets.StringKeyPair; -import com.glia.widgets.StringProvider; -import com.glia.widgets.UiTheme; -import com.glia.widgets.chat.adapter.ChatAdapter; -import com.glia.widgets.chat.model.OperatorAttachmentItem; -import com.glia.widgets.di.Dependencies; -import com.glia.widgets.view.OperatorStatusView; - -public class OperatorFileAttachmentViewHolder extends FileAttachmentViewHolder { - private final OperatorStatusView operatorStatusView; - private final StringProvider stringProvider; - - public OperatorFileAttachmentViewHolder(@NonNull View itemView, UiTheme uiTheme) { - this(itemView, uiTheme, Dependencies.getStringProvider()); - } - - public OperatorFileAttachmentViewHolder(@NonNull View itemView, UiTheme uiTheme, @NonNull StringProvider stringProvider) { - super(itemView, stringProvider); - this.stringProvider = stringProvider; - operatorStatusView = itemView.findViewById(R.id.chat_head_view); - setupOperatorStatusView(uiTheme); - } - - public void bind(OperatorAttachmentItem.File item, ChatAdapter.OnFileItemClickListener listener) { - super.setData(item.isFileExists(), item.isDownloading(), item.getAttachment(), listener); - updateOperatorStatusView(item); - } - - private void setupOperatorStatusView(UiTheme uiTheme) { - operatorStatusView.setTheme(uiTheme); - operatorStatusView.setShowRippleAnimation(false); - } - - private void updateOperatorStatusView(OperatorAttachmentItem.File item) { - operatorStatusView.setVisibility(item.getShowChatHead() ? View.VISIBLE : View.GONE); - if (item.getOperatorProfileImgUrl() != null) { - operatorStatusView.showProfileImage(item.getOperatorProfileImgUrl()); - } else { - operatorStatusView.showPlaceholder(); - } - - String name = getAttachmentName(item.getAttachment()); - long size = getAttachmentSize(item.getAttachment()); - String byteSize = Formatter.formatFileSize(itemView.getContext(), size); - itemView.setContentDescription( - stringProvider.getRemoteString( - R.string.android_chat_operator_file_accessibility, - new StringKeyPair(StringKey.NAME, name), - new StringKeyPair(StringKey.SIZE, byteSize) - ) - ); - - ViewCompat.setAccessibilityDelegate(itemView, new AccessibilityDelegateCompat() { - @Override - public void onInitializeAccessibilityNodeInfo(@NonNull View host, @NonNull AccessibilityNodeInfoCompat info) { - super.onInitializeAccessibilityNodeInfo(host, info); - - String actionLabel = stringProvider.getRemoteString(item.isFileExists() - ? R.string.general_open - : R.string.general_download); - - AccessibilityNodeInfoCompat.AccessibilityActionCompat actionClick - = new AccessibilityNodeInfoCompat.AccessibilityActionCompat( - AccessibilityNodeInfoCompat.ACTION_CLICK, actionLabel); - info.addAction(actionClick); - } - }); - } -} diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/holder/fileattachment/OperatorFileAttachmentViewHolder.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/holder/fileattachment/OperatorFileAttachmentViewHolder.kt new file mode 100644 index 000000000..79bbc3694 --- /dev/null +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/holder/fileattachment/OperatorFileAttachmentViewHolder.kt @@ -0,0 +1,74 @@ +package com.glia.widgets.chat.adapter.holder.fileattachment + +import android.text.format.Formatter +import android.view.View +import androidx.core.view.AccessibilityDelegateCompat +import androidx.core.view.ViewCompat +import androidx.core.view.accessibility.AccessibilityNodeInfoCompat +import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat +import com.glia.widgets.R +import com.glia.widgets.StringKey +import com.glia.widgets.StringKeyPair +import com.glia.widgets.StringProvider +import com.glia.widgets.UiTheme +import com.glia.widgets.chat.adapter.ChatAdapter.OnFileItemClickListener +import com.glia.widgets.chat.model.OperatorAttachmentItem +import com.glia.widgets.databinding.ChatAttachmentOperatorFileLayoutBinding +import com.glia.widgets.di.Dependencies +import com.glia.widgets.view.unifiedui.theme.chat.MessageBalloonTheme + +internal class OperatorFileAttachmentViewHolder @JvmOverloads constructor( + private val binding: ChatAttachmentOperatorFileLayoutBinding, + uiTheme: UiTheme, + private val stringProvider: StringProvider = Dependencies.getStringProvider() +) : FileAttachmentViewHolder(binding.root, stringProvider) { + private val operatorTheme: MessageBalloonTheme? by lazy { + Dependencies.getGliaThemeManager().theme?.chatTheme?.operatorMessage + } + + init { + setupOperatorStatusView(uiTheme) + } + + fun bind(item: OperatorAttachmentItem.File, listener: OnFileItemClickListener?) { + super.setData(item.isFileExists, item.isDownloading, item.attachment, listener) + updateOperatorStatusView(item) + } + + private fun setupOperatorStatusView(uiTheme: UiTheme) { + binding.chatHeadView.setTheme(uiTheme) + binding.chatHeadView.setShowRippleAnimation(false) + binding.chatHeadView.applyUserImageTheme(operatorTheme?.userImage) + } + + private fun updateOperatorStatusView(item: OperatorAttachmentItem.File) { + binding.chatHeadView.visibility = if (item.showChatHead) View.VISIBLE else View.GONE + if (item.operatorProfileImgUrl != null) { + binding.chatHeadView.showProfileImage(item.operatorProfileImgUrl) + } else { + binding.chatHeadView.showPlaceholder() + } + val name = getAttachmentName(item.attachment) + val size = getAttachmentSize(item.attachment) + val byteSize = Formatter.formatFileSize(itemView.context, size) + itemView.contentDescription = stringProvider.getRemoteString( + R.string.android_chat_operator_file_accessibility, + StringKeyPair(StringKey.NAME, name), + StringKeyPair(StringKey.SIZE, byteSize) + ) + ViewCompat.setAccessibilityDelegate(itemView, object : AccessibilityDelegateCompat() { + override fun onInitializeAccessibilityNodeInfo( + host: View, + info: AccessibilityNodeInfoCompat + ) { + super.onInitializeAccessibilityNodeInfo(host, info) + val actionLabel = + stringProvider.getRemoteString(if (item.isFileExists) R.string.general_open else R.string.general_download) + val actionClick = AccessibilityActionCompat( + AccessibilityNodeInfoCompat.ACTION_CLICK, actionLabel + ) + info.addAction(actionClick) + } + }) + } +} diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/holder/imageattachment/OperatorImageAttachmentViewHolder.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/holder/imageattachment/OperatorImageAttachmentViewHolder.kt index 273e0529b..14fd74b5e 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/holder/imageattachment/OperatorImageAttachmentViewHolder.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/adapter/holder/imageattachment/OperatorImageAttachmentViewHolder.kt @@ -16,8 +16,7 @@ import com.glia.widgets.filepreview.domain.usecase.GetImageFileFromCacheUseCase import com.glia.widgets.filepreview.domain.usecase.GetImageFileFromDownloadsUseCase import com.glia.widgets.filepreview.domain.usecase.GetImageFileFromNetworkUseCase import com.glia.widgets.helper.rx.Schedulers -import com.glia.widgets.view.OperatorStatusView -import com.glia.widgets.view.unifiedui.theme.UnifiedTheme +import com.glia.widgets.view.unifiedui.theme.chat.MessageBalloonTheme internal class OperatorImageAttachmentViewHolder( private val binding: ChatAttachmentOperatorImageLayoutBinding, @@ -34,6 +33,9 @@ internal class OperatorImageAttachmentViewHolder( getImageFileFromNetworkUseCase, schedulers ) { + private val operatorTheme: MessageBalloonTheme? by lazy { + Dependencies.getGliaThemeManager().theme?.chatTheme?.operatorMessage + } init { setupOperatorStatus(uiTheme) @@ -42,6 +44,7 @@ internal class OperatorImageAttachmentViewHolder( private fun setupOperatorStatus(uiTheme: UiTheme) { binding.chatHeadView.setTheme(uiTheme) binding.chatHeadView.setShowRippleAnimation(false) + binding.chatHeadView.applyUserImageTheme(operatorTheme?.userImage) } fun bind( diff --git a/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorFileAttachmentViewHolderSnapshotTest_withHeaderWithGlobalColors.png b/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorFileAttachmentViewHolderSnapshotTest_withHeaderWithGlobalColors.png index 536f2a507..6841a1dd6 100644 --- a/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorFileAttachmentViewHolderSnapshotTest_withHeaderWithGlobalColors.png +++ b/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorFileAttachmentViewHolderSnapshotTest_withHeaderWithGlobalColors.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5ff6ce20fa2139dbc61ea73b29c7bba7ce4db2ed54c7d08ec946211f3298a81d -size 23742 +oid sha256:1c04449e511ba94b1a0b8f08faa5d35545e34ea1412114971328cec4950bdcb0 +size 24328 diff --git a/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorFileAttachmentViewHolderSnapshotTest_withHeaderWithUnifiedTheme.png b/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorFileAttachmentViewHolderSnapshotTest_withHeaderWithUnifiedTheme.png index 536f2a507..591f4968b 100644 --- a/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorFileAttachmentViewHolderSnapshotTest_withHeaderWithUnifiedTheme.png +++ b/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorFileAttachmentViewHolderSnapshotTest_withHeaderWithUnifiedTheme.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5ff6ce20fa2139dbc61ea73b29c7bba7ce4db2ed54c7d08ec946211f3298a81d -size 23742 +oid sha256:049ec68951a36c07e45af7a3c8860b2f1c0b6a235680c044123cf9fb467aa34b +size 24179 diff --git a/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorImageAttachmentViewHolderSnapshotTest_withHeaderWithGlobalColors.png b/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorImageAttachmentViewHolderSnapshotTest_withHeaderWithGlobalColors.png index fea252204..c22b69c91 100644 --- a/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorImageAttachmentViewHolderSnapshotTest_withHeaderWithGlobalColors.png +++ b/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorImageAttachmentViewHolderSnapshotTest_withHeaderWithGlobalColors.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b6e9114a835a8d33a62ab65137a305da5bada5c39452f56d44a3ebf6b3004feb -size 82437 +oid sha256:8aae0c488d3db0aa5e329e0cee7a758f3b411f02877c13b6cbc0cbd00690cb35 +size 82769 diff --git a/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorImageAttachmentViewHolderSnapshotTest_withHeaderWithUnifiedTheme.png b/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorImageAttachmentViewHolderSnapshotTest_withHeaderWithUnifiedTheme.png index fea252204..8262bc018 100644 --- a/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorImageAttachmentViewHolderSnapshotTest_withHeaderWithUnifiedTheme.png +++ b/widgetssdk/src/test/snapshots/images/com.glia.widgets.chat.adapter.holder_OperatorImageAttachmentViewHolderSnapshotTest_withHeaderWithUnifiedTheme.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b6e9114a835a8d33a62ab65137a305da5bada5c39452f56d44a3ebf6b3004feb -size 82437 +oid sha256:8905458aaa680e31ff11c6d4d5596e8cb0f39bf3b37eaddd287eb2b3cf902ca0 +size 82737 diff --git a/widgetssdk/src/testSnapshot/java/com/glia/widgets/chat/adapter/holder/OperatorFileAttachmentViewHolderSnapshotTest.kt b/widgetssdk/src/testSnapshot/java/com/glia/widgets/chat/adapter/holder/OperatorFileAttachmentViewHolderSnapshotTest.kt index 7d9022003..6aee712f9 100644 --- a/widgetssdk/src/testSnapshot/java/com/glia/widgets/chat/adapter/holder/OperatorFileAttachmentViewHolderSnapshotTest.kt +++ b/widgetssdk/src/testSnapshot/java/com/glia/widgets/chat/adapter/holder/OperatorFileAttachmentViewHolderSnapshotTest.kt @@ -1,6 +1,5 @@ package com.glia.widgets.chat.adapter.holder -import android.widget.LinearLayout import com.glia.androidsdk.chat.AttachmentFile import com.glia.widgets.R import com.glia.widgets.SnapshotTest @@ -8,6 +7,7 @@ import com.glia.widgets.UiTheme import com.glia.widgets.chat.adapter.ChatAdapter import com.glia.widgets.chat.adapter.holder.fileattachment.OperatorFileAttachmentViewHolder import com.glia.widgets.chat.model.OperatorAttachmentItem +import com.glia.widgets.databinding.ChatAttachmentOperatorFileLayoutBinding import com.glia.widgets.di.Dependencies import com.glia.widgets.snapshotutils.SnapshotAttachment import com.glia.widgets.snapshotutils.SnapshotChatScreen @@ -194,11 +194,7 @@ class OperatorFileAttachmentViewHolderSnapshotTest : SnapshotTest( } return OperatorFileAttachmentViewHolder( - layoutInflater.inflate( - R.layout.chat_attachment_operator_file_layout, - LinearLayout(context), - false - ), + ChatAttachmentOperatorFileLayoutBinding.inflate(layoutInflater), uiTheme ).also { viewHolder -> viewHolder.bind(item, object : ChatAdapter.OnFileItemClickListener {