PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/OnlineScheduler/app/src/main/java/com/example/ranjith/jpmconlinescheduler/WorkFlow/Registration.java

https://bitbucket.org/vnrjpmc/onlinescheduler
Java | 227 lines | 162 code | 55 blank | 10 comment | 17 complexity | 7298a771d55dd87e5747dad49b24634c MD5 | raw file
  1. package com.example.ranjith.jpmconlinescheduler.WorkFlow;
  2. import android.app.ProgressDialog;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.os.Bundle;
  7. import android.support.annotation.NonNull;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.text.TextUtils;
  10. import android.view.View;
  11. import android.widget.AdapterView;
  12. import android.widget.ArrayAdapter;
  13. import android.widget.EditText;
  14. import android.widget.Spinner;
  15. import android.widget.Toast;
  16. import com.example.ranjith.jpmconlinescheduler.R;
  17. import com.example.ranjith.jpmconlinescheduler.Util.JpmcToast;
  18. import com.example.ranjith.jpmconlinescheduler.Util.Utils;
  19. import com.google.android.gms.tasks.OnCompleteListener;
  20. import com.google.android.gms.tasks.Task;
  21. import com.google.firebase.auth.AuthResult;
  22. import com.google.firebase.auth.FirebaseAuth;
  23. import com.google.firebase.auth.FirebaseUser;
  24. import com.google.firebase.database.DatabaseReference;
  25. import com.google.firebase.database.FirebaseDatabase;
  26. import java.util.ArrayList;
  27. import java.util.regex.Matcher;
  28. import java.util.regex.Pattern;
  29. public class Registration extends AppCompatActivity {
  30. ArrayList<String> arrayList;
  31. private String var = "SELECT BRANCH";
  32. EditText mobile, name, password, c_password, email;
  33. ProgressDialog progressDialog;
  34. public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
  35. Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
  36. public static final Pattern VALID_MOBILE_ADDRESS_REGEX =
  37. Pattern.compile("(0/91)?[7-9][0-9]{9}$", Pattern.CASE_INSENSITIVE);
  38. @Override
  39. protected void onCreate(Bundle savedInstanceState) {
  40. super.onCreate(savedInstanceState);
  41. setContentView(R.layout.activity_register);
  42. SharedPreferences shared = getSharedPreferences("loginData", Context.MODE_PRIVATE);
  43. Toast.makeText(getApplicationContext(), shared.getString("user", ""), Toast.LENGTH_LONG).show();
  44. }
  45. private void addItems() {
  46. arrayList.add(" JNTU");
  47. arrayList.add(" JEEDIMETLA");
  48. arrayList.add(" SECUNDERABAD");
  49. arrayList.add(" UPPAL");
  50. arrayList.add(" KUKATPALLY");
  51. arrayList.add(" BACHUPALLY");
  52. arrayList.add(" AMEERPET");
  53. arrayList.add(" BALANAGAR");
  54. }
  55. public void register(View view) {
  56. if (Utils.hasActiveInternetConnection(Registration.this)) {
  57. progressDialog = Utils.showLoadingDialog(Registration.this, false);
  58. name = (EditText) findViewById(R.id.mobile);
  59. email = (EditText) findViewById(R.id.email);
  60. password = (EditText) findViewById(R.id.password);
  61. c_password = (EditText) findViewById(R.id.cpassword);
  62. Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(email.getText().toString());
  63. final FirebaseAuth mAuth;
  64. if (matcher.find()) {
  65. //Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
  66. if (!TextUtils.isEmpty(name.getText().toString())) {
  67. if (password.getText().toString().equals(c_password.getText().toString())) {
  68. if (password.getText().toString().length() >= 6) {
  69. // if (!var.equals(" SELECT BRANCH")) {
  70. mAuth = FirebaseAuth.getInstance();
  71. Task<AuthResult> authResultTask = mAuth.createUserWithEmailAndPassword(email.getText().toString()
  72. , password.getText().toString())
  73. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  74. @Override
  75. public void onComplete(@NonNull Task<AuthResult> task) {
  76. if (task.isSuccessful()) {
  77. // mAuth.reload();
  78. // mAuth.getCurrentUser().reload();
  79. //boolean emailVerified = mAuth.getCurrentUser().isEmailVerified();
  80. progressDialog.cancel();
  81. emailVerification();
  82. storeDetails();
  83. Intent intent = new Intent(Registration.this, MainActivity.class);
  84. SharedPreferences shared = getSharedPreferences("loginData", Context.MODE_PRIVATE);
  85. SharedPreferences.Editor editor = shared.edit();
  86. editor.putString("activity","register");
  87. editor.putString("user", email.getText().toString());
  88. editor.commit();
  89. Toast.makeText(Registration.this, "Successfully Registered..Thanks for Being a part of us..!", Toast.LENGTH_SHORT).show();
  90. startActivity(intent);
  91. Toast.makeText(getBaseContext(), "Job Done..!", Toast.LENGTH_LONG).show();
  92. }
  93. if (!task.isSuccessful()) {
  94. progressDialog.cancel();
  95. Toast.makeText(getBaseContext(), "E-mail I'd already exists",
  96. Toast.LENGTH_SHORT).show();
  97. }
  98. // ...
  99. }
  100. });
  101. // } else {
  102. // progressDialog.cancel();
  103. // Toast.makeText(this, "Please Select Branch", Toast.LENGTH_SHORT).show();
  104. // }
  105. } else {
  106. progressDialog.cancel();
  107. Toast.makeText(this, "Minimum length of Password is 6 characters", Toast.LENGTH_SHORT).show();
  108. }
  109. } else {
  110. progressDialog.cancel();
  111. Toast.makeText(this, "Password Mismatch", Toast.LENGTH_SHORT).show();
  112. }
  113. }
  114. else
  115. {
  116. progressDialog.cancel();
  117. Toast.makeText(this,"Please enter your Name",Toast.LENGTH_LONG).show();
  118. }
  119. }
  120. else {
  121. progressDialog.cancel();
  122. Toast.makeText(this, "Please give valid User Email", Toast.LENGTH_SHORT).show();
  123. }
  124. } else {
  125. progressDialog.cancel();
  126. JpmcToast.create(this, R.drawable.ic_error_outline_black_24dp, "No Internet\nPlease try again", Toast.LENGTH_SHORT);
  127. }
  128. }
  129. private void emailVerification() {
  130. FirebaseAuth auth = FirebaseAuth.getInstance();
  131. FirebaseUser user = auth.getCurrentUser();
  132. user.sendEmailVerification()
  133. .addOnCompleteListener(new OnCompleteListener<Void>() {
  134. @Override
  135. public void onComplete(@NonNull Task<Void> task) {
  136. if (task.isSuccessful()) {
  137. progressDialog.cancel();
  138. Toast.makeText(getApplicationContext(),"Email verification link has been sent",Toast.LENGTH_LONG).show();
  139. }
  140. else
  141. {
  142. Toast.makeText(getApplicationContext(),"Email verification link sending failed",Toast.LENGTH_LONG).show();
  143. }
  144. }
  145. });
  146. }
  147. private void storeDetails() {
  148. if (Utils.hasActiveInternetConnection(Registration.this)) {
  149. progressDialog = Utils.showLoadingDialog(Registration.this, false);
  150. if (var != null) {
  151. DatabaseReference mDatabase, mDatabase1, mDatabase2, mDatabase3, mDatabase4;
  152. mDatabase = FirebaseDatabase.getInstance().getReference();
  153. mDatabase1 = mDatabase.child("Customer");
  154. mDatabase2 = mDatabase1.push();
  155. mDatabase2.child("Email").setValue(email.getText().toString());
  156. mDatabase2.child("Name").setValue(name.getText().toString());
  157. mDatabase2.child("Branch").setValue(var);
  158. mDatabase2.child("Verified").setValue("false");
  159. }
  160. else {
  161. progressDialog.cancel();
  162. Toast.makeText(getApplicationContext(), "Please choose Home branch", Toast.LENGTH_LONG).show();
  163. }
  164. } else {
  165. progressDialog.cancel();
  166. JpmcToast.create(this, R.drawable.ic_error_outline_black_24dp, "No Internet\nPlease try again", Toast.LENGTH_SHORT);
  167. }
  168. }
  169. public void back(View view){
  170. startActivity(new Intent(getApplicationContext(),SignIn.class));
  171. }
  172. }