forked from upstream-mirrors/quik
#1393 - Improve how we display long conversation names or group members
This commit is contained in:
@@ -30,6 +30,20 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu
|
|||||||
|
|
||||||
@Inject lateinit var textViewStyler: TextViewStyler
|
@Inject lateinit var textViewStyler: TextViewStyler
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collapse a multiline list of strings into a single line
|
||||||
|
*
|
||||||
|
* Ex.
|
||||||
|
*
|
||||||
|
* Toronto, New York, Los Angeles,
|
||||||
|
* Seattle, Portland
|
||||||
|
*
|
||||||
|
* Will be converted to
|
||||||
|
*
|
||||||
|
* Toronto, New York, Los Angeles, +2
|
||||||
|
*/
|
||||||
|
var collapseEnabled: Boolean = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (!isInEditMode) {
|
if (!isInEditMode) {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
@@ -39,6 +53,22 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom)
|
||||||
|
|
||||||
|
if (collapseEnabled) {
|
||||||
|
layout
|
||||||
|
?.takeIf { layout -> layout.lineCount > 0 }
|
||||||
|
?.let { layout -> layout.getEllipsisCount(layout.lineCount - 1) }
|
||||||
|
?.takeIf { ellipsisCount -> ellipsisCount > 0 }
|
||||||
|
?.let { ellipsisCount ->
|
||||||
|
val lastComma = text.dropLast(ellipsisCount).lastIndexOf(',')
|
||||||
|
val remainingNames = text.drop(lastComma).count { c -> c == ',' }
|
||||||
|
text = "${text.take(lastComma)}, +$remainingNames"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun setTextColor(color: Int) {
|
override fun setTextColor(color: Int) {
|
||||||
super.setTextColor(color)
|
super.setTextColor(color)
|
||||||
setLinkTextColor(color)
|
setLinkTextColor(color)
|
||||||
|
|||||||
+15
@@ -84,6 +84,21 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
view.isActivated = isSelected(conversation.id)
|
view.isActivated = isSelected(conversation.id)
|
||||||
|
|
||||||
view.avatars.contacts = conversation.recipients
|
view.avatars.contacts = conversation.recipients
|
||||||
|
view.title.collapseEnabled = conversation.recipients.size > 1
|
||||||
|
|
||||||
|
val conversationTitle = conversation.getTitle()
|
||||||
|
view.title.text = conversationTitle
|
||||||
|
if (conversation.recipients.size > 1) {
|
||||||
|
view.title.layout
|
||||||
|
?.takeIf { layout -> layout.lineCount > 0 }
|
||||||
|
?.let { layout -> layout.getEllipsisCount(layout.lineCount - 1) }
|
||||||
|
?.takeIf { ellipsisCount -> ellipsisCount > 0 }
|
||||||
|
?.let { ellipsisCount ->
|
||||||
|
val lastComma = conversationTitle.dropLast(ellipsisCount).lastIndexOf(',')
|
||||||
|
val remainingNames = conversationTitle.drop(lastComma).count { c -> c == ',' }
|
||||||
|
view.title.text = "${conversationTitle.take(lastComma)}, +$remainingNames"
|
||||||
|
}
|
||||||
|
}
|
||||||
view.title.text = conversation.getTitle()
|
view.title.text = conversation.getTitle()
|
||||||
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
||||||
view.snippet.text = when (conversation.me) {
|
view.snippet.text = when (conversation.me) {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
<!--
|
|
||||||
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||||
~
|
~
|
||||||
~ This file is part of QKSMS.
|
~ This file is part of QKSMS.
|
||||||
@@ -25,10 +24,10 @@
|
|||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingBottom="12dp"
|
|
||||||
android:paddingEnd="16dp"
|
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingTop="12dp">
|
android:paddingTop="12dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:paddingBottom="12dp">
|
||||||
|
|
||||||
<com.moez.QKSMS.common.widget.GroupAvatarView
|
<com.moez.QKSMS.common.widget.GroupAvatarView
|
||||||
android:id="@+id/avatars"
|
android:id="@+id/avatars"
|
||||||
@@ -45,8 +44,10 @@
|
|||||||
style="@style/TextPrimary"
|
style="@style/TextPrimary"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="16dp"
|
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:lines="1"
|
||||||
app:layout_constraintBottom_toTopOf="@id/snippet"
|
app:layout_constraintBottom_toTopOf="@id/snippet"
|
||||||
app:layout_constraintEnd_toStartOf="@id/date"
|
app:layout_constraintEnd_toStartOf="@id/date"
|
||||||
app:layout_constraintStart_toEndOf="@id/avatars"
|
app:layout_constraintStart_toEndOf="@id/avatars"
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
<item name="android:layout_width">match_parent</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
<item name="android:layout_height">match_parent</item>
|
<item name="android:layout_height">match_parent</item>
|
||||||
<item name="android:background">@null</item>
|
<item name="android:background">@null</item>
|
||||||
|
<item name="android:ellipsize">end</item>
|
||||||
<item name="android:gravity">start|center_vertical</item>
|
<item name="android:gravity">start|center_vertical</item>
|
||||||
<item name="android:maxLines">1</item>
|
<item name="android:maxLines">1</item>
|
||||||
<item name="textColor">primary</item>
|
<item name="textColor">primary</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user