Advertisement
Guest User

Untitled

a guest
Jan 25th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. EditText username, fullname, email, password, password2;
  2. Button register;
  3. TextView txt_login;
  4.  
  5. private static final int RC_SIGN_IN = 9001;
  6. private GoogleApiClient mGoogleApiClient;
  7. FirebaseAuth auth, mAuth;
  8.  
  9. DatabaseReference reference, reference2;
  10. ProgressDialog pd;
  11.  
  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.activity_register);
  16.  
  17.  
  18.  
  19. username = findViewById(R.id.username);
  20. email = findViewById(R.id.email);
  21. fullname = findViewById(R.id.fullname);
  22. password = findViewById(R.id.password);
  23. password2 = findViewById(R.id.password2);
  24. register = findViewById(R.id.register);
  25. txt_login = findViewById(R.id.txt_login);
  26.  
  27. auth = FirebaseAuth.getInstance();
  28. mAuth = FirebaseAuth.getInstance();
  29.  
  30. txt_login.setOnClickListener(new View.OnClickListener() {
  31. @Override
  32. public void onClick(View view) {
  33. startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
  34. }
  35. });
  36.  
  37. register.setOnClickListener(new View.OnClickListener() {
  38. @Override
  39. public void onClick(View view) {
  40. pd = new ProgressDialog(RegisterActivity.this);
  41. pd.setMessage("Please wait...");
  42. pd.show();
  43.  
  44. String str_username = username.getText().toString();
  45. String str_fullname = fullname.getText().toString();
  46. String str_email = email.getText().toString();
  47. String str_password = password.getText().toString();
  48. String str_password2 = password2.getText().toString();
  49.  
  50. if (TextUtils.isEmpty(str_username) || TextUtils.isEmpty(str_fullname) || TextUtils.isEmpty(str_email) || TextUtils.isEmpty(str_password) || TextUtils.isEmpty(str_password2)){
  51. pd.dismiss();
  52. Toast.makeText(RegisterActivity.this, "All fields are required!", Toast.LENGTH_SHORT).show();
  53. } else if(str_password.length() < 6){
  54. pd.dismiss();
  55. Toast.makeText(RegisterActivity.this, "Password must have 6 characters!", Toast.LENGTH_SHORT).show();
  56. }else if(!str_password.equals(str_password2)){
  57. pd.dismiss();
  58. Toast.makeText(RegisterActivity.this, "Passwords does not match", Toast.LENGTH_SHORT).show();
  59. } else {
  60. register(str_username, str_fullname, str_email, str_password);
  61. }
  62. }
  63. });
  64.  
  65. //google login
  66.  
  67. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
  68. .requestIdToken(getString(R.string.default_web_client_id))
  69. .requestEmail()
  70. .build();
  71.  
  72. mGoogleApiClient = new GoogleApiClient.Builder(this)
  73. .enableAutoManage(this, this)
  74. .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
  75. .build();
  76.  
  77. SignInButton button = (SignInButton) findViewById(R.id.GoogleLogin);
  78. button.setOnClickListener(new View.OnClickListener() {
  79. @Override
  80. public void onClick(View v) {
  81. Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
  82. startActivityForResult(signInIntent, RC_SIGN_IN);
  83. }
  84. });
  85.  
  86. @Override
  87. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  88. super.onActivityResult(requestCode, resultCode, data);
  89.  
  90. // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
  91. if (requestCode == RC_SIGN_IN) {
  92. GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
  93. if (result.isSuccess()) {
  94. // Google Sign In was successful, authenticate with Firebase
  95. GoogleSignInAccount account = result.getSignInAccount();
  96. firebaseAuthWithGoogle(account);
  97. } else {
  98. // Google Sign In failed, update UI appropriately
  99. // ...
  100. }
  101. }
  102. }
  103.  
  104.  
  105.  
  106. private void firebaseAuthWithGoogle (GoogleSignInAccount acct){
  107. AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
  108. mAuth.signInWithCredential(credential)
  109. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  110. @Override
  111. public void onComplete(@NonNull Task<AuthResult> task) {
  112. if (task.isSuccessful()) {
  113. FirebaseUser firebaseUser = mAuth.getCurrentUser();
  114. String userID = firebaseUser.getUid();
  115.  
  116. reference = FirebaseDatabase.getInstance().getReference().child("Users").child(userID);
  117. HashMap<String, Object> map = new HashMap<>();
  118. map.put("id", userID);
  119. map.put("username", username);
  120. map.put("fullname", fullname);
  121. map.put("imageurl", "https://firebasestorage.googleapis.com/v0/b/instagramtest-fcbef.appspot.com/o/placeholder.png?alt=media&token=b09b809d-a5f8-499b-9563-5252262e9a49");
  122. map.put("bio", "");
  123. reference.setValue(map).addOnCompleteListener(new OnCompleteListener<Void>() {
  124. @Override
  125. public void onComplete(@NonNull Task<Void> task) {
  126. if (task.isSuccessful()){
  127. pd.dismiss();
  128. Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
  129. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
  130. startActivity(intent);
  131. }
  132. }
  133. });
  134. } else {
  135. // If sign in fails, display a message to the user.
  136. //Log.w(TAG, "signInWithCredential:failure", task.getException());
  137. // Toast.makeText(GoogleSignInActivity.this, "Authentication failed.",
  138. // Toast.LENGTH_SHORT).show();
  139. // updateUI(null);
  140. }
  141.  
  142. // ...
  143. }
  144. });
  145. }
  146.  
  147.  
  148. @Override
  149. public void onConnectionFailed (@NonNull ConnectionResult connectionResult){
  150.  
  151. }
  152.  
  153. java.lang.NoSuchMethodError: No virtual method zzbqo()Z in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com.devkang.instagramtest-0yUpiRLjYo6Yjvmds4v0zA==/split_lib_dependencies_apk.apk)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement