Last active
April 11, 2018 14:34
-
-
Save T31337/8ed5f512bfb842113133ef971b952b1f to your computer and use it in GitHub Desktop.
Basic FireBase Skeleton Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Firebase.Skeleton; | |
import android.app.Activity; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.support.annotation.NonNull; | |
import android.util.Log; | |
import android.widget.Toast; | |
import com.google.android.gms.tasks.OnCompleteListener; | |
import com.google.android.gms.tasks.Task; | |
import com.google.firebase.auth.AuthResult; | |
import com.google.firebase.auth.FirebaseAuth; | |
import com.google.firebase.auth.FirebaseUser; | |
//FireData Is For All FireBase Management, Auth+Data | |
public class FireData extends Activity | |
{ | |
private static final String TAG = "TBug"; | |
private FirebaseAuth FireAuth; | |
private String UserName,UserEmail,ImgSRC,UserPass; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
FireAuth = FirebaseAuth.getInstance(); | |
} | |
@Override | |
public void onStart() | |
{ | |
super.onStart(); | |
//Current User Info | |
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); | |
if (user != null) | |
{ | |
// Name, email address, and profile photo Url | |
String UserName = user.getDisplayName(); | |
String UserEmail = user.getEmail(); | |
Uri imgSRC = user.getPhotoUrl(); | |
// Check if user's email is verified | |
boolean Verified = user.isEmailVerified(); | |
// The user's ID, unique to the Firebase project. Do NOT use this value to | |
// authenticate with your backend server, if you have one. Use | |
// FirebaseUser.getToken() instead. | |
String UID = user.getUid(); | |
// Check if user is signed in (non-null) and update UI accordingly. | |
FirebaseUser currentUser = FireAuth.getCurrentUser(); | |
updateUI(currentUser); | |
} | |
} | |
private void Regestration() | |
{ | |
FireAuth.createUserWithEmailAndPassword(UserName,UserPass) | |
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() | |
{ | |
@Override | |
public void onComplete(@NonNull Task<AuthResult> task) | |
{ | |
if (task.isSuccessful()) | |
{ | |
// Sign in success, update UI with the signed-in user's information | |
Log.d(TAG, "createUserWithEmail:success"); | |
FirebaseUser user = FireAuth.getCurrentUser(); | |
updateUI(user); | |
} | |
else | |
{ | |
// If sign in fails, display a message to the user. | |
Log.w(TAG, "createUserWithEmail:failure", task.getException()); | |
Toast.makeText(getBaseContext().getApplicationContext(), "Authentication failed.", | |
Toast.LENGTH_SHORT).show(); | |
updateUI(null); | |
} | |
// ... | |
} | |
}); | |
} | |
//Handle Google Login Here | |
private void Authentication() | |
{ | |
} | |
//Update UserInfo Here | |
private void updateUI(FirebaseUser currentUser) | |
{ | |
//ToDo: RTL DB SYNCING | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment