Skip to content

Commit

Permalink
Merge pull request #34 from natura-cosmeticos/release
Browse files Browse the repository at this point in the history
Release 1.1
  • Loading branch information
bihletti authored Mar 12, 2020
2 parents 319a2e2 + 9e1bb62 commit fd204b3
Show file tree
Hide file tree
Showing 34 changed files with 1,474 additions and 17 deletions.
3 changes: 3 additions & 0 deletions bitrise-test3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Teste para adicionar o bitrise
--Adicionando webhook para testes
Adicionando mais linhas
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ ext {
expressoVersion = '3.1.1'
ktlintVersion = '0.35.0'
androidXTestVersion = '1.2.0'
testCoreKtxVersion = "1.2.0"
androidxJunitVersion = "1.1.1"
truthVersion = '1.2.0'
robolectricVersion = '4.3'
}
15 changes: 15 additions & 0 deletions designsystem/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ android {
lintOptions {
baseline file("lint-baseline.xml")
}

testOptions {
unitTests.includeAndroidResources = true
unitTests.returnDefaultValues = true
}
}

dependencies {
Expand All @@ -40,6 +45,16 @@ dependencies {
implementation "com.android.support.constraint:constraint-layout:$rootProject.constraintLayout"

testImplementation "junit:junit:$rootProject.junitVersion"
testImplementation "androidx.test.ext:truth:$rootProject.truthVersion"
testImplementation "androidx.test:runner:$rootProject.androidXTestVersion"
testImplementation "androidx.test:core-ktx:$rootProject.testCoreKtxVersion"
testImplementation "androidx.test.ext:junit:$rootProject.androidxJunitVersion"
testImplementation "org.robolectric:robolectric:$rootProject.robolectricVersion"

androidTestImplementation "androidx.test.ext:junit:$rootProject.junitExtVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.expressoVersion"
}

androidExtensions {
experimental = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
package com.natura.android.textfield

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.support.constraint.ConstraintLayout
import android.support.v4.content.ContextCompat
import android.text.InputFilter
import android.util.AttributeSet
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import com.natura.android.R
import com.natura.android.icon.FontIcon


@SuppressLint("CustomViewStyleable")
class TextFieldInput @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {

enum class State {
NONE, ERROR, SUCCESS
}

enum class LayoutState(val borderWidth: Int, val borderColor: Int, val labelColor: Int, val textColor: Int, val footerColor: Int) {
DEFAULT(R.dimen.ds_border_tiny, R.color.colorHighEmphasis, R.color.colorMediumEmphasis, R.color.colorHighEmphasis, R.color.colorMediumEmphasis),
DISABLED(R.dimen.ds_border_tiny, R.color.colorLowEmphasis, R.color.colorLowEmphasis, R.color.colorLowEmphasis, R.color.colorLowEmphasis),
FOCUSED(R.dimen.ds_border_emphasis, R.color.colorBrdNatYellow, R.color.colorMediumEmphasis, R.color.colorHighEmphasis, R.color.colorMediumEmphasis),
ERROR(R.dimen.ds_border_emphasis, R.color.colorBrdNatRed, R.color.colorBrdNatRed, R.color.colorHighEmphasis, R.color.colorBrdNatRed),
SUCCESS(R.dimen.ds_border_tiny, R.color.colorBrdNatGreen, R.color.colorBrdNatGreen, R.color.colorHighEmphasis, R.color.colorBrdNatGreen)
}

private val SUCCESS_ICON = "EA15"
private val ERROR_ICON = "EA13"

private val inputLabel by lazy { findViewById<TextView>(R.id.text_field_input_label) }

private val inputBox by lazy { findViewById<LinearLayout>(R.id.text_field_input_box) }
private val inputValue by lazy { findViewById<EditText>(R.id.text_field_input_value) }
private val inputIcon by lazy { findViewById<FontIcon>(R.id.text_field_input_icon) }

private val footerBox by lazy { findViewById<LinearLayout>(R.id.text_field_input_footer_box) }
private val footerValue by lazy { findViewById<TextView>(R.id.text_field_input_footer) }
private val footerIcon by lazy { findViewById<FontIcon>(R.id.text_field_input_footer_icon) }

override fun setEnabled(enabled: Boolean) {
super.setEnabled(enabled)
inputValue?.isEnabled = enabled
inputIcon?.isEnabled = enabled
resetLayoutState()
}

var inputType: Int = EditorInfo.TYPE_CLASS_TEXT
set(value) {
field = value
inputValue?.inputType = value
inputValue?.setSelection(inputValue?.text?.length ?: 0)
}

var hint: String? = null
set(value) {
field = value
inputValue.hint = value
}

var maxLength: Int = 0
set(value) {
field = value

val fArray = arrayOfNulls<InputFilter>(1)
fArray[0] = InputFilter.LengthFilter(value)
inputValue.filters = fArray
}

var maxLines: Int = 0
set(value) {
field = value
inputValue.maxLines = value
}

var lines: Int = 0
set(value) {
field = value
inputValue.setLines(value)
}

var text: String? = null
set(value) {
field = value
inputValue.setText(value)
}

var icon: String? = null
set(value) {
field = value
inputIcon.setText(value)
changeVisibilityByValue(inputIcon, value)
}

var label: String? = null
set(value) {
field = value
inputLabel.text = value
changeVisibilityByValue(inputLabel, value)
}

var footer: String? = null
set(value) {
field = value
footerValue.text = value
changeVisibilityByValue(footerBox, value)
}

var layoutState: LayoutState = LayoutState.DEFAULT
private set(value) {
field = value
inputLabel?.setTextColor(ContextCompat.getColor(context, value.labelColor))
(inputBox.background as GradientDrawable).setStroke(
resources.getDimension(value.borderWidth).toInt(),
ContextCompat.getColor(context, value.borderColor))
footerValue?.setTextColor(ContextCompat.getColor(context, value.footerColor))
footerIcon?.setTextColor(ContextCompat.getColor(context, value.footerColor))
}

var state: State = State.NONE
set(value) {
field = value
resetLayoutState()
when (value) {
State.ERROR -> {
setFooterIcon(ERROR_ICON, View.VISIBLE)
}
State.SUCCESS -> {
setFooterIcon(SUCCESS_ICON, View.VISIBLE)
}
else -> {
setFooterIcon("", View.GONE)
}
}
}

var error: String? = null
set(value) {
field = value
footer = value
if (value != null) {
state = State.ERROR
} else {
state = State.NONE
}
}

private fun resetLayoutState() {
layoutState = when (state) {
State.ERROR -> LayoutState.ERROR
State.SUCCESS -> LayoutState.SUCCESS
else -> {
if (!isEnabled) LayoutState.DISABLED
else if (inputValue.isFocused) LayoutState.FOCUSED
else LayoutState.DEFAULT
}
}
}

private fun setFooterIcon(value: String, visibility: Int) {
footerIcon.text = value
footerIcon.visibility = visibility
}

private fun changeVisibilityByValue(view: View, value: String?) {
if (value == null || value.isEmpty()) view.visibility = View.GONE
else view.visibility = View.VISIBLE
}

private fun intToState(vstate: Int)= when(vstate) {
1 -> State.SUCCESS
2 -> State.ERROR
else -> State.NONE
}

init {
View.inflate(context, R.layout.ds_text_field_input, this)

val typedArray = context.obtainStyledAttributes(attrs, R.styleable.ds_text_field_input)

val vinputType = typedArray.getInteger(R.styleable.ds_text_field_input_android_inputType, EditorInfo.TYPE_CLASS_TEXT)
val vhint = typedArray.getString(R.styleable.ds_text_field_input_android_hint)
val vmaxLength = typedArray.getInteger(R.styleable.ds_text_field_input_android_maxLength, Integer.MAX_VALUE)
val vmaxLines = typedArray.getInteger(R.styleable.ds_text_field_input_android_maxLines, 1)
val vlines = typedArray.getInteger(R.styleable.ds_text_field_input_android_lines, 1)
val venabled = typedArray.getBoolean(R.styleable.ds_text_field_input_android_enabled, true)

val vlabel = typedArray.getString(R.styleable.ds_text_field_input_text_field_label)
val vtext = typedArray.getString(R.styleable.ds_text_field_input_text_field_text)
val vicon = typedArray.getString(R.styleable.ds_text_field_input_text_field_icon)
val vfooter = typedArray.getString(R.styleable.ds_text_field_input_text_field_footer)
var vstate = typedArray.getInt(R.styleable.ds_text_field_input_text_field_state, 0)

typedArray.recycle()

inputType = vinputType
hint = vhint
maxLines = vmaxLines
maxLength = vmaxLength
lines = vlines
isEnabled = venabled

text = vtext
label = vlabel
footer = vfooter
icon = vicon
state = intToState(vstate)

inputValue.setOnFocusChangeListener { v, hasFocus -> onFocusChanged(v, hasFocus) }
inputIcon.setOnClickListener { v -> onFocusChanged(v, true) }

inputBox.setOnClickListener {
inputValue.requestFocus()
}
}

private fun onFocusChanged(view: View, hasFocus: Boolean) {
if (hasFocus) {
layoutState = LayoutState.FOCUSED
} else {
resetLayoutState()
}
}

fun setOnIconClickListener(l: OnClickListener?) {
inputIcon?.setOnClickListener(l)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.natura.android.widget

import android.content.Context
import android.support.constraint.ConstraintLayout
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.TextView
import com.natura.android.R

class TextInputHighlight @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {

private lateinit var descriptionLabel: TextView
private lateinit var highlightInfoLabel: TextView

init {
LayoutInflater.from(context)
.inflate(R.layout.ds_input_text_highlight_view, this, true)

with(context.obtainStyledAttributes(attrs, R.styleable.ds_text_input_highlight)) {
val description = this.getString(R.styleable.ds_text_input_highlight_description_label)
val highlight = this.getString(R.styleable.ds_text_input_highlight_highlight_label)

setupView(description, highlight)

this.recycle()
}
}

private fun setupView(description: String?, highlight: String?) {
descriptionLabel = findViewById(R.id.description_label)
highlightInfoLabel = findViewById(R.id.highlight_label)

description?.let { descriptionLabel.text = it }
highlight?.let { highlightInfoLabel.text = it }
}

fun setDescription(description: String) {
descriptionLabel.text = description
descriptionLabel.invalidate()
descriptionLabel.requestLayout()
}

fun setHighlightedInfo(highlightStr: String) {
highlightInfoLabel.text = highlightStr
highlightInfoLabel.invalidate()
highlightInfoLabel.requestLayout()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/black" android:state_enabled="true"/>
<item android:color="@color/mtrlBtnTextColorDisabled"/>
</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?colorSecondary" android:state_enabled="true"/>
<item android:color="@color/colorBrdBlack_12"/>
</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/black" android:state_enabled="true"/>
<item android:color="@color/mtrlBtnTextColorDisabled"/>
</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?colorSecondary" android:state_enabled="true"/>
<item android:color="@color/mtrlBtnTextColorDisabled"/>
</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.16" android:color="?attr/colorSecondary" android:state_pressed="true"/>
<item android:alpha="0.12" android:color="?attr/colorSecondary" android:state_focused="true" android:state_hovered="true"/>
<item android:alpha="0.12" android:color="?attr/colorSecondary" android:state_focused="true"/>
<item android:alpha="0.04" android:color="?attr/colorSecondary" android:state_hovered="true"/>
<item android:alpha="0.00" android:color="?attr/colorSecondary"/>
</selector>
6 changes: 6 additions & 0 deletions designsystem/src/main/res/drawable/ds_custom_border.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="4dp"/>
<padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
<stroke android:width="@dimen/ds_border_tiny" android:color="@color/colorHighEmphasis"/>
</shape>
5 changes: 5 additions & 0 deletions designsystem/src/main/res/drawable/ds_text_field_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/colorLowEmphasis"/>
<item android:color="@color/colorHighEmphasis"/>
</selector>
Loading

0 comments on commit fd204b3

Please sign in to comment.