Skip to content

Commit

Permalink
Validation Init
Browse files Browse the repository at this point in the history
  • Loading branch information
aveek committed Jun 20, 2022
1 parent fbdd33d commit fddeef0
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 29 deletions.
Binary file modified buildSrc/build/kotlin/compileKotlin/build-history.bin
Binary file not shown.
Binary file modified buildSrc/build/kotlin/compileKotlin/last-build.bin
Binary file not shown.
Binary file modified buildSrc/build/libs/buildSrc.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class LoginDataSource @Inject constructor(private val service : LoginDataService
errorResponseRemote?.let {
it.message?.let { msg ->
emit(ApiResponseResult.error(msg, result.code().toString()))
} ?: kotlin.run {
emit(ApiResponseResult.error("Server Error", result.code().toString()))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ class LoginActivityHandler (val binding : ActivityLoginBinding){
fun passwordValidator(editable: Editable) {
with(binding){
if (etPassword == null) return
val minimumLength = 5
if (!TextUtils.isEmpty(editable.toString()) && editable.length < minimumLength) {
etPassword.error = "Password must be minimum $minimumLength length"
} else {
etPassword.error = null
if (TextUtils.isEmpty(editable.toString())) {
etPassword.error = binding.root.resources.getString(R.string.error_empty_password)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,22 @@ class LoginActivity : AppCompatActivity() {
with(loginViewModel){
loginClick.observe(this@LoginActivity, Observer {
if (it){
if (isNetworkAvailable(this@LoginActivity)) {
login()
if(this.isValid()) {
if (isNetworkAvailable(this@LoginActivity)) {
login()
} else {
Snackbar.make(
binding.root,
getString(R.string.no_internet),
Snackbar.LENGTH_LONG
).show()
}
}else{
Snackbar.make(binding.root, getString(R.string.no_internet), Snackbar.LENGTH_LONG).show()
Snackbar.make(
binding.root,
getString(R.string.empty_fields),
Snackbar.LENGTH_LONG
).show()
}
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moneybox.minimb.feature.login.presentation.login

import android.content.SharedPreferences
import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand Down Expand Up @@ -33,6 +34,7 @@ class LoginViewModel @Inject constructor(private val loginRepository: LoginRepos
val password = MutableLiveData<String>("")

fun login(){

val userMap = HashMap<String, String>()
userMap["email"] = email.value!!
userMap["password"] = password.value!!
Expand Down Expand Up @@ -69,4 +71,7 @@ class LoginViewModel @Inject constructor(private val loginRepository: LoginRepos
_loginResultStored.value = false
}
}
fun isValid() : Boolean{
return !TextUtils.isEmpty(email.value) && !TextUtils.isEmpty(password.value)
}
}
61 changes: 40 additions & 21 deletions feature/login/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,56 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/moneybox_logo"
app:layout_constraintBottom_toTopOf="@+id/et_email"
app:layout_constraintBottom_toTopOf="@+id/email_text_input_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/et_email"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/email_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
app:layout_constraintBottom_toTopOf="@+id/et_password"
app:layout_constraintTop_toTopOf="parent"
android:hint="@string/text_email"
style="@style/edittext_style"
app:layout_constraintVertical_bias="1.0"
android:inputType="text"
android:text="@={viewModel.email}"
android:afterTextChanged="@{(edible)->handler.emailValidator(edible)}"
/>
app:layout_constraintBottom_toTopOf="@+id/password_text_input_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" >

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/et_email"
style="@style/edittext_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:afterTextChanged="@{(editable)->handler.emailValidator(editable)}"
android:hint="@string/text_email"
android:inputType="text"
android:text="@={viewModel.email}"/>
</com.google.android.material.textfield.TextInputLayout>

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/et_password"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/text_password"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="@style/edittext_style"
android:inputType="textPassword"
android:text="@={viewModel.password}"
android:afterTextChanged="@{(edible)->handler.passwordValidator(edible)}"/>
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/secondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/et_password"
style="@style/edittext_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:afterTextChanged="@{(editable)->handler.passwordValidator(editable)}"
android:hint="@string/text_password"
android:inputType="textPassword"

android:text="@={viewModel.password}" />
</com.google.android.material.textfield.TextInputLayout>

<Button
android:id="@+id/btn_login"
Expand All @@ -81,7 +100,7 @@
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_password" />
app:layout_constraintTop_toBottomOf="@+id/password_text_input_layout" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down
1 change: 1 addition & 0 deletions feature/login/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<string name="title_activity_login">LoginActivity</string>
<string name="text_login">LOG IN</string>
<string name="no_internet">Connection interrupted\nPlease turn on your internet connection</string>
<string name="empty_fields">Fields cant be empty</string>
<string name="text_email">Email</string>
<string name="text_password">Password</string>
<string name="error_empty_email">Email can not be empty!</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.moneybox.minimb.feature.login

import org.junit.Test

class LoginViewModelTest {

@Test
fun validateEmail(){}
}

0 comments on commit fddeef0

Please sign in to comment.