packageorg.marcinzelent.liberavem;importandroid.content.Intent;importandroid.os.Bundle;importandroid.support.annotation.NonNull;importandroid.support.v7.app.AppCompatActivity;importandroid.support.v7.widget.Toolbar;importandroid.text.TextUtils;importandroid.view.View;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.ProgressBar;importandroid.widget.Toast;importcom.google.android.gms.tasks.OnCompleteListener;importcom.google.android.gms.tasks.Task;importcom.google.firebase.auth.AuthResult;importcom.google.firebase.auth.FirebaseAuth;publicclassLoginActivityextendsAppCompatActivity{privateEditTextinputEmail,inputPassword;privateFirebaseAuthauth;privateProgressBarprogressBar;privateButtonbtnSignup,btnLogin,btnReset;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);//Get Firebase auth instanceauth=FirebaseAuth.getInstance();if(auth.getCurrentUser()!=null){startActivity(newIntent(LoginActivity.this,MainActivity.class));finish();}// set the view nowsetContentView(R.layout.activity_login);Toolbartoolbar=(Toolbar)findViewById(R.id.toolbar);setSupportActionBar(toolbar);inputEmail=(EditText)findViewById(R.id.email);inputPassword=(EditText)findViewById(R.id.password);progressBar=(ProgressBar)findViewById(R.id.progressBar);btnSignup=(Button)findViewById(R.id.btn_signup);btnLogin=(Button)findViewById(R.id.btn_login);btnReset=(Button)findViewById(R.id.btn_reset_password);//Get Firebase auth instanceauth=FirebaseAuth.getInstance();btnSignup.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){startActivity(newIntent(LoginActivity.this,SignupActivity.class));}});btnReset.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){startActivity(newIntent(LoginActivity.this,ResetPasswordActivity.class));}});btnLogin.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){Stringemail=inputEmail.getText().toString();finalStringpassword=inputPassword.getText().toString();if(TextUtils.isEmpty(email)){Toast.makeText(getApplicationContext(),"Enter email address!",Toast.LENGTH_SHORT).show();return;}if(TextUtils.isEmpty(password)){Toast.makeText(getApplicationContext(),"Enter password!",Toast.LENGTH_SHORT).show();return;}progressBar.setVisibility(View.VISIBLE);//authenticate userauth.signInWithEmailAndPassword(email,password).addOnCompleteListener(LoginActivity.this,newOnCompleteListener<AuthResult>(){@OverridepublicvoidonComplete(@NonNullTask<AuthResult>task){// If sign in fails, display a message to the user. If sign in succeeds// the auth state listener will be notified and logic to handle the// signed in user can be handled in the listener.progressBar.setVisibility(View.GONE);if(!task.isSuccessful()){// there was an errorif(password.length()<6){inputPassword.setError(getString(R.string.minimum_password));}else{Toast.makeText(LoginActivity.this,getString(R.string.auth_failed),Toast.LENGTH_LONG).show();}}else{Intentintent=newIntent(LoginActivity.this,MainActivity.class);startActivity(intent);finish();}}});}});}}