Skip to content

Commit 6a95cd7

Browse files
Add custom subtitle view (microsoft#46)
1 parent bad4ad5 commit 6a95cd7

File tree

7 files changed

+102
-9
lines changed

7 files changed

+102
-9
lines changed

FluentUI.Demo/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ android {
1515
applicationId 'com.microsoft.fluentuidemo'
1616
minSdkVersion 21
1717
targetSdkVersion 28
18-
versionCode 10
19-
versionName '0.0.10'
18+
versionCode 11
19+
versionName '0.0.11'
2020
}
2121
buildTypes {
2222
release {

FluentUI.Demo/src/main/java/com/microsoft/fluentuidemo/demos/ListItemViewActivity.kt

+51-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import android.support.v7.widget.DividerItemDecoration
1414
import android.text.TextUtils
1515
import android.view.View
1616
import android.widget.ImageView
17+
import android.widget.LinearLayout
1718
import android.widget.TextView
1819
import com.microsoft.fluentui.listitem.ListItemDivider
1920
import com.microsoft.fluentui.listitem.ListItemView
@@ -140,6 +141,39 @@ class ListItemViewActivity : DemoActivity() {
140141
)
141142
)
142143

144+
val twoLineCustomSecondarySubtitleSection = createSection(
145+
createListSubHeader(getString(R.string.list_item_sub_header_two_line_custom_secondary_subtitle)),
146+
arrayListOf(
147+
createListItem(
148+
getString(R.string.list_item_title),
149+
getString(R.string.list_item_subtitle),
150+
customView = createExampleCustomView(smallIcon),
151+
customViewSize = ListItemView.CustomViewSize.SMALL,
152+
customSecondarySubtitleView = createExampleCustomSecondarySubtitleView(),
153+
layoutDensity = ListItemView.LayoutDensity.COMPACT
154+
),
155+
createListItem(
156+
getString(R.string.list_item_title),
157+
getString(R.string.list_item_subtitle),
158+
customView = createExampleCustomView(smallIcon),
159+
customViewSize = ListItemView.CustomViewSize.SMALL,
160+
customAccessoryView = createExampleCustomView(overflowIcon),
161+
customSecondarySubtitleView = createExampleCustomSecondarySubtitleView(),
162+
addCustomAccessoryViewClick = true,
163+
layoutDensity = ListItemView.LayoutDensity.COMPACT
164+
),
165+
createListItem(
166+
getString(R.string.list_item_title),
167+
getString(R.string.list_item_subtitle),
168+
customView = createExampleAvatarView(R.drawable.avatar_wanda_howard),
169+
customViewSize = ListItemView.CustomViewSize.MEDIUM,
170+
customAccessoryView = createExampleTextView(),
171+
customSecondarySubtitleView = createExampleCustomSecondarySubtitleView(),
172+
layoutDensity = ListItemView.LayoutDensity.COMPACT
173+
)
174+
)
175+
)
176+
143177
// Three-line list example
144178

145179
val threeLineSection = createSection(
@@ -276,7 +310,7 @@ class ListItemViewActivity : DemoActivity() {
276310
)
277311
)
278312

279-
val twoLineListSections = twoLineSection + twoLineDenseSection
313+
val twoLineListSections = twoLineSection + twoLineDenseSection + twoLineCustomSecondarySubtitleSection
280314
val layoutVariantSections = noCustomViewSection + largeHeaderSection + truncationSection + wrappingSection
281315
return (singleLineSection + twoLineListSections + threeLineSection + layoutVariantSections) as ArrayList<IBaseListItem>
282316
}
@@ -319,6 +353,7 @@ class ListItemViewActivity : DemoActivity() {
319353
customView: View? = null,
320354
customViewSize: ListItemView.CustomViewSize = DEFAULT_CUSTOM_VIEW_SIZE,
321355
customAccessoryView: View? = null,
356+
customSecondarySubtitleView: View? = null,
322357
addCustomAccessoryViewClick: Boolean = false,
323358
layoutDensity: ListItemView.LayoutDensity = DEFAULT_LAYOUT_DENSITY,
324359
wrap: Boolean = false
@@ -331,6 +366,7 @@ class ListItemViewActivity : DemoActivity() {
331366
item.customAccessoryView = customAccessoryView
332367
item.customView = customView
333368
item.customViewSize = customViewSize
369+
item.customSecondarySubtitleView = customSecondarySubtitleView
334370

335371
if (wrap) {
336372
item.titleMaxLines = 4
@@ -376,4 +412,18 @@ class ListItemViewActivity : DemoActivity() {
376412
avatarView.name = getString(avatarNameStringId)
377413
return avatarView
378414
}
415+
416+
private fun createExampleCustomSecondarySubtitleView(): LinearLayout {
417+
val dotTextView = TextView(this)
418+
dotTextView.text = " . "
419+
420+
val secondarySubtitleTextView = TextView(this)
421+
TextViewCompat.setTextAppearance(secondarySubtitleTextView, R.style.TextAppearance_DemoListItemSubtitle)
422+
secondarySubtitleTextView.text = getString(R.string.list_item_secondary_subtitle)
423+
424+
val linearLayout = LinearLayout(this)
425+
linearLayout.addView(dotTextView)
426+
linearLayout.addView(secondarySubtitleTextView)
427+
return linearLayout
428+
}
379429
}

FluentUI.Demo/src/main/java/com/microsoft/fluentuidemo/demos/list/IListItem.kt

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface IListItem : IBaseListItem {
2727
var customView: View?
2828
var customViewSize: ListItemView.CustomViewSize
2929
var customAccessoryView: View?
30+
var customSecondarySubtitleView: View?
3031

3132
var layoutDensity: ListItemView.LayoutDensity
3233
}
@@ -46,6 +47,7 @@ data class ListItem(override var title: String = "") : IListItem {
4647
override var customView: View? = null
4748
override var customViewSize: ListItemView.CustomViewSize = ListItemView.DEFAULT_CUSTOM_VIEW_SIZE
4849
override var customAccessoryView: View? = null
50+
override var customSecondarySubtitleView: View? = null
4951

5052
override var layoutDensity: ListItemView.LayoutDensity = ListItemView.DEFAULT_LAYOUT_DENSITY
5153
}

FluentUI.Demo/src/main/java/com/microsoft/fluentuidemo/demos/list/ListAdapter.kt

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ fun ListItemView.setListItem(listItem: IListItem) {
149149
customView = listItem.customView
150150
customViewSize = listItem.customViewSize
151151
customAccessoryView = listItem.customAccessoryView
152+
customSecondarySubtitleView = listItem.customSecondarySubtitleView
152153

153154
layoutDensity = listItem.layoutDensity
154155
}

FluentUI.Demo/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,12 @@
199199
<!--ListItem-->
200200
<string name="list_item_title">Title, primary text</string>
201201
<string name="list_item_subtitle">Subtitle, secondary text</string>
202+
<string name="list_item_secondary_subtitle">Custom subtitle text</string>
202203
<string name="list_item_footer">Footer, tertiary text</string>
203204
<string name="list_item_sub_header_single_line">Single-line list with gray sub header text</string>
204205
<string name="list_item_sub_header_two_line">Two-line list</string>
205206
<string name="list_item_sub_header_two_line_dense">Two-line list with dense spacing</string>
207+
<string name="list_item_sub_header_two_line_custom_secondary_subtitle">Two line list with custom secondary subtitle view</string>
206208
<string name="list_item_sub_header_three_line">Three-line list with black sub header text</string>
207209
<string name="list_item_sub_header_no_custom_views">List items with no custom views</string>
208210
<string name="list_item_sub_header_large_header">List items with large custom views</string>

FluentUI/src/main/java/com/microsoft/fluentui/listitem/ListItemView.kt

+14
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ open class ListItemView : TemplateView {
190190
updateTemplate()
191191
}
192192

193+
/**
194+
* This view will be displayed at the end of subtitle view.
195+
*/
196+
var customSecondarySubtitleView: View? = null
197+
set(value) {
198+
if (field == value)
199+
return
200+
field = value
201+
updateTemplate()
202+
}
203+
193204
/**
194205
* Determines the list item view vertical padding density.
195206
*/
@@ -313,6 +324,7 @@ open class ListItemView : TemplateView {
313324
private var container: LinearLayout? = null
314325
private var customViewContainer: RelativeLayout? = null
315326
private var customAccessoryViewContainer: RelativeLayout? = null
327+
private var customSecondarySubtitleViewContainer: RelativeLayout? = null
316328
private var textViewContainer: LinearLayout? = null
317329

318330
override fun onTemplateLoaded() {
@@ -325,6 +337,7 @@ open class ListItemView : TemplateView {
325337
container = findViewInTemplateById(R.id.list_item)
326338
customViewContainer = findViewInTemplateById(R.id.list_item_custom_view_container)
327339
customAccessoryViewContainer = findViewInTemplateById(R.id.list_item_custom_accessory_view_container)
340+
customSecondarySubtitleViewContainer = findViewInTemplateById(R.id.list_item_custom_secondary_subtitle_view_container)
328341
textViewContainer = findViewInTemplateById(R.id.list_item_text_view_container)
329342

330343
updateTemplate()
@@ -341,6 +354,7 @@ open class ListItemView : TemplateView {
341354

342355
customViewContainer?.setContentAndUpdateVisibility(customView, ::updateCustomViewLayout)
343356
customAccessoryViewContainer?.setContentAndUpdateVisibility(customAccessoryView)
357+
customSecondarySubtitleViewContainer?.setContentAndUpdateVisibility(customSecondarySubtitleView)
344358

345359
setBackgroundResource(background)
346360
}

FluentUI/src/main/res/layout/view_list_item.xml

+30-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
88
xmlns:tools="http://schemas.android.com/tools"
9+
xmlns:app="http://schemas.android.com/apk/res-auto"
910
android:id="@+id/list_item"
1011
android:layout_width="match_parent"
1112
android:layout_height="wrap_content"
@@ -33,14 +34,37 @@
3334
android:textAppearance="@style/TextAppearance.FluentUI.ListItemTitle"
3435
tools:text="Title" />
3536

36-
<TextView
37-
android:id="@+id/list_item_subtitle"
37+
<android.support.constraint.ConstraintLayout
38+
android:id="@+id/list_item_subtitle_view_container"
3839
android:layout_width="match_parent"
3940
android:layout_height="wrap_content"
40-
android:layout_marginTop="@dimen/fluentui_list_item_text_vertical_spacing"
41-
android:textAppearance="@style/TextAppearance.FluentUI.ListItemSubtitle"
42-
tools:text="Subtitle"
43-
tools:visibility="visible" />
41+
android:layout_marginTop="@dimen/fluentui_list_item_text_vertical_spacing">
42+
43+
<TextView
44+
android:id="@+id/list_item_subtitle"
45+
android:layout_width="wrap_content"
46+
android:layout_height="wrap_content"
47+
android:textAppearance="@style/TextAppearance.FluentUI.ListItemSubtitle"
48+
app:layout_constraintTop_toTopOf="@+id/list_item_subtitle_view_container"
49+
app:layout_constraintStart_toStartOf="@+id/list_item_subtitle_view_container"
50+
app:layout_constraintBottom_toBottomOf="@+id/list_item_subtitle_view_container"
51+
app:layout_constraintEnd_toStartOf="@+id/list_item_custom_secondary_subtitle_view_container"
52+
app:layout_constraintHorizontal_bias="0.0"
53+
app:layout_constraintHorizontal_chainStyle="packed"
54+
app:layout_constrainedWidth="true"
55+
tools:text="Subtitle"
56+
tools:visibility="visible"/>
57+
58+
<RelativeLayout
59+
android:id="@+id/list_item_custom_secondary_subtitle_view_container"
60+
android:layout_width="wrap_content"
61+
android:layout_height="wrap_content"
62+
app:layout_constraintStart_toEndOf="@+id/list_item_subtitle"
63+
app:layout_constraintEnd_toEndOf="@+id/list_item_subtitle_view_container"
64+
app:layout_constraintTop_toTopOf="@+id/list_item_subtitle_view_container"
65+
app:layout_constraintBottom_toBottomOf="@+id/list_item_subtitle_view_container"/>
66+
67+
</android.support.constraint.ConstraintLayout>
4468

4569
<TextView
4670
android:id="@+id/list_item_footer"

0 commit comments

Comments
 (0)