Main Activity

mail@pastecode.io avatar
unknown
java
3 years ago
2.2 kB
1
Indexable
Never
package com.example.cse332mainproject;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.view.View;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity

{
    EditText username,password;
    ImageButton btnLogin;

    DBHelper myDB;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        username = (EditText) findViewById(R.id.editTextTextEmailAddress);
        password = (EditText) findViewById(R.id.editTextTextPassword);
        btnLogin = (ImageButton) findViewById(R.id.imageButton);

        myDB = new DBHelper(this);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String user = username.getText().toString();
                String pass = password.getText().toString();

                if(user.equals("") || pass.equals(""))
                {
                    Toast.makeText(MainActivity.this, "Please enter the credentials", Toast.LENGTH_SHORT).show();
                }
                else
                {
                    Boolean result = myDB.checkusernamePassword(user, pass);
                    if(result)
                    {
                        Intent intent = new Intent(getApplicationContext(), HomepageActivity.class);
                        startActivity(intent);

                    }
                    else
                    {
                        Toast.makeText(MainActivity.this, "Invalid username or password", Toast.LENGTH_SHORT).show();
                    }

                }

            }
        });
    }

    public void gotoHomepage(View view) {
        Intent i = new Intent(this,HomepageActivity.class);
        startActivity(i);
    }

    public void gotoRegistration(View view) {
        Intent i = new Intent(this,registerActivity.class);
        startActivity(i);
    }


}