Twelve: ListItem: Add leading text support
Change-Id: I02fdf48854795136d7b25bcdbba704619eaa9f33
diff --git a/app/src/main/java/org/lineageos/twelve/ui/views/ListItem.kt b/app/src/main/java/org/lineageos/twelve/ui/views/ListItem.kt
index 049b4ca..86cb4a7 100644
--- a/app/src/main/java/org/lineageos/twelve/ui/views/ListItem.kt
+++ b/app/src/main/java/org/lineageos/twelve/ui/views/ListItem.kt
@@ -28,6 +28,7 @@
) : FrameLayout(context, attrs) {
private val headlineTextView by lazy { findViewById<TextView>(R.id.headlineTextView) }
private val leadingIconImageView by lazy { findViewById<ImageView>(R.id.leadingIconImageView) }
+ private val leadingTextView by lazy { findViewById<TextView>(R.id.leadingTextView) }
private val supportingTextView by lazy { findViewById<TextView>(R.id.supportingTextView) }
private val trailingIconImageView by lazy { findViewById<ImageView>(R.id.trailingIconImageView) }
private val trailingSupportingTextView by lazy { findViewById<TextView>(R.id.trailingSupportingTextView) }
@@ -38,6 +39,12 @@
leadingIconImageView.setImageAndUpdateVisibility(value)
}
+ var leadingText: CharSequence?
+ get() = leadingTextView.text
+ set(value) {
+ leadingTextView.setTextAndUpdateVisibility(value)
+ }
+
var headlineText: CharSequence?
get() = headlineTextView.text
set(value) {
@@ -68,6 +75,7 @@
context.obtainStyledAttributes(attrs, R.styleable.ListItem, 0, 0).apply {
try {
leadingIconImage = getDrawable(R.styleable.ListItem_leadingIconImage)
+ leadingText = getString(R.styleable.ListItem_leadingText)
headlineText = getString(R.styleable.ListItem_headlineText)
supportingText = getString(R.styleable.ListItem_supportingText)
trailingIconImage = getDrawable(R.styleable.ListItem_trailingIconImage)
@@ -89,6 +97,10 @@
fun setLeadingIconImage(uri: Uri) = leadingIconImageView.setImageAndUpdateVisibility(uri)
+ fun setLeadingText(@StringRes resId: Int) = leadingTextView.setTextAndUpdateVisibility(resId)
+ fun setLeadingText(@StringRes resId: Int, vararg formatArgs: Any) =
+ leadingTextView.setTextAndUpdateVisibility(resId, *formatArgs)
+
fun setSupportingText(@StringRes resId: Int) =
supportingTextView.setTextAndUpdateVisibility(resId)
diff --git a/app/src/main/res/layout/list_item.xml b/app/src/main/res/layout/list_item.xml
index 70eb846..a971960 100644
--- a/app/src/main/res/layout/list_item.xml
+++ b/app/src/main/res/layout/list_item.xml
@@ -25,6 +25,16 @@
tools:src="@android:drawable/star_on"
tools:visibility="visible" />
+ <TextView
+ android:id="@+id/leadingTextView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="16dp"
+ android:visibility="gone"
+ app:tint="?attr/colorOnSurfaceVariant"
+ tools:text="Leading"
+ tools:visibility="visible" />
+
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
diff --git a/app/src/main/res/values/attrs_ListItem.xml b/app/src/main/res/values/attrs_ListItem.xml
index 8483f7a..85df37b 100644
--- a/app/src/main/res/values/attrs_ListItem.xml
+++ b/app/src/main/res/values/attrs_ListItem.xml
@@ -7,6 +7,7 @@
<declare-styleable name="ListItem">
<attr name="headlineText" format="string" />
<attr name="leadingIconImage" format="reference" />
+ <attr name="leadingText" format="string" />
<attr name="supportingText" format="string" />
<attr name="trailingIconImage" format="reference" />
<attr name="trailingSupportingText" format="string" />