Skip to content

Commit

Permalink
When programmatically removing error, only change color when in focus
Browse files Browse the repository at this point in the history
  • Loading branch information
edwnmrtnz committed May 13, 2022
1 parent cefb28e commit 5a306bf
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ class MainActivity : AppCompatActivity() {
setContentView(binding.root)
binding.etFirstName.setError("first name is required")
binding.etLastName.setError("last name is required")
binding.etPassword.setError("password required")
binding.etGender.setError("this field is required")
binding.etText.setError("this field is required")

binding.etFirstName.setText("Olol ka ba?")

val adapter = ArrayAdapter(
this,
R.layout.awesomeform_dropdown_popup_item,
resources.getStringArray(R.array.exposed_dropdown_content)
)

binding. etGender.setAdapter(adapter)
binding.etGender.setAdapter(adapter)


binding.etMobileNumber.removeError()

}
}
20 changes: 11 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
android:layout_height="wrap_content"
android:orientation="vertical">


<com.github.edwnmrtnz.awesomeforms.library.AwesomeFormNormalEditText
android:id="@+id/etFirstName"
app:fieldLabel="First Name"
Expand All @@ -34,6 +35,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<com.github.edwnmrtnz.awesomeforms.library.AwesomeFormPhonePrefixEditText
android:layout_marginTop="20dp"
android:id="@+id/etMobileNumber"
app:fieldLabel="Mobile Number"
android:inputType="number"
android:imeOptions="actionDone"
app:assistiveText="Optional"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<com.github.edwnmrtnz.awesomeforms.library.AwesomeFormPasswordEditText
android:layout_marginTop="20dp"
android:id="@+id/etPassword"
Expand All @@ -54,15 +65,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<com.github.edwnmrtnz.awesomeforms.library.AwesomeFormPhonePrefixEditText
android:layout_marginTop="20dp"
android:id="@+id/etText"
app:fieldLabel="Text"
android:inputType="text"
android:imeOptions="actionDone"
app:assistiveText="Optional"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>
</ScrollView>
3 changes: 0 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<resources>
<string name="app_name">awesome-form-fields</string>

<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.21'
ext.kotlin_version = '1.6.21'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0-beta03'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
6 changes: 2 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ apply plugin: 'kotlin-kapt'


android {
compileSdkVersion 30
compileSdkVersion 31
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0.15"
targetSdkVersion 31
vectorDrawables.useSupportLibrary true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,21 @@ class AwesomeFormNormalEditText(context: Context, attrs: AttributeSet) :

fun removeError() {
isErrorEnabled = false
tvFieldLabel.setTextColor(
ContextCompat.getColor(
context,
R.color.AwesomeForm_focused_color

if(etField.hasFocus()) {
tvFieldLabel.setTextColor(
ContextCompat.getColor(
context,
R.color.AwesomeForm_focused_color
)
)
)
tvAssistiveText.setTextColor(
ContextCompat.getColor(
context,
R.color.AwesomeForm_focused_color
tvAssistiveText.setTextColor(
ContextCompat.getColor(
context,
R.color.AwesomeForm_focused_color
)
)
)
}

if (assistiveText != null) {
tvAssistiveText.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.text.Editable
import android.text.InputFilter
import android.text.TextWatcher
import android.util.AttributeSet
import android.util.Log
import android.util.SparseArray
import android.view.View
import android.view.View.OnFocusChangeListener
Expand Down Expand Up @@ -236,18 +237,20 @@ class AwesomeFormPasswordEditText(context: Context, attrs: AttributeSet) : Const

fun removeError() {
isErrorEnabled = false
tvFieldLabel.setTextColor(
ContextCompat.getColor(
context,
R.color.AwesomeForm_focused_color
if(etField.hasFocus()) {
tvFieldLabel.setTextColor(
ContextCompat.getColor(
context,
R.color.AwesomeForm_focused_color
)
)
)
tvAssistiveText.setTextColor(
ContextCompat.getColor(
context,
R.color.AwesomeForm_focused_color
tvAssistiveText.setTextColor(
ContextCompat.getColor(
context,
R.color.AwesomeForm_focused_color
)
)
)
}

if (assistiveText != null) {
tvAssistiveText.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import android.os.Parcelable
import android.text.Editable
import android.text.InputFilter
import android.text.TextWatcher
import android.util.AttributeSet
import android.util.DisplayMetrics
import android.util.SparseArray
import android.util.TypedValue
import android.util.*
import android.view.View
import android.view.View.OnFocusChangeListener
import androidx.annotation.AttrRes
Expand Down Expand Up @@ -208,9 +205,11 @@ class AwesomeFormPhonePrefixEditText(context: Context, attrs: AttributeSet) :
fun removeError() {
isErrorEnabled = false

tvFieldLabel.setTextColor(ContextCompat.getColor(context, R.color.AwesomeForm_focused_color))
tvAssistiveText.setTextColor(ContextCompat.getColor(context, R.color.AwesomeForm_focused_color))
prefixDivider.setBackgroundColor(focusedColor)
if(etField.hasFocus()) {
tvFieldLabel.setTextColor(ContextCompat.getColor(context, R.color.AwesomeForm_focused_color))
tvAssistiveText.setTextColor(ContextCompat.getColor(context, R.color.AwesomeForm_focused_color))
prefixDivider.setBackgroundColor(focusedColor)
}

if (assistiveText != null) {
tvAssistiveText.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class AwesomeFormSpinnerEditText(context: Context, attrs: AttributeSet) : Constr

fun removeError() {
isErrorEnabled = false

tvFieldLabel.setTextColor(ContextCompat.getColor(context, R.color.AwesomeForm_focused_color))
tvAssistiveText.setTextColor(ContextCompat.getColor(context, R.color.AwesomeForm_focused_color))

Expand Down

0 comments on commit 5a306bf

Please sign in to comment.