Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.safariagaming.flix;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.support.annotation.NonNull;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.text.TextUtils;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.google.android.gms.tasks.OnCompleteListener;
- import com.google.android.gms.tasks.Task;
- import com.google.firebase.auth.AuthResult;
- import com.google.firebase.auth.FirebaseAuth;
- import static android.R.attr.password;
- public class LoginScreen extends AppCompatActivity implements View.OnClickListener {
- public void openSignUpScreen(View view) {
- Intent i = new Intent(this, SignUpScreen.class /*we use .class to say that it is a class*/); //The intent is stored in i
- startActivity(i);
- }
- public void openForgotScreen(View view) {
- Intent i = new Intent(this, ForgotScreen.class /*we use .class to say that it is a class*/); //The intent is stored in i
- startActivity(i);
- }
- //defining views
- private Button buttonSignIn;
- private EditText editTextEmail;
- private EditText editTextPassword;
- //firebase auth object
- private FirebaseAuth firebaseAuth;
- //progress dialog
- private ProgressDialog progressDialog;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login_screen);
- //getting firebase auth object
- firebaseAuth = FirebaseAuth.getInstance();
- //if the objects getcurrentuser method is not null
- //means user is already logged in
- /* if(firebaseAuth.getCurrentUser() != null){
- //close this activity
- finish();
- //opening profile activity
- startActivity(new Intent(getApplicationContext(), screen_after_logged_in.class));
- }
- */
- //initializing views
- editTextEmail = (EditText) findViewById(R.id.ET_USERNAME_log);
- editTextPassword = (EditText) findViewById(R.id.ET_PASSWORD_log);
- buttonSignIn = (Button) findViewById(R.id.btn_LOGIN_log);
- progressDialog = new ProgressDialog(this);
- //attaching click listener
- buttonSignIn.setOnClickListener(this);
- }
- //method for user login
- private void userLogin(){
- String email = editTextEmail.getText().toString().trim();
- String password = editTextPassword.getText().toString().trim();
- //checking if email and passwords are empty
- if(TextUtils.isEmpty(email)){
- Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show();
- return;
- }
- if(TextUtils.isEmpty(password)){
- Toast.makeText(this,"Please enter password",Toast.LENGTH_LONG).show();
- return;
- }
- //if the email and password are not empty
- //displaying a progress dialog
- progressDialog.setMessage("Loging in");
- progressDialog.show();
- //logging in the user
- firebaseAuth.signInWithEmailAndPassword(email, password)
- .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- progressDialog.dismiss();
- //if the task is successfull
- if(task.isSuccessful()){
- //start the profile activity
- finish();
- startActivity(new Intent(getApplicationContext(), screen_after_logged_in.class));
- }
- }
- });
- }
- @Override
- public void onClick(View view) {
- if(view == buttonSignIn){
- userLogin();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement