1
+ package my .foodOn .app ;
2
+
3
+ import androidx .annotation .NonNull ;
4
+ import androidx .appcompat .app .AppCompatActivity ;
5
+
6
+ import android .app .ProgressDialog ;
7
+ import android .content .Intent ;
8
+ import android .os .Bundle ;
9
+ import android .text .TextUtils ;
10
+ import android .view .View ;
11
+ import android .widget .Button ;
12
+ import android .widget .TextView ;
13
+ import android .widget .Toast ;
14
+
15
+ import com .google .android .gms .tasks .OnCompleteListener ;
16
+ import com .google .android .gms .tasks .Task ;
17
+ import com .google .android .material .textfield .TextInputLayout ;
18
+ import com .google .firebase .auth .AuthResult ;
19
+ import com .google .firebase .auth .FirebaseAuth ;
20
+
21
+ public class Cheflogin extends AppCompatActivity {
22
+
23
+ TextInputLayout email ,pass ;
24
+ Button Signin ,Signinphone ;
25
+ TextView Forgotpassword , signup ;
26
+ FirebaseAuth Fauth ;
27
+ String emailid ,pwd ;
28
+
29
+ @ Override
30
+ protected void onCreate (Bundle savedInstanceState ) {
31
+ super .onCreate (savedInstanceState );
32
+ setContentView (R .layout .activity_cheflogin );
33
+
34
+ try {
35
+
36
+ email = (TextInputLayout )findViewById (R .id .Lemail );
37
+ pass = (TextInputLayout )findViewById (R .id .Lpassword );
38
+ Signin = (Button )findViewById (R .id .button4 );
39
+ signup = (TextView ) findViewById (R .id .textView3 );
40
+ Forgotpassword = (TextView )findViewById (R .id .forgotpass );
41
+ Signinphone = (Button )findViewById (R .id .btnphone );
42
+
43
+ Fauth = FirebaseAuth .getInstance ();
44
+
45
+ Signin .setOnClickListener (new View .OnClickListener () {
46
+ @ Override
47
+ public void onClick (View v ) {
48
+
49
+ emailid = email .getEditText ().getText ().toString ().trim ();
50
+ pwd = pass .getEditText ().getText ().toString ().trim ();
51
+
52
+ if (isValid ()){
53
+
54
+ final ProgressDialog mDialog = new ProgressDialog (Cheflogin .this );
55
+ mDialog .setCanceledOnTouchOutside (false );
56
+ mDialog .setCancelable (false );
57
+ mDialog .setMessage ("Sign In Please Wait......." );
58
+ mDialog .show ();
59
+
60
+ Fauth .signInWithEmailAndPassword (emailid ,pwd ).addOnCompleteListener (new OnCompleteListener <AuthResult >() {
61
+ @ Override
62
+ public void onComplete (@ NonNull Task <AuthResult > task ) {
63
+
64
+ if (task .isSuccessful ()){
65
+ mDialog .dismiss ();
66
+
67
+ if (Fauth .getCurrentUser ().isEmailVerified ()){
68
+ mDialog .dismiss ();
69
+ Toast .makeText (Cheflogin .this , "Congratulation! You Have Successfully Login" , Toast .LENGTH_SHORT ).show ();
70
+ Intent Z = new Intent (Cheflogin .this ,ChefFoodPanel_BottomNavigation .class );
71
+ startActivity (Z );
72
+ finish ();
73
+
74
+ }else {
75
+ ReusableCodeForAll .ShowAlert (Cheflogin .this ,"Verification Failed" ,"You Have Not Verified Your Email" );
76
+
77
+ }
78
+ }else {
79
+ mDialog .dismiss ();
80
+ ReusableCodeForAll .ShowAlert (Cheflogin .this ,"Error" ,task .getException ().getMessage ());
81
+ }
82
+ }
83
+ });
84
+ }
85
+ }
86
+ });
87
+ signup .setOnClickListener (new View .OnClickListener () {
88
+ @ Override
89
+ public void onClick (View v ) {
90
+ startActivity (new Intent (Cheflogin .this ,ChefRegistration .class ));
91
+ finish ();
92
+ }
93
+ });
94
+ Forgotpassword .setOnClickListener (new View .OnClickListener () {
95
+ @ Override
96
+ public void onClick (View v ) {
97
+ startActivity (new Intent (Cheflogin .this ,ChefForgotPassword .class ));
98
+ finish ();
99
+ }
100
+ });
101
+ Signinphone .setOnClickListener (new View .OnClickListener () {
102
+ @ Override
103
+ public void onClick (View v ) {
104
+ startActivity (new Intent (Cheflogin .this ,Chefloginphone .class ));
105
+ finish ();
106
+ }
107
+ });
108
+ }catch (Exception e ){
109
+ Toast .makeText (this ,e .getMessage (),Toast .LENGTH_LONG ).show ();
110
+ }
111
+
112
+ }
113
+ String emailpattern = "[a-zA-Z0-9._-]+@[a-z]+\\ .+[a-z]+" ;
114
+
115
+ public boolean isValid (){
116
+
117
+ email .setErrorEnabled (false );
118
+ email .setError ("" );
119
+ pass .setErrorEnabled (false );
120
+ pass .setError ("" );
121
+
122
+ boolean isvalid =false ,isvalidemail =false ,isvalidpassword =false ;
123
+ if (TextUtils .isEmpty (emailid )){
124
+ email .setErrorEnabled (true );
125
+ email .setError ("Email is required" );
126
+ }else {
127
+ if (emailid .matches (emailpattern )){
128
+ isvalidemail =true ;
129
+ }else {
130
+ email .setErrorEnabled (true );
131
+ email .setError ("Invalid Email Address" );
132
+ }
133
+ }
134
+ if (TextUtils .isEmpty (pwd )){
135
+
136
+ pass .setErrorEnabled (true );
137
+ pass .setError ("Password is Required" );
138
+ }else {
139
+ isvalidpassword =true ;
140
+ }
141
+ isvalid =(isvalidemail && isvalidpassword )?true :false ;
142
+ return isvalid ;
143
+ }
144
+ }
0 commit comments