mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
#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
|
||||
|
||||
/**
|
||||
* 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)
|
||||
|
||||
Reference in New Issue
Block a user