diff --git a/designsystem/src/main/kotlin/com/natura/android/textfield/TextFieldInput.kt b/designsystem/src/main/kotlin/com/natura/android/textfield/TextFieldInput.kt index 1adf57b6f..993284294 100644 --- a/designsystem/src/main/kotlin/com/natura/android/textfield/TextFieldInput.kt +++ b/designsystem/src/main/kotlin/com/natura/android/textfield/TextFieldInput.kt @@ -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, @@ -95,6 +93,9 @@ class TextFieldInput @JvmOverloads constructor( field = value inputValue.setText(value) } + get() { + return inputValue.text.toString() + } var icon: String? = null set(value) { @@ -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 } } @@ -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 @@ -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() diff --git a/designsystem/src/main/kotlin/com/natura/android/widget/ValueTextHighlight.kt b/designsystem/src/main/kotlin/com/natura/android/widget/ValueTextHighlight.kt index 6853a3cab..56d67215d 100644 --- a/designsystem/src/main/kotlin/com/natura/android/widget/ValueTextHighlight.kt +++ b/designsystem/src/main/kotlin/com/natura/android/widget/ValueTextHighlight.kt @@ -49,4 +49,4 @@ class ValueTextHighlight @JvmOverloads constructor( highlightInfoLabel.invalidate() highlightInfoLabel.requestLayout() } -} \ No newline at end of file +} diff --git a/designsystem/src/test/kotlin/com/natura/android/textfield/TextFieldInputTest.kt b/designsystem/src/test/kotlin/com/natura/android/textfield/TextFieldInputTest.kt index d0d0f5707..f002b30de 100644 --- a/designsystem/src/test/kotlin/com/natura/android/textfield/TextFieldInputTest.kt +++ b/designsystem/src/test/kotlin/com/natura/android/textfield/TextFieldInputTest.kt @@ -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) @@ -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) @@ -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 @@ -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 @@ -354,5 +362,4 @@ class TextFieldInputTest { } private fun getColor(id: Int) = ContextCompat.getColor(textFieldInput.context, id) - -} \ No newline at end of file +}