@@ -20,26 +20,31 @@ public abstract class FirebaseLoginBaseActivity extends AppCompatActivity {
2020
2121 private final String LOG_TAG = "FirebaseLoginBaseAct" ;
2222
23- private Firebase mRef ;
24-
2523 private GoogleAuthHelper mGoogleAuthHelper ;
2624
2725 public SocialProvider mChosenProvider ;
2826
2927 /* Abstract methods for Login Events */
30- public abstract void onFirebaseLogin (AuthData authData );
28+ protected abstract void onFirebaseLogin (AuthData authData );
3129
32- public abstract void onFirebaseLogout ();
30+ protected abstract void onFirebaseLogout ();
3331
34- public abstract void onFirebaseLoginError (FirebaseError firebaseError );
32+ protected abstract void onFirebaseLoginError (FirebaseError firebaseError );
3533
36- public abstract void onFirebaseLoginCancel ();
34+ protected abstract void onFirebaseLoginCancel ();
3735
38- public abstract Firebase setupFirebase ();
36+ /**
37+ * Subclasses of this activity must implement this method and return a valid Firebase reference that
38+ * can be used to call authentication related methods on.
39+ *
40+ * @return a Firebase reference that can be used to call authentication related methods on
41+ */
42+ protected abstract Firebase getFirebaseRef ();
3943
4044 /* Login/Logout */
4145
4246 public void loginWithProvider (SocialProvider provider ) {
47+ // TODO: what should happen if you're already authenticated?
4348 switch (provider ) {
4449 case google :
4550 mGoogleAuthHelper .login ();
@@ -61,16 +66,13 @@ public void logout() {
6166 case twitter :
6267 throw new UnsupportedOperationException ();
6368 }
64- mRef .unauth ();
69+ getFirebaseRef () .unauth ();
6570 }
6671
6772
6873 @ Override
6974 protected void onCreate (Bundle savedInstanceState ) {
7075 super .onCreate (savedInstanceState );
71- Firebase .setAndroidContext (this );
72-
73- mRef = setupFirebase ();
7476
7577 mGoogleAuthHelper = new GoogleAuthHelper (this , new TokenAuthHandler () {
7678 @ Override
@@ -93,7 +95,7 @@ public void onError(Exception ex) {
9395 @ Override
9496 protected void onStart () {
9597 super .onStart ();
96- mRef .addAuthStateListener (new Firebase .AuthStateListener () {
98+ getFirebaseRef () .addAuthStateListener (new Firebase .AuthStateListener () {
9799 @ Override
98100 public void onAuthStateChanged (AuthData authData ) {
99101 if (authData != null ) {
@@ -107,7 +109,7 @@ public void onAuthStateChanged(AuthData authData) {
107109 }
108110
109111 private void authenticateRefWithProvider (String provider , String token ) {
110- mRef .authWithOAuthToken (provider , token , new Firebase .AuthResultHandler () {
112+ getFirebaseRef () .authWithOAuthToken (provider , token , new Firebase .AuthResultHandler () {
111113 @ Override
112114 public void onAuthenticated (AuthData authData ) {
113115 // Do nothing. Auth updates are handled in the AuthStateListener
0 commit comments