Search in sources :

Example 66 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project Pepper_v0 by SamDaQueen.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // loading the default fragment
    loadFragment(new CategoryFragment());
    BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    Bundle bundle = getIntent().getBundleExtra("items");
    if (bundle != null)
        arrayList = bundle.getParcelableArrayList("order");
    // Firebase Authentication
    mUsername = ANONYMOUS;
    mFirebaseAuth = FirebaseAuth.getInstance();
    mAuthStateListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // user signed in
                onSignedInInitialize(user.getDisplayName());
            } else {
                // user signed out
                onSignedOutCleanup();
                startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().setIsSmartLockEnabled(false).setAvailableProviders(Arrays.asList(new AuthUI.IdpConfig.GoogleBuilder().build(), new AuthUI.IdpConfig.EmailBuilder().build(), new AuthUI.IdpConfig.PhoneBuilder().build())).setLogo(R.drawable.pepper_500px).build(), RC_SIGN_IN);
            }
        }
    };
}
Also used : BottomNavigationView(android.support.design.widget.BottomNavigationView) Bundle(android.os.Bundle) FirebaseUser(com.google.firebase.auth.FirebaseUser) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 67 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project Pepper_v0 by SamDaQueen.

the class ProfileFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_profile, container, false);
    // Sign out Button
    signoutbtn = rootView.findViewById(R.id.button8);
    signOutFunction();
    // Get User Details
    textView = rootView.findViewById(R.id.textView);
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null)
        if (user.getDisplayName() != null)
            textView.setText(user.getDisplayName());
    // Displaying Credits
    creditsbtn = rootView.findViewById(R.id.button9);
    creditsbtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            startActivity(new Intent(getActivity(), Credits.class));
        }
    });
    // share
    share = rootView.findViewById(R.id.button10);
    share.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onInviteClicked();
        }
    });
    // image
    if (flag == true) {
        imageView = rootView.findViewById(R.id.imageView);
        hint = rootView.findViewById(R.id.hint);
        setImageView();
    }
    return rootView;
}
Also used : Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable)

Example 68 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project OnlineCanteen by josephgunawan97.

the class AccountUtil method createRole.

private static Task<Void> createRole(String role) {
    FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
    FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
    DatabaseReference reference = firebaseDatabase.getReference("role");
    return reference.child(firebaseUser.getUid()).setValue(role);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 69 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project OnlineCanteen by josephgunawan97.

the class AccountUtil method uploadProfilePicture.

private static UploadTask uploadProfilePicture(Uri profilePictureUri) {
    FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
    FirebaseStorage storage = FirebaseStorage.getInstance();
    StorageReference storageReference = storage.getReference();
    StorageReference directoryReference = storageReference.child("profilepics");
    StorageReference profilePictureReference = directoryReference.child(firebaseUser.getUid() + ".jpg");
    if (profilePictureUri != null) {
        return profilePictureReference.putFile(profilePictureUri);
    } else
        return null;
}
Also used : StorageReference(com.google.firebase.storage.StorageReference) FirebaseStorage(com.google.firebase.storage.FirebaseStorage) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 70 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project OnlineCanteen by josephgunawan97.

the class AccountUtil method updateUserInformationOnDatabase.

private static Task<Void> updateUserInformationOnDatabase(User user) {
    FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
    FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
    DatabaseReference reference = firebaseDatabase.getReference("users");
    return reference.child(firebaseUser.getUid()).setValue(user);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Aggregations

FirebaseUser (com.google.firebase.auth.FirebaseUser)100 AuthResult (com.google.firebase.auth.AuthResult)26 Intent (android.content.Intent)22 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)16 DataSnapshot (com.google.firebase.database.DataSnapshot)12 DatabaseError (com.google.firebase.database.DatabaseError)12 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)11 AuthCredential (com.google.firebase.auth.AuthCredential)11 DatabaseReference (com.google.firebase.database.DatabaseReference)11 ValueEventListener (com.google.firebase.database.ValueEventListener)11 View (android.view.View)10 Task (com.google.android.gms.tasks.Task)10 Button (android.widget.Button)9 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