Advertisement
aniksajli

Patient_SignUp.java

Nov 10th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. package com.example.android.patientsignup;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.support.annotation.NonNull;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.text.TextUtils;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12.  
  13. import com.example.android.patientsignup.R;
  14. import com.google.android.gms.tasks.OnCompleteListener;
  15. import com.google.android.gms.tasks.Task;
  16. import com.google.firebase.auth.AuthResult;
  17. import com.google.firebase.auth.FirebaseAuth;
  18. import com.google.firebase.database.FirebaseDatabase;
  19.  
  20.  
  21. public class Patient_SignUp extends AppCompatActivity implements View.OnClickListener {
  22.  
  23. private EditText editName,editGender,editAge, editArea, editEmail,editPassword, editPhoneNumber;
  24. private Button signUp;
  25. private ProgressDialog progressDialog;
  26. private String name,gender,age, area,email,password, phoneNumber;
  27. private FirebaseAuth mAuth;
  28.  
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.activity_patient__sign_up);
  33.  
  34. mAuth = FirebaseAuth.getInstance();
  35.  
  36. editName = findViewById(R.id.patientName_id);
  37. editAge = findViewById(R.id.patientAgeId);
  38. editGender = findViewById(R.id.patientGenderId);
  39. editArea = findViewById(R.id.patientAreaId);
  40. editPhoneNumber = findViewById(R.id.patientPhoneNumber_Id)
  41. editEmail = findViewById(R.id.patientEmail_Id);
  42. editPassword = findViewById(R.id.patientPassword_Id);
  43.  
  44. signUp = findViewById(R.id.patientSignUpButton_Id);
  45. signUp.setOnClickListener(this);
  46.  
  47. progressDialog = new ProgressDialog(this);
  48.  
  49.  
  50. }
  51.  
  52. private void registration()
  53. {
  54. name = editName.getText().toString().trim();
  55. gender = editGender.getText().toString().trim();
  56. age = editAge.getText().toString().trim();
  57. area = editArea.getText().toString().trim();
  58. phoneNumber = editPhoneNumber.getText().toString().trim();
  59. email = editEmail.getText().toString().trim();
  60. password = editPassword.getText().toString().trim();
  61.  
  62.  
  63. if(TextUtils.isEmpty(email)){
  64. editEmail.setError("Email Can't be Empty");
  65. editEmail.requestFocus();
  66. return;
  67.  
  68. }
  69.  
  70. if(TextUtils.isEmpty(password)){
  71. editPassword.setError("Password Can't be Empty");
  72. editPassword.requestFocus();
  73. return;
  74.  
  75. }
  76. if (password.length() < 6) {
  77. editPassword.setError("Minimum Password length 6");
  78. editPassword.requestFocus();
  79. return;
  80. }
  81.  
  82. if(name.isEmpty())
  83. {
  84. editName.setError("Name ccan't be empty");
  85. editName.requestFocus();
  86. return;
  87. }
  88. progressDialog.setMessage("Registration in process...");
  89. progressDialog.show();
  90.  
  91.  
  92.  
  93. mAuth.createUserWithEmailAndPassword(email,password)
  94. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  95. @Override
  96. public void onComplete(@NonNull Task<AuthResult> task) {
  97. if(task.isSuccessful()){
  98. progressDialog.dismiss();
  99.  
  100. Patient_Info user = new Patient_Info(name, gender, age, area, phoneNumber, email);
  101.  
  102. FirebaseDatabase.getInstance().getReference("Users")
  103. .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
  104. .setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
  105. @Override
  106. public void onComplete(@NonNull Task<Void> ttask) {
  107.  
  108. if (ttask.isSuccessful()) {
  109. Toast.makeText(Patient_SignUp.this, "Resistration Successful", Toast.LENGTH_LONG).show();
  110. finish();
  111. } else {
  112. //display a failure message
  113. Toast.makeText(Patient_SignUp.this,ttask.getException().getMessage(),Toast.LENGTH_LONG).show();
  114. }
  115. }
  116. });
  117.  
  118. //startActivity(new Intent(getApplicationContext(),UserCatagory.class));
  119. //Toast.makeText(SignUp.this,"Registered Succeessful",Toast.LENGTH_SHORT).show();
  120. }
  121. else
  122. {
  123. progressDialog.dismiss();
  124. Toast.makeText(Patient_SignUp.this, task.getException().getMessage(), Toast.LENGTH_LONG).show(); }
  125.  
  126. }
  127. });
  128.  
  129.  
  130. }
  131.  
  132. @Override
  133. public void onClick(View view) {
  134. if(view == signUp)
  135. {
  136. Toast.makeText(Patient_SignUp.this,"SignUp pressed",Toast.LENGTH_SHORT).show();
  137. registration();
  138. }
  139. }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement