From 329a6573463eaaf1b0ebb69d0ed12601a4edaffa Mon Sep 17 00:00:00 2001 From: Daniel Nazareth Date: Mon, 21 Sep 2020 14:39:01 -0300 Subject: [PATCH 1/4] feat: [DSY-1485] add tag component to menu --- .../com/natura/android/menu/MenuView.kt | 18 +++++++++++++ .../src/main/res/layout/ds_menu_view.xml | 27 ++++++++++++++----- designsystem/src/main/res/values/ds_attrs.xml | 2 ++ doc/menu.md | 13 +++++++++ .../sample/test/menu/MenuActivityTest.kt | 6 +++++ sample/src/main/res/layout/activity_menu.xml | 2 ++ .../res/layout/component_menu_alert_tag.xml | 18 +++++++++++++ 7 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 sample/src/main/res/layout/component_menu_alert_tag.xml 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/res/layout/ds_menu_view.xml b/designsystem/src/main/res/layout/ds_menu_view.xml index 9749b227a..bbd3906a2 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 @@ + + + + + + From 8b55232835e08de90b59d96a32a3927ac3cd2226 Mon Sep 17 00:00:00 2001 From: Daniel Nazareth Date: Mon, 21 Sep 2020 16:16:06 -0300 Subject: [PATCH 2/4] feat: [DSY-1485] call methods to change tag information on menu for ExpandableNavigationAdapter.kt --- .../android/navigationview/ExpandableNavigationAdapter.kt | 2 ++ .../kotlin/com/natura/android/navigationview/Navigation.kt | 4 +++- designsystem/src/main/res/layout/ds_menu_view.xml | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) 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..180c65151 100644 --- a/designsystem/src/main/kotlin/com/natura/android/navigationview/ExpandableNavigationAdapter.kt +++ b/designsystem/src/main/kotlin/com/natura/android/navigationview/ExpandableNavigationAdapter.kt @@ -69,6 +69,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..1b48eeeab 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 bbd3906a2..48db68138 100644 --- a/designsystem/src/main/res/layout/ds_menu_view.xml +++ b/designsystem/src/main/res/layout/ds_menu_view.xml @@ -60,7 +60,7 @@ android:layout_height="wrap_content" android:layout_marginTop="@dimen/ds_submenu_text_margin_top_bottom" android:layout_marginEnd="@dimen/ds_spacin_tiny" - android:layout_marginStart="@dimen/ds_spacing_standard" + android:layout_marginStart="?spacingTiny" android:layout_marginBottom="@dimen/ds_submenu_text_margin_top_bottom" app:layout_constrainedWidth="true" android:gravity="center_vertical" @@ -78,7 +78,7 @@ android:id="@+id/ds_menu_tag" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/ds_spacin_tiny" + android:layout_marginEnd="?spacingTiny" app:layout_constraintBottom_toBottomOf="@+id/ds_menu_icon" app:layout_constraintEnd_toStartOf="@+id/ds_menu_arrow" app:layout_constraintStart_toEndOf="@+id/ds_menu_label" From aca7b32681e00c378a38a4c739dae86c41777659 Mon Sep 17 00:00:00 2001 From: Marcella Souza Date: Mon, 21 Sep 2020 16:28:34 -0300 Subject: [PATCH 3/4] =?UTF-8?q?style:=20=F0=9F=92=84=20[DSY-1485]=20adjust?= =?UTF-8?q?ing=20lint=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/com/natura/android/navigationview/Navigation.kt | 2 +- designsystem/src/main/res/layout/ds_menu_view.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 1b48eeeab..65f8f9a6f 100644 --- a/designsystem/src/main/kotlin/com/natura/android/navigationview/Navigation.kt +++ b/designsystem/src/main/kotlin/com/natura/android/navigationview/Navigation.kt @@ -15,7 +15,7 @@ data class NavigationItem( var menuState: MenuView.MenuState = MenuView.MenuState.NONE, val childItems: MutableList = mutableListOf(), val tagLabel: String = "", - val showTag: Boolean = false, + 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 48db68138..c3a685182 100644 --- a/designsystem/src/main/res/layout/ds_menu_view.xml +++ b/designsystem/src/main/res/layout/ds_menu_view.xml @@ -59,7 +59,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="@dimen/ds_submenu_text_margin_top_bottom" - android:layout_marginEnd="@dimen/ds_spacin_tiny" + android:layout_marginEnd="?spacingTiny" android:layout_marginStart="?spacingTiny" android:layout_marginBottom="@dimen/ds_submenu_text_margin_top_bottom" app:layout_constrainedWidth="true" From a000e6b56c45ee108d5764c1cd0f33ce067f6430 Mon Sep 17 00:00:00 2001 From: Daniel Nazareth Date: Mon, 21 Sep 2020 18:56:50 -0300 Subject: [PATCH 4/4] fix: [DSY-1485] fix tag not showing when scrolling list of menus --- .../android/navigationview/ExpandableNavigationAdapter.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 180c65151..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 ->