diff --git a/designsystem/src/main/kotlin/com/natura/android/menu/MenuView.kt b/designsystem/src/main/kotlin/com/natura/android/menu/MenuView.kt index 9dddd7db9..a2cc3b714 100644 --- a/designsystem/src/main/kotlin/com/natura/android/menu/MenuView.kt +++ b/designsystem/src/main/kotlin/com/natura/android/menu/MenuView.kt @@ -12,6 +12,7 @@ import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat import com.natura.android.R import com.natura.android.ext.setVisibilityFromBoolean +import com.natura.android.tag.Tag @SuppressLint("CustomViewStyleable") class MenuView @JvmOverloads constructor( @@ -24,6 +25,7 @@ class MenuView @JvmOverloads constructor( private val labelContainer by lazy { findViewById(R.id.ds_menu_view_background) } private val iconMenu by lazy { findViewById(R.id.ds_menu_icon) } private val iconArrowMenu by lazy { findViewById(R.id.ds_menu_arrow) } + private val menuTag by lazy { findViewById(R.id.ds_menu_tag) } private var selectedDrawable: Int private var openedDrawable: Int @@ -40,6 +42,12 @@ class MenuView @JvmOverloads constructor( setMenuIconImage(value) } + var tagLabel: String? = "" + set(value) { + field = value + menuTag.setLabel(value) + } + init { View.inflate(context, R.layout.ds_menu_view, this) @@ -69,6 +77,12 @@ class MenuView @JvmOverloads constructor( val enabled = typedArray.getBoolean(R.styleable.ds_menu_menu_is_enabled, true) val isOpened = typedArray.getBoolean(R.styleable.ds_menu_menu_is_opened, false) + val hasTag = typedArray.getBoolean(R.styleable.ds_menu_menu_has_tag, false) + val tagText = typedArray.getString(R.styleable.ds_menu_menu_tag_label) + + showTag(hasTag) + tagLabel = tagText + typedArray.recycle() configLabel(labelText, labelColor, labelSize) @@ -83,6 +97,10 @@ class MenuView @JvmOverloads constructor( isEnabled = enabled } + fun showTag(hasTag: Boolean) { + menuTag.setVisibilityFromBoolean(hasTag, View.GONE) + } + override fun setSelected(isSelected: Boolean) { super.setSelected(isSelected) changeBackground(isSelected, selectedDrawable) diff --git a/designsystem/src/main/kotlin/com/natura/android/navigationview/ExpandableNavigationAdapter.kt b/designsystem/src/main/kotlin/com/natura/android/navigationview/ExpandableNavigationAdapter.kt index 1f464edec..541d8920a 100644 --- a/designsystem/src/main/kotlin/com/natura/android/navigationview/ExpandableNavigationAdapter.kt +++ b/designsystem/src/main/kotlin/com/natura/android/navigationview/ExpandableNavigationAdapter.kt @@ -59,8 +59,7 @@ class ExpandableNavigationAdapter( convertView: View?, parent: ViewGroup? ): View { - val parentView = convertView - ?: LayoutInflater.from(context).inflate(R.layout.ds_menu_item, null) + val parentView = LayoutInflater.from(context).inflate(R.layout.ds_menu_item, null) val groupView = parentView.findViewById(R.id.menu_item) navigationItems[groupPosition].let { item -> @@ -69,6 +68,8 @@ class ExpandableNavigationAdapter( icon = item.iconText showArrow(item.hasSubMenu) configStateMenu(item.menuState) + showTag(item.showTag) + tagLabel = item.tagLabel } } diff --git a/designsystem/src/main/kotlin/com/natura/android/navigationview/Navigation.kt b/designsystem/src/main/kotlin/com/natura/android/navigationview/Navigation.kt index 5ad6ebf96..65f8f9a6f 100644 --- a/designsystem/src/main/kotlin/com/natura/android/navigationview/Navigation.kt +++ b/designsystem/src/main/kotlin/com/natura/android/navigationview/Navigation.kt @@ -13,7 +13,9 @@ data class NavigationItem( var hasSubMenu: Boolean = true, var tagAnalytics: String = "", var menuState: MenuView.MenuState = MenuView.MenuState.NONE, - val childItems: MutableList = mutableListOf() + val childItems: MutableList = mutableListOf(), + val tagLabel: String = "", + val showTag: Boolean = false ) : Navigation(id) { fun indexOfChildItemId(childId: String) = childItems.indexOfFirst { it.id == childId } } diff --git a/designsystem/src/main/res/layout/ds_menu_view.xml b/designsystem/src/main/res/layout/ds_menu_view.xml index 9749b227a..c3a685182 100644 --- a/designsystem/src/main/res/layout/ds_menu_view.xml +++ b/designsystem/src/main/res/layout/ds_menu_view.xml @@ -36,12 +36,9 @@ android:id="@+id/ds_menu_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/ds_spacing_standard" - android:layout_marginRight="@dimen/ds_spacing_standard" app:srcCompat="@drawable/outlined_default_mockup" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="@id/guide_start" - app:layout_constraintEnd_toStartOf="@+id/ds_menu_label" app:layout_constraintTop_toTopOf="parent" app:tint="?colorOnSurface" /> @@ -59,20 +56,36 @@ + app:layout_constraintHorizontal_chainStyle="packed" + tools:text="Sub Menu item with a big name to test what happens" /> + + + + diff --git a/doc/menu.md b/doc/menu.md index ea45d9d7b..ed0884c0e 100644 --- a/doc/menu.md +++ b/doc/menu.md @@ -12,4 +12,17 @@ You should use it to compose a catalog of options in applications ### How to use it? WIP +Following there's an example of a menu with a tag code: +```android + +``` diff --git a/sample/src/androidTest/kotlin/com/natura/android/sample/test/menu/MenuActivityTest.kt b/sample/src/androidTest/kotlin/com/natura/android/sample/test/menu/MenuActivityTest.kt index 74c033a3b..a7ebb1020 100644 --- a/sample/src/androidTest/kotlin/com/natura/android/sample/test/menu/MenuActivityTest.kt +++ b/sample/src/androidTest/kotlin/com/natura/android/sample/test/menu/MenuActivityTest.kt @@ -42,6 +42,12 @@ class MenuActivityTest { checkView(view) } + @Test + fun verifyMenuWhenHasTag() { + val view: View = inflater.inflate(R.layout.component_menu_alert_tag, null, false) + checkView(view) + } + @UiThreadTest @Test fun verifyMenuWhenIsOpened() { diff --git a/sample/src/main/res/layout/activity_menu.xml b/sample/src/main/res/layout/activity_menu.xml index 291004a83..018a9609a 100644 --- a/sample/src/main/res/layout/activity_menu.xml +++ b/sample/src/main/res/layout/activity_menu.xml @@ -14,4 +14,6 @@ + + diff --git a/sample/src/main/res/layout/component_menu_alert_tag.xml b/sample/src/main/res/layout/component_menu_alert_tag.xml new file mode 100644 index 000000000..d22701ba1 --- /dev/null +++ b/sample/src/main/res/layout/component_menu_alert_tag.xml @@ -0,0 +1,18 @@ + + + + + +