Skip to content

Commit 7ee8ef5

Browse files
Part-9
1 parent 34f7af9 commit 7ee8ef5

File tree

3 files changed

+581
-0
lines changed

3 files changed

+581
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
package my.foodOn.app;
2+
3+
import androidx.annotation.NonNull;
4+
import androidx.appcompat.app.AppCompatActivity;
5+
6+
import android.app.AlertDialog;
7+
import android.app.ProgressDialog;
8+
import android.content.DialogInterface;
9+
import android.content.Intent;
10+
import android.os.Bundle;
11+
import android.text.TextUtils;
12+
import android.view.View;
13+
import android.widget.AdapterView;
14+
import android.widget.ArrayAdapter;
15+
import android.widget.Button;
16+
import android.widget.Spinner;
17+
18+
import com.google.android.gms.tasks.OnCompleteListener;
19+
import com.google.android.gms.tasks.Task;
20+
import com.google.android.material.textfield.TextInputLayout;
21+
import com.google.firebase.auth.AuthResult;
22+
import com.google.firebase.auth.FirebaseAuth;
23+
import com.google.firebase.database.DatabaseReference;
24+
import com.google.firebase.database.FirebaseDatabase;
25+
import com.hbb20.CountryCodePicker;
26+
27+
import java.util.ArrayList;
28+
import java.util.HashMap;
29+
30+
31+
32+
public class ChefRegistration extends AppCompatActivity {
33+
String[] Maharashtra = {"Mumbai","Pune","Nashik"};
34+
String[] Madhyapradesh = {"Bhopal","Indore","Ujjain"};
35+
36+
TextInputLayout Fname,Lname,Email,Pass,cpass,mobileno,houseno,area,pincode;
37+
Spinner Statespin,Cityspin;
38+
Button signup, Emaill, Phone;
39+
CountryCodePicker Cpp;
40+
FirebaseAuth FAuth;
41+
DatabaseReference databaseReference;
42+
FirebaseDatabase firebaseDatabase;
43+
String fname,lname,emailid,password,confpassword,mobile,house,Area,Pincode,statee,cityy;
44+
String role="Chef";
45+
46+
@Override
47+
protected void onCreate(Bundle savedInstanceState) {
48+
super.onCreate(savedInstanceState);
49+
setContentView(R.layout.activity_chef_registration);
50+
51+
Fname = (TextInputLayout)findViewById(R.id.Firstname);
52+
Lname = (TextInputLayout)findViewById(R.id.Lastname);
53+
Email = (TextInputLayout)findViewById(R.id.Email);
54+
Pass = (TextInputLayout)findViewById(R.id.Pwd);
55+
cpass = (TextInputLayout)findViewById(R.id.Cpass);
56+
mobileno = (TextInputLayout)findViewById(R.id.Mobileno);
57+
houseno = (TextInputLayout)findViewById(R.id.houseNo);
58+
pincode = (TextInputLayout)findViewById(R.id.Pincode);
59+
Statespin = (Spinner) findViewById(R.id.Statee);
60+
Cityspin = (Spinner) findViewById(R.id.Citys);
61+
area = (TextInputLayout)findViewById(R.id.Area);
62+
63+
signup = (Button)findViewById(R.id.Signup);
64+
Emaill = (Button)findViewById(R.id.email);
65+
Phone = (Button)findViewById(R.id.phone);
66+
67+
Cpp = (CountryCodePicker)findViewById(R.id.CountryCode);
68+
69+
Statespin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
70+
@Override
71+
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
72+
73+
Object value = parent.getItemAtPosition(position);
74+
statee = value.toString().trim();
75+
if(statee.equals("Maharashtra")){
76+
ArrayList<String> list = new ArrayList<>();
77+
for (String cities : Maharashtra){
78+
list.add(cities);
79+
}
80+
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(ChefRegistration.this,android.R.layout.simple_spinner_item,list);
81+
Cityspin.setAdapter(arrayAdapter);
82+
}
83+
if(statee.equals("Madhyapradesh")){
84+
ArrayList<String> list = new ArrayList<>();
85+
for (String cities : Madhyapradesh){
86+
list.add(cities);
87+
}
88+
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(ChefRegistration.this,android.R.layout.simple_spinner_item,list);
89+
Cityspin.setAdapter(arrayAdapter);
90+
}
91+
92+
}
93+
94+
@Override
95+
public void onNothingSelected(AdapterView<?> parent) {
96+
97+
}
98+
});
99+
100+
Cityspin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
101+
@Override
102+
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
103+
Object value = parent.getItemAtPosition(position);
104+
cityy = value.toString().trim();
105+
106+
}
107+
108+
@Override
109+
public void onNothingSelected(AdapterView<?> parent) {
110+
111+
}
112+
});
113+
114+
databaseReference = firebaseDatabase.getInstance().getReference("Chef");
115+
FAuth = FirebaseAuth.getInstance();
116+
117+
signup.setOnClickListener(new View.OnClickListener() {
118+
@Override
119+
public void onClick(View v) {
120+
121+
fname = Fname.getEditText().getText().toString().trim();
122+
lname = Lname.getEditText().getText().toString().trim();
123+
emailid = Email.getEditText().getText().toString().trim();
124+
mobile = mobileno.getEditText().getText().toString().trim();
125+
password = Pass.getEditText().getText().toString().trim();
126+
confpassword = cpass.getEditText().getText().toString().trim();
127+
Area = area.getEditText().getText().toString().trim();
128+
house = houseno.getEditText().getText().toString().trim();
129+
Pincode = pincode.getEditText().getText().toString().trim();
130+
131+
if (isValid()){
132+
final ProgressDialog mDialog = new ProgressDialog(ChefRegistration.this);
133+
mDialog.setCancelable(false);
134+
mDialog.setCanceledOnTouchOutside(false);
135+
mDialog.setMessage("Registration in progress please wait......");
136+
mDialog.show();
137+
138+
FAuth.createUserWithEmailAndPassword(emailid,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
139+
@Override
140+
public void onComplete(@NonNull Task<AuthResult> task) {
141+
142+
if (task.isSuccessful()){
143+
String useridd = FirebaseAuth.getInstance().getCurrentUser().getUid();
144+
databaseReference = FirebaseDatabase.getInstance().getReference("User").child(useridd);
145+
final HashMap<String , String> hashMap = new HashMap<>();
146+
hashMap.put("Role",role);
147+
databaseReference.setValue(hashMap).addOnCompleteListener(new OnCompleteListener<Void>() {
148+
@Override
149+
public void onComplete(@NonNull Task<Void> task) {
150+
151+
HashMap<String , String> hashMap1 = new HashMap<>();
152+
hashMap1.put("Mobile No",mobile);
153+
hashMap1.put("First Name",fname);
154+
hashMap1.put("Last Name",lname);
155+
hashMap1.put("EmailId",emailid);
156+
hashMap1.put("City",cityy);
157+
hashMap1.put("Area",Area);
158+
hashMap1.put("Password",password);
159+
hashMap1.put("Pincode",Pincode);
160+
hashMap1.put("State",statee);
161+
hashMap1.put("Confirm Password",confpassword);
162+
hashMap1.put("House",house);
163+
164+
firebaseDatabase.getInstance().getReference("Chef")
165+
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
166+
.setValue(hashMap1).addOnCompleteListener(new OnCompleteListener<Void>() {
167+
@Override
168+
public void onComplete(@NonNull Task<Void> task) {
169+
mDialog.dismiss();
170+
171+
FAuth.getCurrentUser().sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
172+
@Override
173+
public void onComplete(@NonNull Task<Void> task) {
174+
175+
if(task.isSuccessful()){
176+
AlertDialog.Builder builder = new AlertDialog.Builder(ChefRegistration.this);
177+
builder.setMessage("You Have Registered! Make Sure To Verify Your Email");
178+
builder.setCancelable(false);
179+
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
180+
@Override
181+
public void onClick(DialogInterface dialog, int which) {
182+
183+
dialog.dismiss();
184+
185+
String phonenumber = Cpp.getSelectedCountryCodeWithPlus() + mobile;
186+
Intent b = new Intent(ChefRegistration.this,ChefVerifyPhone.class);
187+
b.putExtra("phonenumber",phonenumber);
188+
startActivity(b);
189+
190+
}
191+
});
192+
AlertDialog Alert = builder.create();
193+
Alert.show();
194+
}else{
195+
mDialog.dismiss();
196+
ReusableCodeForAll.ShowAlert(ChefRegistration.this,"Error",task.getException().getMessage());
197+
}
198+
}
199+
});
200+
201+
}
202+
});
203+
204+
}
205+
});
206+
}
207+
}
208+
});
209+
}
210+
//
211+
}
212+
});
213+
214+
}
215+
216+
String emailpattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
217+
public boolean isValid(){
218+
Email.setErrorEnabled(false);
219+
Email.setError("");
220+
Fname.setErrorEnabled(false);
221+
Fname.setError("");
222+
Lname.setErrorEnabled(false);
223+
Lname.setError("");
224+
Pass.setErrorEnabled(false);
225+
Pass.setError("");
226+
mobileno.setErrorEnabled(false);
227+
mobileno.setError("");
228+
cpass.setErrorEnabled(false);
229+
cpass.setError("");
230+
area.setErrorEnabled(false);
231+
area.setError("");
232+
houseno.setErrorEnabled(false);
233+
houseno.setError("");
234+
pincode.setErrorEnabled(false);
235+
pincode.setError("");
236+
237+
boolean isValid=false,isValidhouseno=false,isValidlname=false,isValidname=false,isValidemail=false,isValidpassword=false,isValidconfpassword=false,isValidmobilenum=false,isValidarea=false,isValidpincode=false;
238+
if(TextUtils.isEmpty(fname)){
239+
Fname.setErrorEnabled(true);
240+
Fname.setError("Enter First Name");
241+
}else{
242+
isValidname = true;
243+
}
244+
if(TextUtils.isEmpty(lname)){
245+
Lname.setErrorEnabled(true);
246+
Lname.setError("Enter Last Name");
247+
}else{
248+
isValidlname = true;
249+
}
250+
if(TextUtils.isEmpty(emailid)){
251+
Email.setErrorEnabled(true);
252+
Email.setError("Email Is Required");
253+
}else{
254+
if(emailid.matches(emailpattern)){
255+
isValidemail = true;
256+
}else{
257+
Email.setErrorEnabled(true);
258+
Email.setError("Enter a Valid Email Id");
259+
}
260+
}
261+
if(TextUtils.isEmpty(password)){
262+
Pass.setErrorEnabled(true);
263+
Pass.setError("Enter Password");
264+
}else{
265+
if(password.length()<8){
266+
Pass.setErrorEnabled(true);
267+
Pass.setError("Password is Weak");
268+
}else{
269+
isValidpassword = true;
270+
}
271+
}
272+
if(TextUtils.isEmpty(confpassword)){
273+
cpass.setErrorEnabled(true);
274+
cpass.setError("Enter Password Again");
275+
}else{
276+
if(!password.equals(confpassword)){
277+
cpass.setErrorEnabled(true);
278+
cpass.setError("Password Dosen't Match");
279+
}else{
280+
isValidconfpassword = true;
281+
}
282+
}
283+
if(TextUtils.isEmpty(mobile)){
284+
mobileno.setErrorEnabled(true);
285+
mobileno.setError("Mobile Number Is Required");
286+
}else{
287+
if(mobile.length()<10){
288+
mobileno.setErrorEnabled(true);
289+
mobileno.setError("Invalid Mobile Number");
290+
}else{
291+
isValidmobilenum = true;
292+
}
293+
}
294+
if(TextUtils.isEmpty(Area)){
295+
area.setErrorEnabled(true);
296+
area.setError("Area Is Required");
297+
}else{
298+
isValidarea = true;
299+
}
300+
if(TextUtils.isEmpty(Pincode)){
301+
pincode.setErrorEnabled(true);
302+
pincode.setError("Please Enter Pincode");
303+
}else{
304+
isValidpincode = true;
305+
}
306+
if(TextUtils.isEmpty(house)){
307+
houseno.setErrorEnabled(true);
308+
houseno.setError("Fields Can't Be Empty");
309+
}else{
310+
isValidhouseno = true;
311+
}
312+
313+
isValid = (isValidarea && isValidconfpassword && isValidpassword && isValidpincode && isValidemail && isValidmobilenum && isValidname && isValidhouseno && isValidlname) ? true : false;
314+
return isValid;
315+
316+
317+
}
318+
}

0 commit comments

Comments
 (0)