So, I implemented
public class DriverLoginActivity extends BaseActivity implements Observer<LoginUser>
And, onChanged overided.
@Override
public void onChanged(@Nullable LoginUser loginUser) {
if (TextUtils.isEmpty(Objects.requireNonNull(loginUser).getEmail())) {
binding.email.setError("Email Id can't be blank");
binding.email.requestFocus();
} else if (!loginUser.isEmailValid()) {
binding.email.setError("Please enter valid Email Id");
binding.email.requestFocus();
} else if (TextUtils.isEmpty(Objects.requireNonNull(loginUser).getPassword())) {
binding.password.setError("Password can't be blank");
binding.password.requestFocus();
} else if (!loginUser.isPasswordLengthGreaterThan5()) {
binding.password.setError("Password length must be at least 8 digit");
binding.password.requestFocus();
} else {
mAuth.createUserWithEmailAndPassword(loginUser.getEmail(), loginUser.getPassword()).addOnCompleteListener(this);
}
}
Now, for this activity, I have 2 buttons. so, the depending on the button click, this onChanged will be call. Now I want to do login button for login user and registre for registration. How can I make it separate in onChanged method?
Please suggest me the very best practice.
I don't think I should use setter in viewmodel class and getter in activity. It don't consider MVVM practice. right?
In MVVM, the ViewModel is designed to manage data. The ideal way would be handling your API calls in the ViewModel. Using LiveData for this is not the ideal use of LiveData.
Your ViewModel can have
And in your activity_main.xml
Check this https://github.com/MindorksOpenSource/android-mvvm-architecture/tree/master/app/src/main/java/com/mindorks/framework/mvvm/ui/login