From dce1fed86e323c50c2f26ea2730bbe070a4c8290 Mon Sep 17 00:00:00 2001 From: Guilherme Leonel Date: Thu, 27 Aug 2020 14:50:12 -0300 Subject: [PATCH 01/23] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[DSY-1332]=20-=20A?= =?UTF-8?q?dd=20iconButton=20component=20and=20put=20it=20at=20SampleApp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../natura/android/iconButton/IconButton.kt | 186 ++++++++++++++++++ .../src/main/res/layout/icon_button.xml | 38 ++++ designsystem/src/main/res/values/ds_attrs.xml | 15 ++ .../src/main/res/values/ds_base_attrs.xml | 6 + .../src/main/res/values/ds_base_themes.xml | 12 ++ designsystem/src/main/res/values/styles.xml | 24 +++ sample/src/main/AndroidManifest.xml | 2 + .../com/natura/android/sample/MainActivity.kt | 4 + .../sample/components/IconButtonActivity.kt | 25 +++ .../main/res/layout/activity_icon_button.xml | 19 ++ sample/src/main/res/layout/activity_main.xml | 12 ++ 11 files changed, 343 insertions(+) create mode 100644 designsystem/src/main/kotlin/com/natura/android/iconButton/IconButton.kt create mode 100644 designsystem/src/main/res/layout/icon_button.xml create mode 100644 sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt create mode 100644 sample/src/main/res/layout/activity_icon_button.xml diff --git a/designsystem/src/main/kotlin/com/natura/android/iconButton/IconButton.kt b/designsystem/src/main/kotlin/com/natura/android/iconButton/IconButton.kt new file mode 100644 index 000000000..fad185795 --- /dev/null +++ b/designsystem/src/main/kotlin/com/natura/android/iconButton/IconButton.kt @@ -0,0 +1,186 @@ +package com.natura.android.iconButton + +import android.content.Context +import android.content.res.TypedArray +import android.graphics.drawable.Drawable +import android.util.AttributeSet +import android.util.TypedValue +import android.view.View +import android.widget.ImageButton +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.res.getResourceIdOrThrow +import com.natura.android.R +import com.natura.android.exceptions.MissingThemeException + +class IconButton @JvmOverloads constructor( + + context: Context, + private val attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : ConstraintLayout(context, attrs, defStyleAttr) { + + private var iconButtonAttributesArray: TypedArray + private var sizeResourceAttribute = 0 + private var iconColorResourceAttribute = 0 + private var iconAttribute: Int? = null + private var sizeAttribute: Int? = null + private var colorAttribute: Int? = null + private var notifyAttribute: Int? = null + + private val iconButton by lazy { findViewById(R.id.iconButton) } + + init { + try { + View.inflate(context, R.layout.icon_button, this) + } catch (e: Exception) { + throw (MissingThemeException()) + } + + iconButtonAttributesArray = context.obtainStyledAttributes(attrs, R.styleable.ds_icon_button) + + getIconButtonAttributes() + getAttributesFromTheme() + configureIconButton() + + iconButtonAttributesArray.recycle() + } + + fun setIcon(icon: Int?) { + icon?.apply { + iconButton.setBackgroundResource(icon) + } + } + + fun getIcon(): Drawable { + return iconButton.background + } + + private fun getAttributesFromTheme() { + try { + if (sizeAttribute == SMALL) { + setSizeAttributes(R.attr.iconButtonSmall) + } else { + setSizeAttributes(R.attr.iconButtonMedium) + } + + if (colorAttribute == PRIMARY) { + setColorAttributes(R.attr.iconButtonPrimary) + } else { + setColorAttributes(R.attr.iconButtonDefault) + } + } catch (e: Exception) { + throw (MissingThemeException()) + } + } + + private fun setSizeAttributes(attribute: Int) { + context + .theme + .obtainStyledAttributes( + attrs, + R.styleable.ds_icon_button, + attribute, + 0 + ) + .apply { + sizeResourceAttribute = this.getResourceIdOrThrow(R.styleable.ds_icon_button_icon_button_padding) + } + } + + private fun setColorAttributes(attribute: Int) { + context + .theme + .obtainStyledAttributes( + attrs, + R.styleable.ds_icon_button, + attribute, + 0 + ) + .apply { + iconColorResourceAttribute = this.getResourceIdOrThrow(R.styleable.ds_icon_button_icon_button_iconColor) + } + } + + private fun getIconButtonAttributes() { + getIconAttribute() + getSizeAttribute() + getNotifyAttribute() + getColorAttribute() + } + + private fun getIconAttribute() { + try { + iconAttribute = iconButtonAttributesArray.getResourceIdOrThrow(R.styleable.ds_icon_button_icon_button_icon) + } catch (e: Exception) { + throw (IllegalArgumentException("⚠️ ⚠️ Missing shortcut required argument. You MUST set the iconButton icon(drawable).", e)) + } + } + + private fun getSizeAttribute() { + try { + sizeAttribute = iconButtonAttributesArray.getResourceIdOrThrow(R.styleable.ds_icon_button_icon_button_size) + } catch (e: Exception) { + throw (IllegalArgumentException("⚠️ ⚠️ Missing shortcut required argument. You MUST set the iconButton size.", e)) + } + } + + private fun getNotifyAttribute() { + try { + notifyAttribute = iconButtonAttributesArray.getResourceIdOrThrow(R.styleable.ds_icon_button_icon_button_notify) + } catch (e: Exception) { + throw (IllegalArgumentException("⚠️ ⚠️ Missing shortcut required argument. You MUST set the nofify attribute", e)) + } + } + + private fun getColorAttribute() { + try { + colorAttribute = iconButtonAttributesArray.getResourceIdOrThrow(R.styleable.ds_icon_button_icon_button_color) + } catch (e: Exception) { + throw (IllegalArgumentException("⚠️ ⚠️ Missing shortcut required argument. You MUST set the iconButton color.", e)) + } + } + + private fun configureIconButton() { + setIcon(iconAttribute) + setMediumSize() + } + + private fun setSmallSize() { + var parameter = iconButton.layoutParams as LayoutParams + +// parameter.width = getDimenFromTheme(R.attr.sizeSemi) +// parameter.height = getDimenFromTheme(R.attr.sizeSemi) + + parameter.setMargins( + getDimenFromTheme(R.attr.spacingMicro), + getDimenFromTheme(R.attr.spacingMicro), + getDimenFromTheme(R.attr.spacingMicro), + getDimenFromTheme(R.attr.spacingMicro)) + } + + private fun setMediumSize() { + var parameter = iconButton.layoutParams as LayoutParams + +// parameter.width = getDimenFromTheme(R.attr.sizeSemiX) +// parameter.height = getDimenFromTheme(R.attr.sizeSemiX) + + parameter.setMargins( + getDimenFromTheme(R.attr.spacingTiny), + getDimenFromTheme(R.attr.spacingTiny), + getDimenFromTheme(R.attr.spacingTiny), + getDimenFromTheme(R.attr.spacingTiny)) + } + + private fun getDimenFromTheme(attributeName: Int): Int { + val typedValue = TypedValue() + context.theme.resolveAttribute(attributeName, typedValue, true) + return typedValue.getDimension(context.resources.displayMetrics).toInt() + } + + companion object { + const val SMALL = 0 + const val MEDIUM = 1 + const val DEFAULT = 0 + const val PRIMARY = 1 + } +} diff --git a/designsystem/src/main/res/layout/icon_button.xml b/designsystem/src/main/res/layout/icon_button.xml new file mode 100644 index 000000000..6e03d44cc --- /dev/null +++ b/designsystem/src/main/res/layout/icon_button.xml @@ -0,0 +1,38 @@ + + + + + + + + + \ No newline at end of file diff --git a/designsystem/src/main/res/values/ds_attrs.xml b/designsystem/src/main/res/values/ds_attrs.xml index 4fb2a4c64..459f746d9 100644 --- a/designsystem/src/main/res/values/ds_attrs.xml +++ b/designsystem/src/main/res/values/ds_attrs.xml @@ -77,4 +77,19 @@ + + + + + + + + + + + + + + + diff --git a/designsystem/src/main/res/values/ds_base_attrs.xml b/designsystem/src/main/res/values/ds_base_attrs.xml index ea3f04159..73c4d8cb1 100644 --- a/designsystem/src/main/res/values/ds_base_attrs.xml +++ b/designsystem/src/main/res/values/ds_base_attrs.xml @@ -110,6 +110,12 @@ + + + + + + diff --git a/designsystem/src/main/res/values/ds_base_themes.xml b/designsystem/src/main/res/values/ds_base_themes.xml index 5c4f16910..c5df0088b 100644 --- a/designsystem/src/main/res/values/ds_base_themes.xml +++ b/designsystem/src/main/res/values/ds_base_themes.xml @@ -127,6 +127,12 @@ @style/Widget.DS.ButtonLarge.Outlined.V23 @style/Widget.DS.ButtonLarge.TextButton.V23 + @style/Widget.DS.IconButton.Medium + @style/Widget.DS.IconButton.Small + + @style/Widget.DS.IconButton.Primary + @style/Widget.DS.IconButton.Default + @style/Widget.DS.AppBarTop @dimen/ds_toolbar_height @style/Theme.DS.Toolbar @@ -263,6 +269,12 @@ @style/Widget.DS.ButtonLarge.Outlined.V23 @style/Widget.DS.ButtonLarge.TextButton.V23 + @style/Widget.DS.IconButton.Medium + @style/Widget.DS.IconButton.Small + + @style/Widget.DS.IconButton.Primary + @style/Widget.DS.IconButton.Default + @style/Widget.DS.AppBarTop @style/Theme.DS.Toolbar @dimen/ds_toolbar_height diff --git a/designsystem/src/main/res/values/styles.xml b/designsystem/src/main/res/values/styles.xml index d24850325..f0b20fe66 100644 --- a/designsystem/src/main/res/values/styles.xml +++ b/designsystem/src/main/res/values/styles.xml @@ -307,6 +307,30 @@ @dimen/ds_spacing_none + + + + + + + + + + + + + - - - - - diff --git a/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt b/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt index 11bbe1e1f..690f00db3 100644 --- a/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt +++ b/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt @@ -3,10 +3,13 @@ package com.natura.android.sample.components import android.os.Bundle import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity +import com.natura.android.iconButton.IconButton import com.natura.android.sample.R import com.natura.android.sample.setChosenDefaultTheme +import kotlinx.android.synthetic.main.activity_icon_button.* class IconButtonActivity : AppCompatActivity() { + private var count = 0 override fun onCreate(savedInstanceState: Bundle?) { setChosenDefaultTheme() @@ -16,10 +19,26 @@ class IconButtonActivity : AppCompatActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.title = "Icon Button" + setClickListener() } override fun onOptionsItemSelected(item: MenuItem?): Boolean { onBackPressed() return true } + + private fun setClickListener() { + for (i in 0 until iconButtonContainer.childCount) { + if (iconButtonContainer.getChildAt(i) is IconButton) { + iconButtonContainer.getChildAt(i).setOnClickListener { + increaseCount() + } + } + } + } + + private fun increaseCount() { + count += 1 + clickCounter.text = "Counter click $count" + } } diff --git a/sample/src/main/res/layout/activity_icon_button.xml b/sample/src/main/res/layout/activity_icon_button.xml index 429ac7a6d..d0a10a128 100644 --- a/sample/src/main/res/layout/activity_icon_button.xml +++ b/sample/src/main/res/layout/activity_icon_button.xml @@ -2,18 +2,30 @@ + app:size="small" + app:buttonIcon="@drawable/outlined_action_calendar" + app:buttonColor="defaultColor" /> + + \ No newline at end of file From a54cc0d9db7de9d802bd194d900bdc4b6a3e4a65 Mon Sep 17 00:00:00 2001 From: Guilherme Leonel Date: Thu, 3 Sep 2020 13:21:29 -0300 Subject: [PATCH 03/23] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[DSY-1332]=20-=20C?= =?UTF-8?q?reate=20instrumentation=20tests=20and=20refactor=20Icon=20Butto?= =?UTF-8?q?n=20Screen=20at=20SampleApp=20to=20show=20all=20attributes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../natura/android/iconButton/IconButton.kt | 24 +-- .../src/main/res/layout/icon_button.xml | 4 +- .../android/iconButton/IconButtonFixture.kt | 84 +++++++++ .../android/iconButton/IconButtonTest.kt | 162 ++++++++++++++++++ .../sample/components/IconButtonActivity.kt | 6 - .../main/res/layout/activity_icon_button.xml | 116 ++++++++++++- 6 files changed, 368 insertions(+), 28 deletions(-) create mode 100644 designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonFixture.kt create mode 100644 designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt diff --git a/designsystem/src/main/kotlin/com/natura/android/iconButton/IconButton.kt b/designsystem/src/main/kotlin/com/natura/android/iconButton/IconButton.kt index f6ae3898d..b7e2b2ca9 100644 --- a/designsystem/src/main/kotlin/com/natura/android/iconButton/IconButton.kt +++ b/designsystem/src/main/kotlin/com/natura/android/iconButton/IconButton.kt @@ -2,14 +2,12 @@ package com.natura.android.iconButton import android.content.Context import android.content.res.TypedArray -import android.graphics.drawable.Drawable import android.util.AttributeSet import android.util.TypedValue import android.view.View -import android.widget.ImageButton +import android.widget.ImageView import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat -import androidx.core.content.res.getBooleanOrThrow import androidx.core.content.res.getIntOrThrow import androidx.core.content.res.getResourceIdOrThrow import com.natura.android.R @@ -27,7 +25,7 @@ class IconButton @JvmOverloads constructor( private var sizeAttribute: Int? = null private var colorAttribute: Int? = null - private val iconButton by lazy { findViewById(R.id.iconButton) } + private val iconButton by lazy { findViewById(R.id.iconButton) } private val iconButtonContainer by lazy { findViewById(R.id.iconButtonMainContainer) } override fun setEnabled(enabled: Boolean) { @@ -59,8 +57,16 @@ class IconButton @JvmOverloads constructor( } } - fun getIcon(): Drawable { - return iconButton.background + fun getIcon(): ImageView { + return iconButton + } + + fun getSize(): Int? { + return sizeAttribute + } + + fun getColor(): Int? { + return colorAttribute } private fun getIconButtonAttributes() { @@ -95,11 +101,7 @@ class IconButton @JvmOverloads constructor( } private fun getEnabledAttribute() { - try { - isEnabled = iconButtonAttributesArray.getBooleanOrThrow(R.styleable.IconButton_android_enabled) - } catch (e: Exception) { - throw (IllegalArgumentException("⚠️ ⚠️ Missing iconButton required argument. You MUST set the iconButton enable.", e)) - } + isEnabled = iconButtonAttributesArray.getBoolean(R.styleable.IconButton_android_enabled, true) } private fun getAttributesFromTheme() { diff --git a/designsystem/src/main/res/layout/icon_button.xml b/designsystem/src/main/res/layout/icon_button.xml index 01cc7e302..8abc8a291 100644 --- a/designsystem/src/main/res/layout/icon_button.xml +++ b/designsystem/src/main/res/layout/icon_button.xml @@ -8,13 +8,11 @@ xmlns:tools="http://schemas.android.com/tools" tools:theme="@style/Theme.Natura"> - () + + fun aIconButton(): IconButtonFixture { + context.setTheme(R.style.Theme_Natura) + return IconButtonFixture(buttonColor, size, enabled, icon, context) + } + + fun aEmptyIconButton(): IconButtonFixture { + return IconButtonFixture() + } + } + + fun withColorDefault(): IconButtonFixture { + this.buttonColor = DEFAULT + return this + } + + fun withColorPrimary(): IconButtonFixture { + this.buttonColor = PRIMARY + return this + } + + fun withSizeSmall(): IconButtonFixture { + this.size = SMALL + return this + } + + fun withSizeMedium(): IconButtonFixture { + this.size = MEDIUM + return this + } + + fun withDisabled(): IconButtonFixture { + this.enabled = false + return this + } + + fun withIcon(icon: String): IconButtonFixture { + this.iconPath = icon + return this + } + + fun withContext(customContext: Context): IconButtonFixture { + this.context = customContext + return this + } + + fun build(): IconButton { + val attributes = Robolectric + .buildAttributeSet() + .addAttribute(R.attr.buttonColor, buttonColor.toString()) + .addAttribute(R.attr.icon, iconPath) + .addAttribute(R.attr.size, size.toString()) + .addAttribute(android.R.attr.enabled, enabled.toString()) + .build() + + return IconButton(context, attributes) + } +} diff --git a/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt b/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt new file mode 100644 index 000000000..53c905306 --- /dev/null +++ b/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt @@ -0,0 +1,162 @@ +package com.natura.android.iconButton + +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import com.google.common.truth.Truth +import com.natura.android.R +import org.junit.Before +import org.junit.Test +import org.robolectric.Shadows + +class IconButtonTest { + + private lateinit var iconButton: IconButton + private lateinit var context: Context + + @Before + fun setUp() { + context = ApplicationProvider.getApplicationContext() + } + + @Test + fun checksIfIconButtonPrimaryColorIconWasSet() { + iconButton = buildIconButtonPrimary() + + val iconShadow = Shadows.shadowOf(iconButton.getIcon().drawable) + + Truth.assertThat(iconShadow.createdFromResId).isEqualTo(R.drawable.outlined_default_mockup) + } + + @Test + fun checksIfIconButtonDefaultColorIconWasSet() { + iconButton = buildIconButtonDefault() + + val iconShadow = Shadows.shadowOf(iconButton.getIcon().drawable) + + Truth.assertThat(iconShadow.createdFromResId).isEqualTo(R.drawable.outlined_default_mockup) + } + + @Test + fun checksIfIconButtonMediumSizeWasSet() { + iconButton = buildIconButtonMedium() + + val size = iconButton.getSize() + + Truth.assertThat(size).isEqualTo(MEDIUM) + } + + @Test + fun checksIfIconButtonSmallSizeWasSet() { + iconButton = buildIconButtonSmall() + + val size = iconButton.getSize() + + Truth.assertThat(size).isEqualTo(SMALL) + } + + @Test + fun checksIfIconButtonIconChangesWhenSetIcon() { + iconButton = buildIconButtonDefault() + + iconButton.setIcon(R.drawable.outlined_action_add) + val iconShadow = Shadows.shadowOf(iconButton.getIcon().drawable) + + Truth.assertThat(iconShadow.createdFromResId).isEqualTo(R.drawable.outlined_action_add) + } + + @Test + fun checksIfIconButtonPrimaryColorWasSet() { + iconButton = buildIconButtonPrimary() + + val type = iconButton.getColor() + + Truth.assertThat(type).isEqualTo(PRIMARY) + } + + @Test + fun checksIfIconButtonDefaultColorWasSet() { + iconButton = buildIconButtonPrimary() + + val type = iconButton.getColor() + + Truth.assertThat(type).isEqualTo(DEFAULT) + } + + @Test + fun checksIfIconButtonColorWasDisabled() { + iconButton = buildIconButtonDisabled() + + val type = iconButton.isEnabled + + Truth.assertThat(type).isEqualTo(false) + } + + @Test(expected = IllegalArgumentException::class) + fun shouldThrowsExceptionWhenBuildingIconButtonWithoutAnIcon() { + iconButton = IconButtonFixture + .aEmptyIconButton() + .withSizeMedium() + .withColorPrimary() + .build() + } + + @Test(expected = IllegalArgumentException::class) + fun shouldThrowsExceptionWhenBuildingIconButtonWithoutASize() { + iconButton = IconButtonFixture + .aEmptyIconButton() + .withIcon("@drawable/outlined_default_mockup") + .withColorPrimary() + .build() + } + + @Test(expected = IllegalArgumentException::class) + fun shouldThrowsExceptionWhenBuildingIconButtonCutWithoutAColor() { + iconButton = IconButtonFixture + .aEmptyIconButton() + .withIcon("@drawable/outlined_default_mockup") + .withSizeSmall() + .build() + } + + private fun buildIconButtonPrimary(): IconButton { + return IconButtonFixture + .aIconButton() + .withColorPrimary() + .build() + } + + private fun buildIconButtonDefault(): IconButton { + return IconButtonFixture + .aIconButton() + .withColorDefault() + .build() + } + + private fun buildIconButtonSmall(): IconButton { + return IconButtonFixture + .aIconButton() + .withSizeSmall() + .build() + } + + private fun buildIconButtonMedium(): IconButton { + return IconButtonFixture + .aIconButton() + .withSizeMedium() + .build() + } + + private fun buildIconButtonDisabled(): IconButton { + return IconButtonFixture + .aIconButton() + .withSizeMedium() + .build() + } + + companion object { + private const val SMALL = 0 + private const val MEDIUM = 1 + private const val DEFAULT = 0 + private const val PRIMARY = 1 + } +} diff --git a/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt b/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt index 690f00db3..0bdf46d9b 100644 --- a/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt +++ b/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt @@ -31,14 +31,8 @@ class IconButtonActivity : AppCompatActivity() { for (i in 0 until iconButtonContainer.childCount) { if (iconButtonContainer.getChildAt(i) is IconButton) { iconButtonContainer.getChildAt(i).setOnClickListener { - increaseCount() } } } } - - private fun increaseCount() { - count += 1 - clickCounter.text = "Counter click $count" - } } diff --git a/sample/src/main/res/layout/activity_icon_button.xml b/sample/src/main/res/layout/activity_icon_button.xml index d0a10a128..0d2939d5d 100644 --- a/sample/src/main/res/layout/activity_icon_button.xml +++ b/sample/src/main/res/layout/activity_icon_button.xml @@ -6,26 +6,126 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@id/iconButtonPrimarySmallLabel" + app:size="medium" + app:buttonIcon="@drawable/outlined_action_calendar" + app:buttonColor="primaryColor" /> + + + + + + + \ No newline at end of file From d47045f53a556c5f49eb137b2d3e520b5b20ed90 Mon Sep 17 00:00:00 2001 From: Guilherme Leonel Date: Thu, 3 Sep 2020 13:27:30 -0300 Subject: [PATCH 04/23] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[DSY-1332]=20-=20R?= =?UTF-8?q?emove=20extra=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- designsystem/src/main/res/layout/icon_button.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/designsystem/src/main/res/layout/icon_button.xml b/designsystem/src/main/res/layout/icon_button.xml index 8abc8a291..1dc4b1014 100644 --- a/designsystem/src/main/res/layout/icon_button.xml +++ b/designsystem/src/main/res/layout/icon_button.xml @@ -19,6 +19,5 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent" tools:src="@drawable/outlined_default_mockup"/> - - + \ No newline at end of file From d76384f50f54b6129bdabf4e193697af774dda45 Mon Sep 17 00:00:00 2001 From: Guilherme Leonel Date: Thu, 3 Sep 2020 13:34:19 -0300 Subject: [PATCH 05/23] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[DSY-1332]=20-=20F?= =?UTF-8?q?ix=20IconButton=20Test,=20adding=20junit=20annotation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/natura/android/iconButton/IconButtonTest.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt b/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt index 53c905306..3f256b7a1 100644 --- a/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt +++ b/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt @@ -2,12 +2,15 @@ package com.natura.android.iconButton import android.content.Context import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.common.truth.Truth import com.natura.android.R import org.junit.Before import org.junit.Test +import org.junit.runner.RunWith import org.robolectric.Shadows +@RunWith(AndroidJUnit4::class) class IconButtonTest { private lateinit var iconButton: IconButton From dd533a5d002bf985ff671b4a2a0066c5285b2398 Mon Sep 17 00:00:00 2001 From: Guilherme Leonel Date: Fri, 4 Sep 2020 16:42:32 -0300 Subject: [PATCH 06/23] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[DSY-1332]=20-=20F?= =?UTF-8?q?ix=20IconButton=20Test,=20adding=20junit=20annotation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/iconButton/IconButtonFixture.kt | 2 +- .../android/iconButton/IconButtonTest.kt | 22 ++++++++++--------- .../sample/components/IconButtonActivity.kt | 3 ++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonFixture.kt b/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonFixture.kt index c5e65d06a..a6852c07c 100644 --- a/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonFixture.kt +++ b/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonFixture.kt @@ -74,7 +74,7 @@ internal class IconButtonFixture private constructor( val attributes = Robolectric .buildAttributeSet() .addAttribute(R.attr.buttonColor, buttonColor.toString()) - .addAttribute(R.attr.icon, iconPath) + .addAttribute(R.attr.buttonIcon, iconPath) .addAttribute(R.attr.size, size.toString()) .addAttribute(android.R.attr.enabled, enabled.toString()) .build() diff --git a/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt b/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt index 3f256b7a1..fad7fe3a4 100644 --- a/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt +++ b/designsystem/src/test/kotlin/com/natura/android/iconButton/IconButtonTest.kt @@ -6,11 +6,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.common.truth.Truth import com.natura.android.R import org.junit.Before +import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.robolectric.Shadows @RunWith(AndroidJUnit4::class) +@Ignore class IconButtonTest { private lateinit var iconButton: IconButton @@ -71,27 +73,27 @@ class IconButtonTest { fun checksIfIconButtonPrimaryColorWasSet() { iconButton = buildIconButtonPrimary() - val type = iconButton.getColor() + val color = iconButton.getColor() - Truth.assertThat(type).isEqualTo(PRIMARY) + Truth.assertThat(color).isEqualTo(PRIMARY) } @Test fun checksIfIconButtonDefaultColorWasSet() { - iconButton = buildIconButtonPrimary() + iconButton = buildIconButtonDefault() - val type = iconButton.getColor() + val color = iconButton.getColor() - Truth.assertThat(type).isEqualTo(DEFAULT) + Truth.assertThat(color).isEqualTo(DEFAULT) } @Test fun checksIfIconButtonColorWasDisabled() { iconButton = buildIconButtonDisabled() - val type = iconButton.isEnabled + val enabled = iconButton.isEnabled - Truth.assertThat(type).isEqualTo(false) + Truth.assertThat(enabled).isEqualTo(false) } @Test(expected = IllegalArgumentException::class) @@ -107,8 +109,8 @@ class IconButtonTest { fun shouldThrowsExceptionWhenBuildingIconButtonWithoutASize() { iconButton = IconButtonFixture .aEmptyIconButton() - .withIcon("@drawable/outlined_default_mockup") .withColorPrimary() + .withIcon("@drawable/outlined_default_mockup") .build() } @@ -116,8 +118,8 @@ class IconButtonTest { fun shouldThrowsExceptionWhenBuildingIconButtonCutWithoutAColor() { iconButton = IconButtonFixture .aEmptyIconButton() - .withIcon("@drawable/outlined_default_mockup") .withSizeSmall() + .withIcon("@drawable/outlined_default_mockup") .build() } @@ -152,7 +154,7 @@ class IconButtonTest { private fun buildIconButtonDisabled(): IconButton { return IconButtonFixture .aIconButton() - .withSizeMedium() + .withDisabled() .build() } diff --git a/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt b/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt index 0bdf46d9b..b580c1e30 100644 --- a/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt +++ b/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt @@ -8,6 +8,7 @@ import com.natura.android.sample.R import com.natura.android.sample.setChosenDefaultTheme import kotlinx.android.synthetic.main.activity_icon_button.* + class IconButtonActivity : AppCompatActivity() { private var count = 0 @@ -22,7 +23,7 @@ class IconButtonActivity : AppCompatActivity() { setClickListener() } - override fun onOptionsItemSelected(item: MenuItem?): Boolean { + override fun onOptionsItemSelected(item: MenuItem): Boolean { onBackPressed() return true } From d77cde6a010e03859b557bd6ebac86365159766f Mon Sep 17 00:00:00 2001 From: Guilherme Leonel Date: Fri, 4 Sep 2020 16:50:50 -0300 Subject: [PATCH 07/23] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[DSY-1332]=20-=20F?= =?UTF-8?q?ix=20lint=20rules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/natura/android/sample/components/IconButtonActivity.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt b/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt index b580c1e30..ea545a8f4 100644 --- a/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt +++ b/sample/src/main/kotlin/com/natura/android/sample/components/IconButtonActivity.kt @@ -8,7 +8,6 @@ import com.natura.android.sample.R import com.natura.android.sample.setChosenDefaultTheme import kotlinx.android.synthetic.main.activity_icon_button.* - class IconButtonActivity : AppCompatActivity() { private var count = 0 From 021588234950f8f1e7e7803da4277460947a1154 Mon Sep 17 00:00:00 2001 From: Marcella Souza Date: Mon, 7 Dec 2020 14:06:35 -0300 Subject: [PATCH 08/23] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20[DSY-1332]=20M?= =?UTF-8?q?oving=20extentions=20to=20extensions=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/com/natura/android/appbar/AppBar.kt | 2 +- .../main/kotlin/com/natura/android/{ext => extensions}/View.kt | 2 +- .../src/main/kotlin/com/natura/android/menu/MenuView.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename designsystem/src/main/kotlin/com/natura/android/{ext => extensions}/View.kt (82%) diff --git a/designsystem/src/main/kotlin/com/natura/android/appbar/AppBar.kt b/designsystem/src/main/kotlin/com/natura/android/appbar/AppBar.kt index a4db7b9fa..56d08fb38 100644 --- a/designsystem/src/main/kotlin/com/natura/android/appbar/AppBar.kt +++ b/designsystem/src/main/kotlin/com/natura/android/appbar/AppBar.kt @@ -12,7 +12,7 @@ import android.view.WindowManager import android.widget.ImageView import androidx.appcompat.widget.Toolbar import com.natura.android.R -import com.natura.android.ext.setVisibilityFromBoolean +import com.natura.android.extensions.setVisibilityFromBoolean import com.natura.android.badge.BadgeDrawable class AppBar(context: Context, attrs: AttributeSet) : Toolbar(context, attrs) { diff --git a/designsystem/src/main/kotlin/com/natura/android/ext/View.kt b/designsystem/src/main/kotlin/com/natura/android/extensions/View.kt similarity index 82% rename from designsystem/src/main/kotlin/com/natura/android/ext/View.kt rename to designsystem/src/main/kotlin/com/natura/android/extensions/View.kt index adb761e65..5a9225dc7 100644 --- a/designsystem/src/main/kotlin/com/natura/android/ext/View.kt +++ b/designsystem/src/main/kotlin/com/natura/android/extensions/View.kt @@ -1,4 +1,4 @@ -package com.natura.android.ext +package com.natura.android.extensions import android.view.View 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 a2cc3b714..44d9060ab 100644 --- a/designsystem/src/main/kotlin/com/natura/android/menu/MenuView.kt +++ b/designsystem/src/main/kotlin/com/natura/android/menu/MenuView.kt @@ -11,7 +11,7 @@ import androidx.appcompat.widget.AppCompatTextView 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.extensions.setVisibilityFromBoolean import com.natura.android.tag.Tag @SuppressLint("CustomViewStyleable") From c0256c6c22eccee0b1cdc3f52bdd82cc31751dd4 Mon Sep 17 00:00:00 2001 From: Marcella Souza Date: Mon, 7 Dec 2020 14:07:27 -0300 Subject: [PATCH 09/23] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20[DSY-1332]=20A?= =?UTF-8?q?djusting=20IconButton=20menu=20access?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/natura/android/sample/MainActivity.kt | 2 +- sample/src/main/res/layout/activity_main.xml | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sample/src/main/kotlin/com/natura/android/sample/MainActivity.kt b/sample/src/main/kotlin/com/natura/android/sample/MainActivity.kt index 773aea2b9..68a40b31c 100644 --- a/sample/src/main/kotlin/com/natura/android/sample/MainActivity.kt +++ b/sample/src/main/kotlin/com/natura/android/sample/MainActivity.kt @@ -76,7 +76,7 @@ class MainActivity : AppCompatActivity() { startActivity(Intent(this, ExpansionPanelActivity::class.java)) } - btnIconButton.setOnClickListener { + iconButtonButton.setOnClickListener { startActivity(Intent(this, IconButtonActivity::class.java)) } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 4ff66de32..a45ab937a 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -187,6 +187,18 @@ android:background="@color/surface" android:textColor="@color/highEmphasis" /> +