我正在尝试使用自动生成的参考代码创建Google登录名,登录已成功完成,并且在Firebase数据库中更新了自动生成的代码。
问题是注册用户将此自动生成的代码共享给其他新用户以使用此引用代码。而新用户正在使用参考代码。并获得一些积分,但是旧用户没有获得积分(共享用户)积分有什么问题,请检查给定的代码(Android Studio)
我们还可以下载Login.java活动
private void handleFacebookAccessToken(AccessToken token) {
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
if (pDialog != null && pDialog.isShowing())
pDialog.dismiss();
Toast.makeText(Login.this, "login successfully…", Toast.LENGTH_LONG).show();
final String code = randomAlphaNumeric(8);
final DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child("register");
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
if (!dataSnapshot.hasChild(FirebaseAuth.getInstance().getCurrentUser().getUid())) {
mDatabase.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("rate").setValue(false);
mDatabase.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("code").setValue(code);
mDatabase.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("first").setValue(false).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
if (refercode == true) {
String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
Model model = new Model("Referral code", date, "" +REFER_POINT,claim);
FirebaseDatabase.getInstance().getReference().child("users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("coin").push().setValue(model);
FirebaseDatabase.getInstance().getReference().child("register").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("first").setValue(true);
}
}
});
} else {
Boolean first = false;
if (refercode == true) {
if (dataSnapshot.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).hasChild("first"))
if ((dataSnapshot.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("first").getValue()).equals(false)) {
first = true;
String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
Model model = new Model("Referral code", date, "" + REFER_POINT,claim);
FirebaseDatabase.getInstance().getReference().child("users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("coin").push().setValue(model);
FirebaseDatabase.getInstance().getReference().child("register").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("first").setValue(true);
}
if (first == false) {
refer.setText("");
Toast.makeText(Login.this, "You have used Referral code..", Toast.LENGTH_SHORT).show();
}
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Intent intent = new Intent(Login.this, HomeActiviry.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
} else {
Toast.makeText(Login.this, "" + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}