Lazy man's Reverse bubbles

Exploit RTL to reverse the layout.
PNGs again from AOSP Messaging app
This commit is contained in:
SpiritCroc 2020-05-16 17:46:21 +02:00
parent 2f888e79dc
commit e56133348f
12 changed files with 17 additions and 6 deletions

View File

@ -19,9 +19,10 @@ package im.vector.riotx.features.home.room.detail.timeline.item
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.text.method.MovementMethod import android.text.method.MovementMethod
import android.view.Gravity import android.view.Gravity
import android.view.View
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.RelativeLayout
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import androidx.core.text.PrecomputedTextCompat import androidx.core.text.PrecomputedTextCompat
import androidx.core.widget.TextViewCompat import androidx.core.widget.TextViewCompat
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
@ -71,14 +72,15 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
null) null)
holder.messageView.setTextFuture(textFuture) holder.messageView.setTextFuture(textFuture)
var bubbleStyle = if (incomingMessage || outgoingMessage) BubbleThemeUtils.getBubbleStyle(holder.messageView.context) else BUBBLE_STYLE_NONE val bubbleStyle = if (incomingMessage || outgoingMessage) BubbleThemeUtils.getBubbleStyle(holder.messageView.context) else BUBBLE_STYLE_NONE
val reverseBubble = outgoingMessage && bubbleStyle == BUBBLE_STYLE_BOTH
when (bubbleStyle) { when (bubbleStyle) {
BUBBLE_STYLE_NONE -> { BUBBLE_STYLE_NONE -> {
holder.messageView.background = null holder.messageView.background = null
holder.messageView.setPadding(0, 0, 0, 0) holder.messageView.setPadding(0, 0, 0, 0)
} }
BUBBLE_STYLE_START, BUBBLE_STYLE_BOTH -> { BUBBLE_STYLE_START, BUBBLE_STYLE_BOTH -> {
holder.messageView.setBackgroundResource(R.drawable.msg_bubble_incoming) holder.messageView.setBackgroundResource(if (reverseBubble) R.drawable.msg_bubble_outgoing else R.drawable.msg_bubble_incoming)
var tintColor = ColorStateList( var tintColor = ColorStateList(
arrayOf(intArrayOf(0)), arrayOf(intArrayOf(0)),
intArrayOf(ThemeUtils.getColor(holder.messageView.context, intArrayOf(ThemeUtils.getColor(holder.messageView.context,
@ -96,8 +98,10 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
} }
} }
if (holder.messageView.layoutParams is FrameLayout.LayoutParams) { if (holder.messageView.layoutParams is FrameLayout.LayoutParams) {
(holder.messageView.layoutParams as FrameLayout.LayoutParams).gravity = //(holder.messageView.layoutParams as FrameLayout.LayoutParams).gravity =
if (outgoingMessage && bubbleStyle == BUBBLE_STYLE_BOTH) Gravity.END else Gravity.START // if (outgoingMessage && bubbleStyle == BUBBLE_STYLE_BOTH) Gravity.END else Gravity.START
val defaultReverse = holder.messageView.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL;
(holder.messageView.parent.parent as RelativeLayout).layoutDirection = if (reverseBubble != defaultReverse) View.LAYOUT_DIRECTION_RTL else View.LAYOUT_DIRECTION_LTR
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 469 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 597 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -23,6 +23,14 @@
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
tools:src="@tools:sample/avatars" /> tools:src="@tools:sample/avatars" />
<!-- spacer so rtl-hack works better with messageMemberNameView -->
<View
android:id="@+id/spacer_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="@+id/messageTimeView"
android:layout_toEndOf="@+id/messageMemberNameView" />
<im.vector.riotx.core.platform.EllipsizingTextView <im.vector.riotx.core.platform.EllipsizingTextView
android:id="@+id/messageMemberNameView" android:id="@+id/messageMemberNameView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -33,7 +41,6 @@
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:layout_marginEnd="4dp" android:layout_marginEnd="4dp"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:layout_toStartOf="@+id/messageTimeView"
android:layout_toEndOf="@+id/messageStartGuideline" android:layout_toEndOf="@+id/messageStartGuideline"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"