From 2f4ca06f14b6d62576ba8296e649d616e3835f6f Mon Sep 17 00:00:00 2001 From: Aleksandr Chatsky Date: Mon, 2 Dec 2024 13:09:38 +0200 Subject: [PATCH 1/2] Fix send and attachment buttons overlap Side effect of making the layout flat is that now those buttons have slight animation. MOB-3844 # Conflicts: # build.gradle # widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.kt # widgetssdk/src/main/res/layout/chat_view.xml --- .../com/glia/widgets/chat/AttachmentPopup.kt | 7 +- .../java/com/glia/widgets/chat/ChatView.kt | 11 +-- .../glia/widgets/messagecenter/MessageView.kt | 2 +- .../widgets/view/snackbar/SnackBarDelegate.kt | 2 +- widgetssdk/src/main/res/layout/chat_view.xml | 67 ++++++++++--------- .../view/snackbar/SnackBarDelegateTest.kt | 2 +- .../chat/AttachmentPopupSnapshotTest.kt | 5 +- 7 files changed, 53 insertions(+), 43 deletions(-) diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/AttachmentPopup.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/AttachmentPopup.kt index 25929f43f..941f3762c 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/AttachmentPopup.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/AttachmentPopup.kt @@ -12,18 +12,19 @@ import com.glia.widgets.databinding.ChatAttachmentPopupBinding import com.glia.widgets.helper.getColorCompat import com.glia.widgets.helper.setLocaleText import com.glia.widgets.helper.setTintCompat +import com.glia.widgets.helper.wrapWithMaterialThemeOverlay import com.glia.widgets.view.unifiedui.applyImageColorTheme import com.glia.widgets.view.unifiedui.applyTextTheme import com.glia.widgets.view.unifiedui.theme.chat.AttachmentsPopupTheme internal class AttachmentPopup( - anchor: View, + context: Context, private val theme: AttachmentsPopupTheme?, private val popupWindowFunc: (LinearLayout) -> PopupWindow = ::popupWindow ) { - private val margin by lazy { anchor.context.resources.getDimensionPixelSize(R.dimen.glia_chat_attachment_menu_margin) } - private val binding: ChatAttachmentPopupBinding by lazy { bindLayout(anchor.context) } + private val margin by lazy { context.resources.getDimensionPixelSize(R.dimen.glia_chat_attachment_menu_margin) } + private val binding: ChatAttachmentPopupBinding by lazy { bindLayout(context.wrapWithMaterialThemeOverlay()) } private val popupWindow: PopupWindow by lazy { createPopupMenu() } private fun createPopupMenu(): PopupWindow { diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.kt index e301099de..6dd413f12 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.kt @@ -168,7 +168,7 @@ internal class ChatView(context: Context, attrs: AttributeSet?, defStyleAttr: In private var binding by Delegates.notNull() private val attachmentPopup by lazy { AttachmentPopup( - binding.chatMessageLayout, Dependencies.gliaThemeManager.theme?.chatTheme?.attachmentsPopup + context, Dependencies.gliaThemeManager.theme?.chatTheme?.attachmentsPopup ) } @@ -718,7 +718,7 @@ internal class ChatView(context: Context, attrs: AttributeSet?, defStyleAttr: In private fun setupAddAttachmentButton() { binding.addAttachmentButton.setOnClickListener { - attachmentPopup.show(binding.chatMessageLayout, { + attachmentPopup.show(binding.addAttachmentButton, { getContentLauncher?.launch(arrayOf(Constants.MIME_TYPE_IMAGES)) }, { controller?.onTakePhotoClicked() @@ -851,7 +851,7 @@ internal class ChatView(context: Context, attrs: AttributeSet?, defStyleAttr: In binding.sendButton.applyButtonTheme(inputTheme.sendButton) binding.addAttachmentButton.applyButtonTheme(inputTheme.mediaButton) binding.dividerView.applyColorTheme(inputTheme.divider) - binding.chatMessageLayout.applyLayerTheme(inputTheme.background) + binding.messageInputBackground.applyLayerTheme(inputTheme.background) binding.chatEditText.applyTextTheme(textTheme = inputTheme.text, withAlignment = false) inputTheme.placeholder?.textColor?.primaryColor?.also(binding.chatEditText::setHintTextColor) } @@ -872,7 +872,10 @@ internal class ChatView(context: Context, attrs: AttributeSet?, defStyleAttr: In binding.apply { chatRecyclerView.updatePadding(bottom = dialogHeight) chatRecyclerView.scrollBy(0, dialogHeight) - chatMessageLayout.isGone = true + messageInputBackground.isGone = true + chatEditText.isGone = true + addAttachmentButton.isGone = true + sendButton.isGone = true operatorTypingAnimationView.isGone = true } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/messagecenter/MessageView.kt b/widgetssdk/src/main/java/com/glia/widgets/messagecenter/MessageView.kt index d4462e38d..3b324a947 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/messagecenter/MessageView.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/messagecenter/MessageView.kt @@ -77,7 +77,7 @@ internal class MessageView( private var theme: UiTheme by Delegates.notNull() private val attachmentPopup by lazy { - AttachmentPopup(addAttachmentButton, unifiedTheme?.pickMediaTheme) + AttachmentPopup(context, unifiedTheme?.pickMediaTheme) } val messageTitleTop: Int get() = messageTitle.top diff --git a/widgetssdk/src/main/java/com/glia/widgets/view/snackbar/SnackBarDelegate.kt b/widgetssdk/src/main/java/com/glia/widgets/view/snackbar/SnackBarDelegate.kt index ee41eeed3..1985ff13f 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/view/snackbar/SnackBarDelegate.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/view/snackbar/SnackBarDelegate.kt @@ -88,7 +88,7 @@ internal class CommonSnackBarDelegate(activity: Activity, titleStringKey: Int, l @VisibleForTesting internal class ChatActivitySnackBarDelegate(activity: ChatActivity, titleStringKey: Int, localeProvider: LocaleProvider, unifiedTheme: UnifiedTheme?) : SnackBarDelegate(activity.findViewById(R.id.chat_view), titleStringKey, localeProvider, unifiedTheme?.snackBarTheme) { - override val anchorViewId: Int = R.id.chat_message_layout + override val anchorViewId: Int = R.id.message_input_background } @VisibleForTesting diff --git a/widgetssdk/src/main/res/layout/chat_view.xml b/widgetssdk/src/main/res/layout/chat_view.xml index f604e439b..a1bc25a5c 100644 --- a/widgetssdk/src/main/res/layout/chat_view.xml +++ b/widgetssdk/src/main/res/layout/chat_view.xml @@ -103,26 +103,29 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="vertical" - app:layout_constraintBottom_toTopOf="@+id/chat_message_layout" + app:layout_constraintBottom_toTopOf="@+id/chat_edit_text" app:layout_constraintHeight_max="216dp" app:layout_constraintTop_toBottomOf="@+id/divider_view" tools:itemCount="6" tools:listitem="@layout/chat_attachment_uploaded_item" /> - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent"/> + tools:text="@string/chat_input_placeholder"/> - + - - + diff --git a/widgetssdk/src/test/java/com/glia/widgets/view/snackbar/SnackBarDelegateTest.kt b/widgetssdk/src/test/java/com/glia/widgets/view/snackbar/SnackBarDelegateTest.kt index ec2b58cff..97093b88f 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/view/snackbar/SnackBarDelegateTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/view/snackbar/SnackBarDelegateTest.kt @@ -80,7 +80,7 @@ class SnackBarDelegateTest { fun `anchorViewId returns corresponding ids when chat or call activity is passed`() { CommonSnackBarDelegate(commonActivity, titleStringKey, mock(), mock()).apply { assertNull(anchorViewId) } CallActivitySnackBarDelegate(callActivity, titleStringKey, mock(), mock()).apply { assertEquals(R.id.buttons_layout_bg, anchorViewId) } - ChatActivitySnackBarDelegate(chatActivity, titleStringKey, mock(), mock()).apply { assertEquals(R.id.chat_message_layout, anchorViewId) } + ChatActivitySnackBarDelegate(chatActivity, titleStringKey, mock(), mock()).apply { assertEquals(R.id.message_input_background, anchorViewId) } } @Test diff --git a/widgetssdk/src/testSnapshot/java/com/glia/widgets/chat/AttachmentPopupSnapshotTest.kt b/widgetssdk/src/testSnapshot/java/com/glia/widgets/chat/AttachmentPopupSnapshotTest.kt index 3c6be35e2..19ff93ab7 100644 --- a/widgetssdk/src/testSnapshot/java/com/glia/widgets/chat/AttachmentPopupSnapshotTest.kt +++ b/widgetssdk/src/testSnapshot/java/com/glia/widgets/chat/AttachmentPopupSnapshotTest.kt @@ -55,16 +55,15 @@ class AttachmentPopupSnapshotTest : SnapshotTest(), SnapshotTheme, SnapshotProvi ) : AttachmentPopup { localeProviderMock() - val anchor = LinearLayout(context) return AttachmentPopup( - anchor, + context, unifiedTheme ) { it.layoutParams = LinearLayout.LayoutParams(650, LinearLayout.LayoutParams.WRAP_CONTENT) viewCallback(it) mock() }.apply { - show(anchor, mock(), mock(), mock()) + show(View(context), mock(), mock(), mock()) } } } From b3b8c10694e40ee36990e34de188a25999806b13 Mon Sep 17 00:00:00 2001 From: Aleksandr Chatsky Date: Fri, 13 Dec 2024 14:26:29 +0200 Subject: [PATCH 2/2] Fix jumpy animation of chat input on keyboard show/hide MOB-3860 # Conflicts: # widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.kt --- widgetssdk/src/main/res/layout/chat_view.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/widgetssdk/src/main/res/layout/chat_view.xml b/widgetssdk/src/main/res/layout/chat_view.xml index a1bc25a5c..78a13cb51 100644 --- a/widgetssdk/src/main/res/layout/chat_view.xml +++ b/widgetssdk/src/main/res/layout/chat_view.xml @@ -114,7 +114,7 @@ android:layout_height="0dp" android:layout_width="0dp" app:layout_constraintTop_toTopOf="@+id/chat_edit_text" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toBottomOf="@+id/chat_edit_text" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"/> @@ -140,8 +140,8 @@ android:id="@+id/add_attachment_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - app:layout_constraintTop_toTopOf="@+id/message_input_background" - app:layout_constraintBottom_toBottomOf="@+id/message_input_background" + app:layout_constraintTop_toTopOf="@+id/chat_edit_text" + app:layout_constraintBottom_toBottomOf="@+id/chat_edit_text" app:layout_constraintStart_toEndOf="@+id/chat_edit_text" app:layout_constraintEnd_toStartOf="@+id/send_button" android:background="?attr/selectableItemBackground" @@ -153,8 +153,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/glia_large" - app:layout_constraintBottom_toBottomOf="@+id/message_input_background" - app:layout_constraintTop_toTopOf="@+id/message_input_background" + app:layout_constraintBottom_toBottomOf="@+id/chat_edit_text" + app:layout_constraintTop_toTopOf="@+id/chat_edit_text" app:layout_constraintStart_toEndOf="@+id/add_attachment_button" app:layout_constraintEnd_toEndOf="parent" android:background="?attr/selectableItemBackground"