mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-29 06:28:45 +03:00
Fix RTL paddings
Android apparently has an issue with the layout in RTL, since it applies the start/end padding to both sides of the bubble. As a workaround, put the bubbleLayout always in LTR, and handle the correct padding selection from code. Change-Id: Icddbe4b8d99383448d68bcf97f3ea166fd4cd3e6
This commit is contained in:
parent
d6b05925a9
commit
707012ee5c
1 changed files with 18 additions and 12 deletions
|
@ -221,7 +221,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
|
||||||
val memberNameView by bind<TextView>(R.id.messageMemberNameView)
|
val memberNameView by bind<TextView>(R.id.messageMemberNameView)
|
||||||
val timeView by bind<TextView>(R.id.messageTimeView)
|
val timeView by bind<TextView>(R.id.messageTimeView)
|
||||||
val eventBaseView by bind<RelativeLayout>(R.id.eventBaseView)
|
val eventBaseView by bind<RelativeLayout>(R.id.eventBaseView)
|
||||||
val bubbleView by bind<View>(R.id.bubbleView)
|
val bubbleView by bind<ViewGroup>(R.id.bubbleView)
|
||||||
val bubbleMemberNameView by bind<TextView>(R.id.bubbleMessageMemberNameView)
|
val bubbleMemberNameView by bind<TextView>(R.id.bubbleMessageMemberNameView)
|
||||||
val bubbleTimeView by bind<TextView>(R.id.bubbleMessageTimeView)
|
val bubbleTimeView by bind<TextView>(R.id.bubbleMessageTimeView)
|
||||||
val bubbleFootView by bind<LinearLayout>(R.id.bubbleFootView)
|
val bubbleFootView by bind<LinearLayout>(R.id.bubbleFootView)
|
||||||
|
@ -419,6 +419,10 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
|
||||||
val bubbleView = holder.bubbleView
|
val bubbleView = holder.bubbleView
|
||||||
val contentInBubble = infoInBubbles(holder.memberNameView.context)
|
val contentInBubble = infoInBubbles(holder.memberNameView.context)
|
||||||
|
|
||||||
|
val defaultDirection = holder.eventBaseView.resources.configuration.layoutDirection;
|
||||||
|
val defaultRtl = defaultDirection == View.LAYOUT_DIRECTION_RTL
|
||||||
|
val reverseDirection = if (defaultRtl) View.LAYOUT_DIRECTION_LTR else View.LAYOUT_DIRECTION_RTL
|
||||||
|
|
||||||
when (bubbleStyle) {
|
when (bubbleStyle) {
|
||||||
BubbleThemeUtils.BUBBLE_STYLE_START,
|
BubbleThemeUtils.BUBBLE_STYLE_START,
|
||||||
BubbleThemeUtils.BUBBLE_STYLE_BOTH,
|
BubbleThemeUtils.BUBBLE_STYLE_BOTH,
|
||||||
|
@ -447,12 +451,13 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
|
||||||
shortPadding = 0//if (attributes.informationData.showInformation && !hideSenderInformation()) { 8 } else { 0 }
|
shortPadding = 0//if (attributes.informationData.showInformation && !hideSenderInformation()) { 8 } else { 0 }
|
||||||
}
|
}
|
||||||
val density = bubbleView.resources.displayMetrics.density
|
val density = bubbleView.resources.displayMetrics.density
|
||||||
if (reverseBubble) {
|
if (reverseBubble != defaultRtl) {
|
||||||
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).marginStart = getBubbleMargin(bubbleView.resources, bubbleStyle, reverseBubble)
|
// Use left/right instead of start/end: bubbleView is always LTR
|
||||||
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).marginEnd = 0
|
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).leftMargin = getBubbleMargin(bubbleView.resources, bubbleStyle, reverseBubble)
|
||||||
|
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).rightMargin = 0
|
||||||
} else {
|
} else {
|
||||||
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).marginStart = 0
|
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).leftMargin = 0
|
||||||
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).marginEnd = getBubbleMargin(bubbleView.resources, bubbleStyle, reverseBubble)
|
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).rightMargin = getBubbleMargin(bubbleView.resources, bubbleStyle, reverseBubble)
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
(bubbleView.layoutParams as RelativeLayout.LayoutParams).marginStart = round(20*density).toInt()
|
(bubbleView.layoutParams as RelativeLayout.LayoutParams).marginStart = round(20*density).toInt()
|
||||||
|
@ -461,15 +466,16 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
|
||||||
*/
|
*/
|
||||||
val shortPaddingDp = round(shortPadding * density).toInt()
|
val shortPaddingDp = round(shortPadding * density).toInt()
|
||||||
val longPaddingDp = round(longPadding * density).toInt()
|
val longPaddingDp = round(longPadding * density).toInt()
|
||||||
if (reverseBubble) {
|
if (reverseBubble != defaultRtl) {
|
||||||
bubbleView.setPaddingRelative(
|
// Use left/right instead of start/end: bubbleView is always LTR
|
||||||
|
bubbleView.setPadding(
|
||||||
shortPaddingDp,
|
shortPaddingDp,
|
||||||
shortPaddingDp,
|
shortPaddingDp,
|
||||||
longPaddingDp,
|
longPaddingDp,
|
||||||
shortPaddingDp
|
shortPaddingDp
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
bubbleView.setPaddingRelative(
|
bubbleView.setPadding(
|
||||||
longPaddingDp,
|
longPaddingDp,
|
||||||
shortPaddingDp,
|
shortPaddingDp,
|
||||||
shortPaddingDp,
|
shortPaddingDp,
|
||||||
|
@ -580,9 +586,6 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val defaultDirection = holder.eventBaseView.resources.configuration.layoutDirection;
|
|
||||||
val defaultRtl = defaultDirection == View.LAYOUT_DIRECTION_RTL
|
|
||||||
val reverseDirection = if (defaultRtl) View.LAYOUT_DIRECTION_LTR else View.LAYOUT_DIRECTION_RTL
|
|
||||||
/*
|
/*
|
||||||
holder.eventBaseView.layoutDirection = if (shouldRtl) View.LAYOUT_DIRECTION_RTL else View.LAYOUT_DIRECTION_LTR
|
holder.eventBaseView.layoutDirection = if (shouldRtl) View.LAYOUT_DIRECTION_RTL else View.LAYOUT_DIRECTION_LTR
|
||||||
setRtl(shouldRtl)
|
setRtl(shouldRtl)
|
||||||
|
@ -591,6 +594,9 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
|
||||||
//holder.informationBottom.layoutDirection = if (shouldRtl) View.LAYOUT_DIRECTION_RTL else View.LAYOUT_DIRECTION_LTR
|
//holder.informationBottom.layoutDirection = if (shouldRtl) View.LAYOUT_DIRECTION_RTL else View.LAYOUT_DIRECTION_LTR
|
||||||
setFlatRtl(holder.reactionsContainer, if (reverseBubble) reverseDirection else defaultDirection,
|
setFlatRtl(holder.reactionsContainer, if (reverseBubble) reverseDirection else defaultDirection,
|
||||||
holder.eventBaseView.resources.configuration.layoutDirection)
|
holder.eventBaseView.resources.configuration.layoutDirection)
|
||||||
|
// Layout is broken if bubbleView is RTL (for some reason, Android uses left/end padding for right/start as well...)
|
||||||
|
setFlatRtl(holder.bubbleView, View.LAYOUT_DIRECTION_LTR,
|
||||||
|
holder.eventBaseView.resources.configuration.layoutDirection)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tintFooter(holder: H, color: Int) {
|
private fun tintFooter(holder: H, color: Int) {
|
||||||
|
|
Loading…
Reference in a new issue