mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-28 05:59:05 +03:00
Rich replies: max height
Change-Id: I4a0672dc9b2223245128e8ee0fd8fba20a1ecd8d
This commit is contained in:
parent
a9c7c15bd2
commit
d8ac4f53d7
5 changed files with 86 additions and 21 deletions
|
@ -33,6 +33,7 @@ public class ExpandableViewLayout extends FrameLayout {
|
|||
|
||||
private int mMaxHeight;
|
||||
private boolean mExpanded;
|
||||
private boolean mAllowExpand;
|
||||
private View mExpandableControl;
|
||||
private int mChildViewHeight;
|
||||
|
||||
|
@ -57,6 +58,8 @@ public class ExpandableViewLayout extends FrameLayout {
|
|||
mMaxHeight = a.getDimensionPixelSize(attr, mMaxHeight);
|
||||
} else if (attr == R.styleable.ExpandableViewLayout_expanded) {
|
||||
mExpanded = a.getBoolean(attr, false);
|
||||
} else if (attr == R.styleable.ExpandableViewLayout_allowExpand) {
|
||||
mAllowExpand = a.getBoolean(attr, false);
|
||||
}
|
||||
}
|
||||
a.recycle();
|
||||
|
@ -73,11 +76,19 @@ public class ExpandableViewLayout extends FrameLayout {
|
|||
|
||||
// Obtain the expandable control
|
||||
mExpandableControl = getChildAt(1);
|
||||
mExpandableControl.setOnClickListener(view -> {
|
||||
mExpanded = !mExpanded;
|
||||
setExpandableControlVisibility();
|
||||
requestLayout();
|
||||
});
|
||||
if (mAllowExpand) {
|
||||
mExpandableControl.setOnClickListener(view -> {
|
||||
mExpanded = !mExpanded;
|
||||
setExpandableControlVisibility();
|
||||
requestLayout();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void setExpanded(Boolean expanded) {
|
||||
mExpanded = expanded;
|
||||
setExpandableControlVisibility();
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
package im.vector.app.features.home.room.detail.timeline.reply
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.text.Spanned
|
||||
import android.text.method.MovementMethod
|
||||
import android.util.AttributeSet
|
||||
|
@ -28,11 +30,14 @@ import androidx.core.text.PrecomputedTextCompat
|
|||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.TextViewCompat
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.tintBackground
|
||||
import im.vector.app.databinding.ViewInReplyToBinding
|
||||
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.app.features.home.room.detail.timeline.item.BindingOptions
|
||||
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData
|
||||
import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLayout
|
||||
import im.vector.app.features.home.room.detail.timeline.tools.findPillsAndProcess
|
||||
import im.vector.app.features.themes.ThemeUtils
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageTextContent
|
||||
|
@ -103,6 +108,7 @@ class InReplyToView @JvmOverloads constructor(
|
|||
private fun hideViews() {
|
||||
views.replyMemberNameView.isVisible = false
|
||||
views.replyTextView.isVisible = false
|
||||
renderFadeOut(null)
|
||||
}
|
||||
|
||||
private fun renderHidden() {
|
||||
|
@ -139,6 +145,7 @@ class InReplyToView @JvmOverloads constructor(
|
|||
if (state.event.root.isRedacted()) {
|
||||
renderRedacted()
|
||||
} else {
|
||||
renderFadeOut(roomInformationData)
|
||||
when (val content = state.event.getLastMessageContent()) {
|
||||
is MessageTextContent -> renderTextContent(content, retriever, movementMethod, coroutineScope)
|
||||
else -> renderFallback(state.event, retriever)
|
||||
|
@ -207,4 +214,36 @@ class InReplyToView @JvmOverloads constructor(
|
|||
text = message
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param informationData The information data of the parent message, for background fade rendering info. Null to force expand to full height.
|
||||
*/
|
||||
private fun renderFadeOut(informationData: MessageInformationData?) {
|
||||
if (informationData != null) {
|
||||
views.expandableReplyView.setExpanded(false)
|
||||
val bgColor = when (val layout = informationData.messageLayout) {
|
||||
is TimelineMessageLayout.ScBubble -> {
|
||||
if (informationData.sentByMe && !layout.singleSidedLayout) {
|
||||
ThemeUtils.getColor(context, R.attr.sc_message_bg_outgoing)
|
||||
} else {
|
||||
ThemeUtils.getColor(context, R.attr.sc_message_bg_incoming)
|
||||
}
|
||||
}
|
||||
is TimelineMessageLayout.Bubble -> {
|
||||
if (layout.isPseudoBubble) {
|
||||
0
|
||||
} else {
|
||||
val backgroundColorAttr = if (informationData.sentByMe) R.attr.vctr_message_bubble_outbound else R.attr.vctr_message_bubble_inbound
|
||||
ThemeUtils.getColor(context, backgroundColorAttr)
|
||||
}
|
||||
}
|
||||
is TimelineMessageLayout.Default -> {
|
||||
ThemeUtils.getColor(context, R.attr.vctr_system)
|
||||
}
|
||||
}
|
||||
views.expandableReplyView.getChildAt(1).tintBackground(bgColor)
|
||||
} else {
|
||||
views.expandableReplyView.setExpanded(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,5 +15,5 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<gradient android:angle="90" android:startColor="#FFFFFFFF" android:endColor="#99FFFFFF" />
|
||||
</shape>
|
||||
<gradient android:angle="90" android:startColor="#FFFFFFFF" android:endColor="#00FFFFFF" />
|
||||
</shape>
|
||||
|
|
|
@ -31,22 +31,36 @@
|
|||
android:textSize="12sp"
|
||||
tools:text="@sample/users.json/data/displayName" />
|
||||
|
||||
<!-- Layout gravity left: fixes long display name pills moving text out:
|
||||
https://github.com/SchildiChat/SchildiChat-android/issues/66
|
||||
Interestingly, this not only fixes it for LTR texts for RTL locales,
|
||||
but it also makes it align better for RTL texts in RTL locales - at least
|
||||
until the user pill is touched...
|
||||
-->
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/replyTextView"
|
||||
style="@style/Widget.Vector.TextView.Body"
|
||||
<com.ruesga.rview.widget.ExpandableViewLayout
|
||||
android:id="@+id/expandableReplyView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="0dp"
|
||||
android:textColor="?vctr_content_primary"
|
||||
android:layout_gravity="left"
|
||||
tools:text="@sample/messages.json/data/message"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
android:scrollbars="none"
|
||||
app:expanded="false"
|
||||
app:allowExpand="false"
|
||||
app:maxHeight="64dp">
|
||||
<!-- Layout gravity left: fixes long display name pills moving text out:
|
||||
https://github.com/SchildiChat/SchildiChat-android/issues/66
|
||||
Interestingly, this not only fixes it for LTR texts for RTL locales,
|
||||
but it also makes it align better for RTL texts in RTL locales - at least
|
||||
until the user pill is touched...
|
||||
-->
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/replyTextView"
|
||||
style="@style/Widget.Vector.TextView.Body"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="0dp"
|
||||
android:textColor="?vctr_content_primary"
|
||||
android:layout_gravity="left"
|
||||
tools:text="@sample/messages.json/data/message"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="32dp"
|
||||
android:background="@drawable/bg_expandable_edge_shadow"
|
||||
android:layout_gravity="bottom" />
|
||||
</com.ruesga.rview.widget.ExpandableViewLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -18,5 +18,6 @@
|
|||
<declare-styleable name="ExpandableViewLayout">
|
||||
<attr name="maxHeight" format="dimension"/>
|
||||
<attr name="expanded" format="boolean"/>
|
||||
<attr name="allowExpand" format="boolean"/>
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue