Skip to content

Commit

Permalink
Bugfix/minor component fix (#41)
Browse files Browse the repository at this point in the history
* Release (#39)

* rename TextInputHighlight to ValueTextHighlight

* fix button styles

* update unit test config (#37)

Co-authored-by: Bianca Letti <[email protected]>
Co-authored-by: Rodrigo Nunes <[email protected]>

* bump version (#38)

Co-authored-by: Rodrigo Nunes <[email protected]>

Co-authored-by: Rodrigo Nunes <[email protected]>
Co-authored-by: Bianca Letti <[email protected]>
Co-authored-by: Rodrigo Souza <[email protected]>

* text field input should return current typed text

* run and fix klint warnings

* text field input should return current typed text

* run and fix klint warnings

Co-authored-by: Bianca Letti <[email protected]>
Co-authored-by: Angélica Oliveira <[email protected]>
Co-authored-by: Rodrigo Nunes <[email protected]>
  • Loading branch information
4 people authored Mar 18, 2020
1 parent 60831f4 commit 6d70d40
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ 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,
Expand Down Expand Up @@ -95,6 +93,9 @@ class TextFieldInput @JvmOverloads constructor(
field = value
inputValue.setText(value)
}
get() {
return inputValue.text.toString()
}

var icon: String? = null
set(value) {
Expand Down Expand Up @@ -149,10 +150,10 @@ class TextFieldInput @JvmOverloads constructor(
set(value) {
field = value
footer = value
if (value != null) {
state = State.ERROR
state = if (value != null) {
State.ERROR
} else {
state = State.NONE
State.NONE
}
}

Expand All @@ -178,7 +179,7 @@ class TextFieldInput @JvmOverloads constructor(
else view.visibility = View.VISIBLE
}

private fun intToState(vstate: Int)= when(vstate) {
private fun intToState(vstate: Int) = when (vstate) {
1 -> State.SUCCESS
2 -> State.ERROR
else -> State.NONE
Expand All @@ -200,7 +201,7 @@ class TextFieldInput @JvmOverloads constructor(
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)
val vstate = typedArray.getInt(R.styleable.ds_text_field_input_text_field_state, 0)

typedArray.recycle()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ class ValueTextHighlight @JvmOverloads constructor(
highlightInfoLabel.invalidate()
highlightInfoLabel.requestLayout()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.robolectric.Robolectric
import org.robolectric.annotation.Config

@RunWith(AndroidJUnit4::class)
@Config(sdk=[28])
@Config(sdk = [28])
class TextFieldInputTest {

val activityController = Robolectric.buildActivity(Activity::class.java)
Expand All @@ -45,7 +45,7 @@ class TextFieldInputTest {
@Test
fun basicConstructor_NoStyledAttributes() {
assertThat(textFieldInput.label).isNull()
assertThat(textFieldInput.text).isNull()
assertThat(textFieldInput.text).isEmpty()
assertThat(textFieldInput.footer).isNull()
assertThat(textFieldInput.icon).isNull()
assertThat(textFieldInput.state).isEqualTo(TextFieldInput.State.NONE)
Expand Down Expand Up @@ -160,8 +160,12 @@ class TextFieldInputTest {
test_seError(NOT_EMPTY_TEXT, NOT_EMPTY_TEXT, View.VISIBLE, ERROR_ICON_CODE.toIcon())
}

private fun test_seError(value: String?, expectedValue: String, expectedVisibility: Int,
expectedIcon: String) {
private fun test_seError(
value: String?,
expectedValue: String,
expectedVisibility: Int,
expectedIcon: String
) {
val footerView = textFieldInput.findViewById(R.id.text_field_input_footer) as TextView
val footerIconView = textFieldInput.findViewById(R.id.text_field_input_footer_icon) as FontIcon
val footerBoxView = textFieldInput.findViewById(R.id.text_field_input_footer_box) as View
Expand Down Expand Up @@ -191,8 +195,12 @@ class TextFieldInputTest {
test_setState(TextFieldInput.State.SUCCESS, TextFieldInput.LayoutState.SUCCESS, View.VISIBLE, SUCCESS_ICON_CODE.toIcon())
}

private fun test_setState(state: TextFieldInput.State, expectedLayoutState: TextFieldInput.LayoutState,
expectedIconVisibility: Int, expectedIconValue: String) {
private fun test_setState(
state: TextFieldInput.State,
expectedLayoutState: TextFieldInput.LayoutState,
expectedIconVisibility: Int,
expectedIconValue: String
) {
val labelView = textFieldInput.findViewById(R.id.text_field_input_label) as TextView
val footerView = textFieldInput.findViewById(R.id.text_field_input_footer) as TextView
val footerIconView = textFieldInput.findViewById(R.id.text_field_input_footer_icon) as FontIcon
Expand Down Expand Up @@ -354,5 +362,4 @@ class TextFieldInputTest {
}

private fun getColor(id: Int) = ContextCompat.getColor(textFieldInput.context, id)

}
}

0 comments on commit 6d70d40

Please sign in to comment.