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
val email = MutableStateFlow("") | |
val password = MutableStateFlow("") | |
val isEmailAndPasswordValid = MutableStateFlow(false).apply { | |
viewModelScope.launch { | |
combine(email, password) { n1, n2 -> | |
validate(n1, n2) | |
}.collect { isValid -> | |
value = isValid | |
} | |
} |
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
val email = MutableLiveData<String>() | |
val password = MutableLiveData<String>() | |
val isEmailAndPasswordValid = MediatorLiveData<Boolean>().apply { | |
addSource(email) { validate() } | |
addSource(password) { validate() } | |
} | |
private fun validate() { | |
isEmailAndPasswordValid.value = | |
email.value.orEmpty().isNotEmpty() && password.value.orEmpty().isNotEmpty() |
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
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:padding="20dp"> | |
<com.rengwuxian.materialedittext.MaterialEditText | |
android:id="@+id/email" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" |