Skip to content

Commit

Permalink
Fix send and attachment buttons overlap
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gugalo authored and Andrii-Horishnii-Glia committed Jan 23, 2025
1 parent 68f73c3 commit 4587236
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ internal class ChatView(context: Context, attrs: AttributeSet?, defStyleAttr: In
private var binding by Delegates.notNull<ChatViewBinding>()
private val attachmentPopup by lazy {
AttachmentPopup(
binding.chatMessageLayout, Dependencies.gliaThemeManager.theme?.chatTheme?.attachmentsPopup
context, Dependencies.gliaThemeManager.theme?.chatTheme?.attachmentsPopup
)
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 37 additions & 30 deletions widgetssdk/src/main/res/layout/chat_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<LinearLayout
android:id="@+id/chat_message_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
<View
android:id="@+id/message_input_background"
android:layout_height="0dp"
android:layout_width="0dp"
app:layout_constraintTop_toTopOf="@+id/chat_edit_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/add_attachment_queue">
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<com.glia.widgets.view.textview.SingleLineHintEditText
android:id="@+id/chat_edit_text"
style="@style/Application.Glia.Chat.Edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/add_attachment_button"
android:importantForAutofill="no"
android:maxLength="10000"
android:maxLines="4"
Expand All @@ -131,29 +134,33 @@
android:textColor="?attr/gliaBaseDarkColor"
android:textColorHint="?attr/gliaBaseNormalColor"
android:textCursorDrawable="@null"
tools:ignore="RtlSymmetry"
tools:textColor="@color/glia_black_color" />
tools:text="@string/chat_input_placeholder"/>

<ImageButton
android:id="@+id/add_attachment_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/glia_large"
android:src="@drawable/ic_add_attachment" />
<ImageButton
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_constraintStart_toEndOf="@+id/chat_edit_text"
app:layout_constraintEnd_toStartOf="@+id/send_button"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/glia_large"
android:src="@drawable/ic_add_attachment" />

<ImageButton
android:id="@+id/send_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/glia_large"
android:src="?attr/gliaIconSendMessage"
app:tint="?attr/gliaBrandPrimaryColor"
tools:src="@drawable/ic_baseline_send"
tools:tint="@color/glia_brand_primary_color" />
</LinearLayout>
<ImageButton
android:id="@+id/send_button"
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_constraintStart_toEndOf="@+id/add_attachment_button"
app:layout_constraintEnd_toEndOf="parent"
android:background="?attr/selectableItemBackground"
android:src="?attr/gliaIconSendMessage"
app:tint="?attr/gliaBrandPrimaryColor"
tools:src="@drawable/ic_baseline_send"
tools:tint="@color/glia_primary_color" />

</merge>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}

0 comments on commit 4587236

Please sign in to comment.