Skip to content

Instantly share code, notes, and snippets.

@HammadNasir
Last active June 6, 2016 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HammadNasir/6abfc58534c358eda21153907d8bfd3e to your computer and use it in GitHub Desktop.
Save HammadNasir/6abfc58534c358eda21153907d8bfd3e to your computer and use it in GitHub Desktop.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mAuth = FirebaseAuth.getInstance();
databaseReference = FirebaseDatabase.getInstance().getReference();
hRequestAdapter = new HRequestAdapter(hRequestsList);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(helpRequestAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
checkAuthState();
}
here's checkAuthState():
public void checkAuthState() {
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d("signedIn", "onAuthStateChanged:signed_in:" + user.getUid());
retrieveUserInfo();
retrieveHRequests();
} else {
// User is signed out
Log.d("signedOut", "onAuthStateChanged:signed_out");
Intent signUpActivityIntent = new Intent(MainActivity.this, SignupActivity.class);
signUpActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
signUpActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(signUpActivityIntent);
}
// ...
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment