Search in sources :

Example 36 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.

the class LoginActivity method setView.

/**
 * Attempts to sign in or register the account specified by the login form.
 * If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual login attempt is made.
 */
private void setView(String userId, final String email) {
    final String uid = userId;
    final Context context = getApplicationContext();
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    FirebaseDatabase.getInstance().getReference().child("users").child(uid).addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            User user = dataSnapshot.getValue(User.class);
            String account_type = user.account_type;
            showProgress(false);
            if (account_type.equals("individual")) {
                Intent intent;
                intent = new Intent(LoginActivity.this, MainActivity.class);
                intent.putExtra("mEmail", email);
                startActivity(intent);
            } else if (account_type.equals("organization")) {
                Intent intent;
                intent = new Intent(LoginActivity.this, MainActivityOrg.class);
                intent.putExtra("mEmail", email);
                startActivity(intent);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return;
}
Also used : Context(android.content.Context) User(com.jexapps.bloodhub.m_Model.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) DatabaseError(com.google.firebase.database.DatabaseError) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 37 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.

the class UserProfile method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    mAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_profile);
    mUserReference = FirebaseDatabase.getInstance().getReference().child("users").child(user.getUid());
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 38 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.

the class SplashActivity method onStart.

@Override
public void onStart() {
    super.onStart();
    mAuth = FirebaseAuth.getInstance();
    FirebaseUser currentUser = mAuth.getCurrentUser();
    if (currentUser != null) {
        setView(currentUser.getUid(), currentUser.getEmail());
    } else {
        setContentView(R.layout.activity_fscreen);
        Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SplashActivity.this, EmergencyRequestActivity.class);
                startActivity(intent);
            }
        });
        Button button1 = (Button) findViewById(R.id.button2);
        button1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
                startActivity(intent);
            }
        });
    }
}
Also used : Button(android.widget.Button) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser) View(android.view.View)

Example 39 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.

the class UserProfileOrg method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    mAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_org_profile);
    mUserReference = FirebaseDatabase.getInstance().getReference().child("users").child(user.getUid());
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 40 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project Firebase-Helper by AtifAbbAsi19.

the class FireBaseHelper method deleteUserAuthAccount.

public void deleteUserAuthAccount(FireBaseOnTaskComplete onTaskComplete) {
    if (onTaskComplete != null) {
        this.onTaskCompleteInterface = onTaskComplete;
        final FirebaseUser currentUser = mAuth.getInstance().getCurrentUser();
        currentUser.delete().addOnCompleteListener(new OnCompleteListener<Void>() {

            @Override
            public void onComplete(@NonNull Task<Void> task) {
                onTaskCompleteInterface.onComplete(task);
                if (task.isSuccessful()) {
                // Log.d(LOG_TAG, "OK! Works fine!");
                // startActivity(new Intent(Main3WelcomeActivity.this, Main3Activity.class));
                // finish();
                } else {
                // Log.w(LOG_TAG, "Something is wrong!");
                }
            }
        });
    }
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Aggregations

FirebaseUser (com.google.firebase.auth.FirebaseUser)115 AuthResult (com.google.firebase.auth.AuthResult)29 Intent (android.content.Intent)23 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)16 AuthCredential (com.google.firebase.auth.AuthCredential)14 DatabaseReference (com.google.firebase.database.DatabaseReference)13 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)12 DataSnapshot (com.google.firebase.database.DataSnapshot)12 DatabaseError (com.google.firebase.database.DatabaseError)12 ValueEventListener (com.google.firebase.database.ValueEventListener)11 View (android.view.View)10 Button (android.widget.Button)10 Task (com.google.android.gms.tasks.Task)10 NonNull (android.support.annotation.NonNull)8 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)7 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)7 TextView (android.widget.TextView)6 Test (org.junit.Test)6 Context (android.content.Context)5 SharedPreferences (android.content.SharedPreferences)5