-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from natura-cosmeticos/release
Release 1.1
- Loading branch information
Showing
34 changed files
with
1,474 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
239 changes: 239 additions & 0 deletions
239
designsystem/src/main/kotlin/com/natura/android/textfield/TextFieldInput.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
designsystem/src/main/kotlin/com/natura/android/widget/TextInputHighlight.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
designsystem/src/main/res/color/ds_mtrl_default_btn_text_color_selector.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
5 changes: 5 additions & 0 deletions
5
designsystem/src/main/res/color/ds_mtrl_sec_btn_background_selector.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
5 changes: 5 additions & 0 deletions
5
designsystem/src/main/res/color/ds_mtrl_sec_btn_text_color_selector.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
5 changes: 5 additions & 0 deletions
5
designsystem/src/main/res/color/ds_mtrl_sec_colored_btn_text_color_selector.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
8 changes: 8 additions & 0 deletions
8
designsystem/src/main/res/color/ds_mtrl_sec_colored_ripple_color_selector.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
5
designsystem/src/main/res/drawable/ds_text_field_selector.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.