From e2e9618a967af9f1d106aae400d55832ac7c9494 Mon Sep 17 00:00:00 2001 From: Marcella Souza Date: Fri, 10 Jul 2020 11:35:49 -0300 Subject: [PATCH 01/44] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[DSY-864]=20Adding?= =?UTF-8?q?=20shortcut=20base=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/natura/android/shortcut/ShortCut.kt | 4 ++ .../main/res/drawable/shortcut_background.xml | 5 +++ .../src/main/res/layout/short_cut.xml | 44 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 designsystem/src/main/kotlin/com/natura/android/shortcut/ShortCut.kt create mode 100644 designsystem/src/main/res/drawable/shortcut_background.xml create mode 100644 designsystem/src/main/res/layout/short_cut.xml diff --git a/designsystem/src/main/kotlin/com/natura/android/shortcut/ShortCut.kt b/designsystem/src/main/kotlin/com/natura/android/shortcut/ShortCut.kt new file mode 100644 index 000000000..772f13d64 --- /dev/null +++ b/designsystem/src/main/kotlin/com/natura/android/shortcut/ShortCut.kt @@ -0,0 +1,4 @@ +package com.natura.android.shortcut + +class ShortCut { +} \ No newline at end of file diff --git a/designsystem/src/main/res/drawable/shortcut_background.xml b/designsystem/src/main/res/drawable/shortcut_background.xml new file mode 100644 index 000000000..aa59f1331 --- /dev/null +++ b/designsystem/src/main/res/drawable/shortcut_background.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/designsystem/src/main/res/layout/short_cut.xml b/designsystem/src/main/res/layout/short_cut.xml new file mode 100644 index 000000000..b5f714e27 --- /dev/null +++ b/designsystem/src/main/res/layout/short_cut.xml @@ -0,0 +1,44 @@ + + + + + + + \ No newline at end of file From e6b89a6ccdc89c99c08863c3969d2642b58d9818 Mon Sep 17 00:00:00 2001 From: Marcella Souza Date: Fri, 10 Jul 2020 14:53:01 -0300 Subject: [PATCH 02/44] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[DSY-864]=20Adding?= =?UTF-8?q?=20component=20base=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + designsystem/build.gradle | 2 + .../com/natura/android/shortcut/ShortCut.kt | 96 ++++++++++++++++++- .../main/res/drawable/shortcut_background.xml | 3 +- .../src/main/res/layout/short_cut.xml | 1 - designsystem/src/main/res/values/dimens.xml | 1 - designsystem/src/main/res/values/ds_attrs.xml | 11 +++ 7 files changed, 110 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index c6b8c15fb..b826296f0 100644 --- a/build.gradle +++ b/build.gradle @@ -51,4 +51,5 @@ ext { materialVersion = '1.1.0' espressoIntentsVersion = '3.1.0' mockKVersion = '1.10.0' + coreKTXVersion = '1.3.0' } diff --git a/designsystem/build.gradle b/designsystem/build.gradle index 84ad96ed9..361651a2c 100644 --- a/designsystem/build.gradle +++ b/designsystem/build.gradle @@ -55,6 +55,8 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "com.google.android.material:material:$rootProject.materialVersion" implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayout" + implementation "androidx.core:core-ktx:$rootProject.coreKTXVersion" + testImplementation "junit:junit:$rootProject.junitVersion" testImplementation "androidx.test.ext:truth:$rootProject.truthVersion" diff --git a/designsystem/src/main/kotlin/com/natura/android/shortcut/ShortCut.kt b/designsystem/src/main/kotlin/com/natura/android/shortcut/ShortCut.kt index 772f13d64..1af53f633 100644 --- a/designsystem/src/main/kotlin/com/natura/android/shortcut/ShortCut.kt +++ b/designsystem/src/main/kotlin/com/natura/android/shortcut/ShortCut.kt @@ -1,4 +1,96 @@ package com.natura.android.shortcut -class ShortCut { -} \ No newline at end of file +import android.content.Context +import android.graphics.drawable.GradientDrawable +import android.util.AttributeSet +import android.view.View +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.res.getIntOrThrow +import androidx.core.content.res.getResourceIdOrThrow +import androidx.core.content.res.getStringOrThrow +import com.natura.android.R + +class ShortCut @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : ConstraintLayout(context, attrs, defStyleAttr) { + + private var labelAttribute: String? + private var typeAttribute = 0 + private var backgroundColorResourceAttribute = 0 + private var iconColorResourceAttribute = 0 + private var labelColorResourceAttribute = 0 + private var iconResourceAttribute = 0 + + private val labelContainer by lazy { findViewById(R.id.shortCutLabel) } + private val backgroundContainer by lazy { findViewById(R.id.shortcutBackground) } + private val iconContainer by lazy { findViewById(R.id.shortCutIcon) } + + + init { + View.inflate(context, R.layout.short_cut, this) + + val typedArray = context.obtainStyledAttributes(attrs, R.styleable.shortCut) + labelAttribute = typedArray.getStringOrThrow(R.styleable.shortCut_shortCutLabel) + backgroundColorResourceAttribute = typedArray.getResourceIdOrThrow(R.styleable.shortCut_shortCutBackgroundColor) + iconColorResourceAttribute = typedArray.getResourceIdOrThrow(R.styleable.shortCut_shortCutIconColor) + labelColorResourceAttribute = typedArray.getResourceIdOrThrow(R.styleable.shortCut_shortCutLabelColor) + iconResourceAttribute = typedArray.getResourceIdOrThrow(R.styleable.shortCut_shortCutIcon) + typeAttribute = typedArray.getIntOrThrow(R.styleable.shortCut_shortCutType) + + configureShortCutByType(typeAttribute) + } + + fun setLabel(text: String?) { + labelContainer.text = text + labelContainer.setTextColor(labelColorResourceAttribute) + } + + fun setIcon(icon: Int) { + val iconDrawable = context.getDrawable(icon) + iconDrawable?.setTint(iconColorResourceAttribute) + iconContainer.setImageResource(icon) + } + + private fun configureShortCutByType(type: Int) { + when (typeAttribute) { + CONTAINED -> configureContainedShortCut() + OUTLINED -> configureOutlinedShortCut() + } + } + + private fun configureOutlinedShortCut() { + setLabel(labelAttribute) + setIcon(iconResourceAttribute) + setBackgroundOutlined() + } + + private fun configureContainedShortCut() { + setLabel(labelAttribute) + setIcon(iconResourceAttribute) + setBackgroundContained() + } + + private fun setBackgroundContained() { + val drawableBackground = context.getDrawable(R.drawable.shortcut_background) + drawableBackground?.setTint(backgroundColorResourceAttribute) + backgroundContainer.background = drawableBackground + } + + private fun setBackgroundOutlined() { + val drawableBackground = context.getDrawable(R.drawable.shortcut_background) as GradientDrawable + drawableBackground.setStroke(1, backgroundColorResourceAttribute) + backgroundContainer.background = drawableBackground + } + + companion object { + const val CONTAINED = 0 + const val OUTLINED = 1 + } +} + + diff --git a/designsystem/src/main/res/drawable/shortcut_background.xml b/designsystem/src/main/res/drawable/shortcut_background.xml index aa59f1331..0f37cb6a5 100644 --- a/designsystem/src/main/res/drawable/shortcut_background.xml +++ b/designsystem/src/main/res/drawable/shortcut_background.xml @@ -1,5 +1,6 @@ - + + \ No newline at end of file diff --git a/designsystem/src/main/res/layout/short_cut.xml b/designsystem/src/main/res/layout/short_cut.xml index b5f714e27..12c875cf5 100644 --- a/designsystem/src/main/res/layout/short_cut.xml +++ b/designsystem/src/main/res/layout/short_cut.xml @@ -14,7 +14,6 @@ android:layout_width="?sizeMediumX" android:layout_height="?sizeMediumX" android:background="@drawable/shortcut_background" - android:elevation="?elevation03" android:gravity="center" android:orientation="vertical" app:layout_constraintBottom_toBottomOf="parent" diff --git a/designsystem/src/main/res/values/dimens.xml b/designsystem/src/main/res/values/dimens.xml index 607bd7725..c852e4333 100644 --- a/designsystem/src/main/res/values/dimens.xml +++ b/designsystem/src/main/res/values/dimens.xml @@ -24,7 +24,6 @@ 0.04 0.0 - 0dp 2dp diff --git a/designsystem/src/main/res/values/ds_attrs.xml b/designsystem/src/main/res/values/ds_attrs.xml index f334585c8..0f6dd82b2 100644 --- a/designsystem/src/main/res/values/ds_attrs.xml +++ b/designsystem/src/main/res/values/ds_attrs.xml @@ -1,5 +1,16 @@ + + + + + + + + + + + From 58760f214867434be25b70891e7e9ef4e2d64927 Mon Sep 17 00:00:00 2001 From: Marcella Souza Date: Fri, 10 Jul 2020 15:03:25 -0300 Subject: [PATCH 03/44] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[DSY-864]=20Adding?= =?UTF-8?q?=20shortcut=20sample?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sample/MainActivityFunctionalTests.kt | 8 ++++ sample/src/main/AndroidManifest.xml | 10 +++-- .../com/natura/android/sample/MainActivity.kt | 4 ++ .../sample/components/ShortcutActivity.kt | 21 ++++++++++ sample/src/main/res/layout/activity_main.xml | 12 ++++++ .../src/main/res/layout/activity_shortcut.xml | 41 +++++++++++++++++++ .../natura/android/sample/MainActivityTest.kt | 17 ++------ 7 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 sample/src/main/kotlin/com/natura/android/sample/components/ShortcutActivity.kt create mode 100644 sample/src/main/res/layout/activity_shortcut.xml diff --git a/sample/src/androidTest/kotlin/com/natura/android/sample/MainActivityFunctionalTests.kt b/sample/src/androidTest/kotlin/com/natura/android/sample/MainActivityFunctionalTests.kt index afc90fc98..2af3035ab 100644 --- a/sample/src/androidTest/kotlin/com/natura/android/sample/MainActivityFunctionalTests.kt +++ b/sample/src/androidTest/kotlin/com/natura/android/sample/MainActivityFunctionalTests.kt @@ -128,6 +128,14 @@ class MainActivityFunctionalTests { onView(withText("Selection Control")).check(matches(isDisplayed())) } + @Test + fun shouldOpenShortcutScreenWhenTapOnItButton() { + onView(withId(R.id.shortcutButton)).perform(scrollTo()) + onView(withId(R.id.shortcutButton)).perform(click()) + + onView(withText("Shortcut")).check(matches(isDisplayed())) + } + @Test fun shouldOpenTextFieldScreenWhenTapOnItButton() { onView(withId(R.id.btnTextfield)).perform(scrollTo()) diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index fb69c57e6..74144260e 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -15,10 +15,11 @@ + - + @@ -43,6 +44,7 @@ + @@ -80,12 +82,14 @@ - - + + \ No newline at end of file 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 db1452986..41c0821fd 100644 --- a/sample/src/main/kotlin/com/natura/android/sample/MainActivity.kt +++ b/sample/src/main/kotlin/com/natura/android/sample/MainActivity.kt @@ -73,6 +73,10 @@ class MainActivity : AppCompatActivity() { startActivity(Intent(this, SelectionControlActivity::class.java)) } + shortcutButton.setOnClickListener { + startActivity(Intent(this, ShortcutActivity::class.java)) + } + btnTextfield.setOnClickListener { startActivity(Intent(this, TextFieldActivity::class.java)) } diff --git a/sample/src/main/kotlin/com/natura/android/sample/components/ShortcutActivity.kt b/sample/src/main/kotlin/com/natura/android/sample/components/ShortcutActivity.kt new file mode 100644 index 000000000..580fa77c9 --- /dev/null +++ b/sample/src/main/kotlin/com/natura/android/sample/components/ShortcutActivity.kt @@ -0,0 +1,21 @@ +package com.natura.android.sample.components + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.view.MenuItem +import com.natura.android.sample.R + +class ShortcutActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_shortcut) + + supportActionBar?.title = "Shortcut" + supportActionBar?.setHomeButtonEnabled(true) + } + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + onBackPressed() + return true + } +} \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index c88294d1d..7896324d7 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" /> +