Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package garbage360.jean.garbage360;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.design.widget.Snackbar;
- import android.support.design.widget.TextInputEditText;
- import android.support.design.widget.TextInputLayout;
- import android.support.v4.widget.NestedScrollView;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.AppCompatButton;
- import android.support.v7.widget.AppCompatTextView;
- import android.util.Log;
- import android.view.View;
- public class LoginController extends AppCompatActivity implements View.OnClickListener {
- private final AppCompatActivity activity = LoginController.this;
- private NestedScrollView nestedScrollView;
- private TextInputLayout textInputLayoutEmail;
- private TextInputLayout textInputLayoutPassword;
- private TextInputEditText textInputEditTextEmail;
- private TextInputEditText textInputEditTextPassword;
- private AppCompatButton appCompatButtonLogin;
- private AppCompatTextView textViewLinkRegister;
- private InputValidation inputValidation;
- private LoginDatabase databaseHelper;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.login_view);
- getSupportActionBar().hide();
- initViews();
- initListeners();
- initObjects();
- }
- /**
- * This method is to initialize views
- */
- private void initViews() {
- nestedScrollView = (NestedScrollView) findViewById(R.id.nestedScrollView);
- textInputLayoutEmail = (TextInputLayout) findViewById(R.id.textInputLayoutEmail);
- textInputLayoutPassword = (TextInputLayout) findViewById(R.id.textInputLayoutPassword);
- textInputEditTextEmail = (TextInputEditText) findViewById(R.id.textInputEditTextEmail);
- textInputEditTextPassword = (TextInputEditText) findViewById(R.id.textInputEditTextPassword);
- appCompatButtonLogin = (AppCompatButton) findViewById(R.id.appCompatButtonLogin);
- textViewLinkRegister = (AppCompatTextView) findViewById(R.id.textViewLinkRegister);
- }
- /**
- * This method is to initialize listeners
- */
- private void initListeners() {
- appCompatButtonLogin.setOnClickListener(this);
- textViewLinkRegister.setOnClickListener(this);
- }
- /**
- * This method is to initialize objects to be used
- */
- private void initObjects() {
- databaseHelper = new LoginDatabase(activity);
- inputValidation = new InputValidation(activity);
- }
- /**
- * This implemented method is to listen the click on view
- *
- * @param v
- */
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.appCompatButtonLogin:
- // Intent intentLogin = new Intent(getApplicationContext(), MainController.class);
- // startActivity(intentLogin);
- verifyFromSQLite();
- break;
- case R.id.textViewLinkRegister:
- // Navigate to RegisterActivity
- Intent intentRegister = new Intent(getApplicationContext(), RegisterController.class);
- startActivity(intentRegister);
- break;
- }
- }
- /**
- * This method is to validate the input text fields and verify login credentials from SQLite
- */
- private void verifyFromSQLite() {
- if (!inputValidation.isInputEditTextFilled(textInputEditTextEmail, textInputLayoutEmail, getString(R.string.error_message_email))) {
- return;
- }
- if (!inputValidation.isInputEditTextEmail(textInputEditTextEmail, textInputLayoutEmail, getString(R.string.error_message_email))) {
- return;
- }
- if (!inputValidation.isInputEditTextFilled(textInputEditTextPassword, textInputLayoutPassword, getString(R.string.error_message_email))) {
- return;
- }
- if (databaseHelper.checkUser(textInputEditTextEmail.getText().toString().trim()
- , textInputEditTextPassword.getText().toString().trim())) {
- Intent accountsIntent = new Intent(activity, MainMenuController.class);
- accountsIntent.putExtra("EMAIL", textInputEditTextEmail.getText().toString().trim());
- emptyInputEditText();
- startActivity(accountsIntent);
- } else {
- // Snack Bar to show success message that record is wrong
- Snackbar.make(nestedScrollView, getString(R.string.error_valid_email_password), Snackbar.LENGTH_LONG).show();
- }
- }
- /**
- * This method is to empty all input edit text
- */
- private void emptyInputEditText() {
- textInputEditTextEmail.setText(null);
- textInputEditTextPassword.setText(null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement