Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EditText username, fullname, email, password, password2;
- Button register;
- TextView txt_login;
- private static final int RC_SIGN_IN = 9001;
- private GoogleApiClient mGoogleApiClient;
- FirebaseAuth auth, mAuth;
- DatabaseReference reference, reference2;
- ProgressDialog pd;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- username = findViewById(R.id.username);
- email = findViewById(R.id.email);
- fullname = findViewById(R.id.fullname);
- password = findViewById(R.id.password);
- password2 = findViewById(R.id.password2);
- register = findViewById(R.id.register);
- txt_login = findViewById(R.id.txt_login);
- auth = FirebaseAuth.getInstance();
- mAuth = FirebaseAuth.getInstance();
- txt_login.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
- }
- });
- register.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- pd = new ProgressDialog(RegisterActivity.this);
- pd.setMessage("Please wait...");
- pd.show();
- String str_username = username.getText().toString();
- String str_fullname = fullname.getText().toString();
- String str_email = email.getText().toString();
- String str_password = password.getText().toString();
- String str_password2 = password2.getText().toString();
- if (TextUtils.isEmpty(str_username) || TextUtils.isEmpty(str_fullname) || TextUtils.isEmpty(str_email) || TextUtils.isEmpty(str_password) || TextUtils.isEmpty(str_password2)){
- pd.dismiss();
- Toast.makeText(RegisterActivity.this, "All fields are required!", Toast.LENGTH_SHORT).show();
- } else if(str_password.length() < 6){
- pd.dismiss();
- Toast.makeText(RegisterActivity.this, "Password must have 6 characters!", Toast.LENGTH_SHORT).show();
- }else if(!str_password.equals(str_password2)){
- pd.dismiss();
- Toast.makeText(RegisterActivity.this, "Passwords does not match", Toast.LENGTH_SHORT).show();
- } else {
- register(str_username, str_fullname, str_email, str_password);
- }
- }
- });
- //google login
- GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
- .requestIdToken(getString(R.string.default_web_client_id))
- .requestEmail()
- .build();
- mGoogleApiClient = new GoogleApiClient.Builder(this)
- .enableAutoManage(this, this)
- .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
- .build();
- SignInButton button = (SignInButton) findViewById(R.id.GoogleLogin);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
- startActivityForResult(signInIntent, RC_SIGN_IN);
- }
- });
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
- if (requestCode == RC_SIGN_IN) {
- GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
- if (result.isSuccess()) {
- // Google Sign In was successful, authenticate with Firebase
- GoogleSignInAccount account = result.getSignInAccount();
- firebaseAuthWithGoogle(account);
- } else {
- // Google Sign In failed, update UI appropriately
- // ...
- }
- }
- }
- private void firebaseAuthWithGoogle (GoogleSignInAccount acct){
- AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
- mAuth.signInWithCredential(credential)
- .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- if (task.isSuccessful()) {
- FirebaseUser firebaseUser = mAuth.getCurrentUser();
- String userID = firebaseUser.getUid();
- reference = FirebaseDatabase.getInstance().getReference().child("Users").child(userID);
- HashMap<String, Object> map = new HashMap<>();
- map.put("id", userID);
- map.put("username", username);
- map.put("fullname", fullname);
- map.put("imageurl", "https://firebasestorage.googleapis.com/v0/b/instagramtest-fcbef.appspot.com/o/placeholder.png?alt=media&token=b09b809d-a5f8-499b-9563-5252262e9a49");
- map.put("bio", "");
- reference.setValue(map).addOnCompleteListener(new OnCompleteListener<Void>() {
- @Override
- public void onComplete(@NonNull Task<Void> task) {
- if (task.isSuccessful()){
- pd.dismiss();
- Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
- }
- }
- });
- } else {
- // If sign in fails, display a message to the user.
- //Log.w(TAG, "signInWithCredential:failure", task.getException());
- // Toast.makeText(GoogleSignInActivity.this, "Authentication failed.",
- // Toast.LENGTH_SHORT).show();
- // updateUI(null);
- }
- // ...
- }
- });
- }
- @Override
- public void onConnectionFailed (@NonNull ConnectionResult connectionResult){
- }
- 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