#1393 - Improve how we display long conversation names or group members

This commit is contained in:
moezbhatti
2019-06-09 01:44:14 -04:00
parent ec89c97b45
commit 97f447dfd3
4 changed files with 53 additions and 6 deletions
@@ -30,6 +30,20 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu
@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 {
if (!isInEditMode) {
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) {
super.setTextColor(color)
setLinkTextColor(color)