I have an Android app that will require the user to log in using either facebook or twitter. I managed to realize both of them and was partly successful. Facebook login was implemented using this facebook tutorial.
As for logging in to Twitter, I just used a button that launches TwitterLoginActivity, which logs into the webview, and if it successfully launches the TwitterHomeActivity function, which is implemented exactly like facebook logic in terms of fragmentation.
So, here is a breakdown of the entire Impedmentation registry
FacebookHomeActivity has 3 fragments
- FacebookSplashFragment (the ability to log in using fb or twitter)
- FacebookSelectionFragment (shows the application menu)
- FacebookUserSettingsFragmen (logout user).
TwitterHomeActivity has 2 snippets
- TwitterSelectionFragment (shows the application menu)
- TwitterUserSettingsFragment (logout)
TwitterLoginActivity (contains a web view for authentication through my server, which will redirect to a Twitter page to log in)
The problem, if you havenβt seen it yet, is that if I log out of my Twitter account, I need to run the FacebookHomeActivity function to view my facebook or twitter login options.
Doing this is very hacky and just plain bad. So I thought that if I made all the fragments, this could solve my problem.
LoginActivity (login host) contains:
- LoginSelectionFragment (select to enter facebook or twitter)
- TwitterLoginFragment (User Login via Web View)
- FacebookSelectionFragment (user and show menu authorization)
- TwitterSelectionFragment (show menu)
- FacebookUserSettingFragment (logout fb user)
- TwitterUserSettingFragment (logout twitter user)
Using this so that it displays the correct fragments in different input states:
@Override protected void onResumeFragments() { super.onResumeFragments(); Session session = Session.getActiveSession(); if (session != null && session.isOpened()) { // if the session is already open, // try to show the selection fragment getSupportActionBar().show(); showFragment(FACEBOOKSELECTION, false); } else if (Globals.loggedIn() && Globals.isTwitterUser()) { // otherwise present the splash screen // and ask the person to login. getSupportActionBar().show(); showFragment(TWITTERSELECTION, false); } else { // otherwise present the splash screen // and ask the person to login. Globals.logout(); getSupportActionBar().hide(); showFragment(LOGINSELECTION, false); } }
Creating login logic exists since fragments seem to make sense to me, but that doesn't behave the way I thought it worked. Instead, it basically runs everything that onStart () has in each fragment, so imagine a lot of progress that comes up and nothing happens. The column was also messed up, causing a fragment that was never shown for display. Either I'm implementing this incorrectly, or this is a completely wrong way to approach this problem.
My question is: what would be the best way to implement both Facebook and Twitter login if this is not the best way to solve the problem.
If the above makes sense and has nothing wrong with that, what do you think I'm doing wrong?