Skip to content

Commit e6fb07c

Browse files
authored
Support New Pill on Settings list item (#6376)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1202857801505092/task/1210770245826488?focus=true ### Description Add support for New pill on SettingsListItem ### Steps to test this PR _Feature 1_ - [x] install this branch - [x] open settings - [x] items are listed correctly - [x] Go to ADS internal settings - [x] List items section - [x] Scroll to the bottom - [x] See an example of components using Beta and New Pill ### UI changes | Before | After | | ------ | ----- | !(Upload before screenshot)|(Upload after screenshot)|
1 parent 3c656f1 commit e6fb07c

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

common/common-ui/src/main/java/com/duckduckgo/common/ui/view/listitem/SettingsListItem.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import android.widget.ImageView
2222
import androidx.annotation.DrawableRes
2323
import androidx.constraintlayout.widget.ConstraintLayout
2424
import androidx.core.content.ContextCompat
25-
import androidx.core.view.isVisible
2625
import com.duckduckgo.common.ui.view.StatusIndicatorView
2726
import com.duckduckgo.common.ui.view.StatusIndicatorView.Status
2827
import com.duckduckgo.common.ui.view.defaultSelectableItemBackground
@@ -68,7 +67,17 @@ class SettingsListItem @JvmOverloads constructor(
6867
leadingIcon.gone()
6968
}
7069

71-
betaPill.isVisible = getBoolean(R.styleable.SettingsListItem_showBetaPill, false)
70+
val pillIcon = getInt(R.styleable.SettingsListItem_pillIcon, 0)
71+
if (pillIcon != 0) {
72+
getPillResource(pillIcon)?.let { resId ->
73+
betaPill.setImageResource(resId)
74+
betaPill.show()
75+
} ?: run {
76+
betaPill.gone()
77+
}
78+
} else {
79+
betaPill.gone()
80+
}
7281

7382
val indicatorStatus = Status.from(getInt(R.styleable.SettingsListItem_indicatorStatus, 2))
7483
statusIndicator.setStatus(indicatorStatus)
@@ -77,6 +86,14 @@ class SettingsListItem @JvmOverloads constructor(
7786
}
7887
}
7988

89+
private fun getPillResource(enumValue: Int): Int? {
90+
return when (enumValue) {
91+
1 -> R.drawable.ic_beta_pill
92+
2 -> R.drawable.ic_new_pill
93+
else -> null
94+
}
95+
}
96+
8097
/** Sets the item click listener */
8198
fun setClickListener(onClick: (() -> Unit)?) {
8299
with(binding) {

common/common-ui/src/main/res/layout/component_settings.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
app:indicatorStatus="on"
6565
app:leadingIcon="@drawable/ic_dax_icon"
6666
app:primaryText="Settings List Item with Beta Pill"
67-
app:showBetaPill="true" />
67+
app:pillIcon="betaPill" />
6868

6969
<com.duckduckgo.common.ui.view.listitem.SettingsListItem
7070
android:id="@+id/settingsListItemWithBetaTagAndLongText"
@@ -73,6 +73,15 @@
7373
app:indicatorStatus="on"
7474
app:leadingIcon="@drawable/ic_dax_icon"
7575
app:primaryText="Settings List Item with Beta Pill and a very long piece of text that should hopefully wrap"
76-
app:showBetaPill="true" />
76+
app:pillIcon="betaPill" />
77+
78+
<com.duckduckgo.common.ui.view.listitem.SettingsListItem
79+
android:id="@+id/settingsListItemWithNewTag"
80+
android:layout_width="match_parent"
81+
android:layout_height="wrap_content"
82+
app:indicatorStatus="on"
83+
app:leadingIcon="@drawable/ic_dax_icon"
84+
app:primaryText="Settings List Item with New Pill"
85+
app:pillIcon="newPill" />
7786

7887
</LinearLayout>

common/common-ui/src/main/res/values/attrs-lists.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
<attr name="trailingIcon" format="integer"/>
3636
<attr name="trailingIconTint" format="reference|color"/>
3737
<attr name="showBetaPill" format="boolean"/>
38+
<attr name="pillIcon">
39+
<enum name="none" value="0" />
40+
<!-- Beta Pill -->
41+
<enum name="betaPill" value="1" />
42+
<!-- New Pill -->
43+
<enum name="newPill" value="2" />
44+
</attr>
3845
<attr name="showSwitch" format="boolean"/>
3946
<attr name="switchEnabled" format="boolean"/>
4047
<attr name="leadingIconBackground">

common/common-ui/src/main/res/values/attrs-settings-list_item.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<declare-styleable name="SettingsListItem">
1919
<attr name="leadingIcon" />
2020
<attr name="primaryText" />
21-
<attr name="showBetaPill" />
21+
<attr name="pillIcon" />
2222
<attr name="indicatorStatus" />
2323
</declare-styleable>
2424
</resources>

0 commit comments

Comments
 (0)