refactoring code
This commit is contained in:
parent
a7f4104313
commit
d0594113a1
|
|
@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class VehOwnApiClientFactory {
|
||||
|
||||
public static boolean dummyMode = false;
|
||||
public static boolean dummyMode = true;
|
||||
|
||||
public static String URL = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -57,105 +57,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
/*
|
||||
final EditText usernameEditText = findViewById(R.id.username);
|
||||
final EditText passwordEditText = findViewById(R.id.password);
|
||||
final Button loginButton = findViewById(R.id.login);
|
||||
final Button btnRegisterCustomer = findViewById(R.id.btnRegisterCustomer);
|
||||
|
||||
final ProgressBar loadingProgressBar = findViewById(R.id.loading);
|
||||
|
||||
loginViewModel.getLoginFormState().observe(this, new Observer<LoginFormState>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable LoginFormState loginFormState) {
|
||||
if (loginFormState == null) {
|
||||
return;
|
||||
}
|
||||
loginButton.setEnabled(loginFormState.isDataValid());
|
||||
if (loginFormState.getUsernameError() != null) {
|
||||
usernameEditText.setError(getString(loginFormState.getUsernameError()));
|
||||
}
|
||||
if (loginFormState.getPasswordError() != null) {
|
||||
passwordEditText.setError(getString(loginFormState.getPasswordError()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
loginViewModel.getLoginResult().observe(this, new Observer<LoginResult>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable LoginResult loginResult) {
|
||||
if (loginResult == null) {
|
||||
return;
|
||||
}
|
||||
loadingProgressBar.setVisibility(View.GONE);
|
||||
if (loginResult.getError() != null) {
|
||||
showLoginFailed(loginResult.getError());
|
||||
}
|
||||
if (loginResult.getSuccess() != null) {
|
||||
updateUiWithUser(loginResult.getSuccess());
|
||||
}
|
||||
setResult(Activity.RESULT_OK);
|
||||
|
||||
//Complete and destroy login activity once successful
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
TextWatcher afterTextChangedListener = new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
loginViewModel.loginDataChanged(usernameEditText.getText().toString(),
|
||||
passwordEditText.getText().toString());
|
||||
}
|
||||
};
|
||||
usernameEditText.addTextChangedListener(afterTextChangedListener);
|
||||
passwordEditText.addTextChangedListener(afterTextChangedListener);
|
||||
passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
loginViewModel.login(usernameEditText.getText().toString(),
|
||||
passwordEditText.getText().toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
btnRegisterCustomer.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Intent intent = new Intent(LoginActivity.this, RegisterCustomerActivity.class);
|
||||
|
||||
// startActivity(intent);
|
||||
|
||||
LoginFragment fragment = new LoginFragment();
|
||||
fragment.setArguments(new Bundle());
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, fragment);
|
||||
fragmentTransaction.commit();
|
||||
|
||||
}
|
||||
});
|
||||
loginButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
loadingProgressBar.setVisibility(View.VISIBLE);
|
||||
loginViewModel.login(usernameEditText.getText().toString(),
|
||||
passwordEditText.getText().toString());
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
showLogin();
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue