From a14ba512aedb5f1a47d353ad9f27ebc2580bb93a Mon Sep 17 00:00:00 2001 From: Ming Li Date: Tue, 11 Dec 2012 16:03:31 -0800 Subject: [PATCH] Updating Scrumptious to simplify session handling. Summary: Simplify state change handling in Scrumptious to be more decoupled. Test Plan: Ran on emulator and ensured that session state changes behaves as expected. Reviewers: mmarucheck, clang Reviewed By: clang CC: caabernathy Differential Revision: https://phabricator.fb.com/D655382 Task ID: 1954737 --- .../facebook/scrumptious/MainActivity.java | 10 +++--- .../scrumptious/SelectionFragment.java | 32 +++++++++++-------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/samples/Scrumptious/src/com/facebook/scrumptious/MainActivity.java b/samples/Scrumptious/src/com/facebook/scrumptious/MainActivity.java index 504dc3e52a..a9934df922 100644 --- a/samples/Scrumptious/src/com/facebook/scrumptious/MainActivity.java +++ b/samples/Scrumptious/src/com/facebook/scrumptious/MainActivity.java @@ -144,12 +144,10 @@ private void onSessionStateChange(Session session, SessionState state, Exception for (int i = 0; i < backStackSize; i++) { manager.popBackStack(); } - if (state.isOpened()) { - if (state.equals(SessionState.OPENED_TOKEN_UPDATED)) { - ((SelectionFragment) fragments[SELECTION]).tokenUpdated(); - } else { - showFragment(SELECTION, false); - } + // check for the OPENED state instead of session.isOpened() since for the + // OPENED_TOKEN_UPDATED state, the selection fragment should already be showing. + if (state.equals(SessionState.OPENED)) { + showFragment(SELECTION, false); } else if (state.isClosed()) { showFragment(SPLASH, false); } diff --git a/samples/Scrumptious/src/com/facebook/scrumptious/SelectionFragment.java b/samples/Scrumptious/src/com/facebook/scrumptious/SelectionFragment.java index 1766c4f2e9..480f35b84c 100644 --- a/samples/Scrumptious/src/com/facebook/scrumptious/SelectionFragment.java +++ b/samples/Scrumptious/src/com/facebook/scrumptious/SelectionFragment.java @@ -141,7 +141,7 @@ public void onDestroy() { /** * Notifies that the session token has been updated. */ - public void tokenUpdated() { + private void tokenUpdated() { if (pendingAnnounce) { handleAnnounce(); } @@ -149,21 +149,25 @@ public void tokenUpdated() { private void onSessionStateChange(final Session session, SessionState state, Exception exception) { if (session != null && session.isOpened()) { - Request request = Request.newMeRequest(session, new Request.GraphUserCallback() { - @Override - public void onCompleted(GraphUser user, Response response) { - if (session == Session.getActiveSession()) { - if (user != null) { - profilePictureView.setProfileId(user.getId()); - userNameView.setText(user.getName()); + if (state.equals(SessionState.OPENED_TOKEN_UPDATED)) { + tokenUpdated(); + } else { + Request request = Request.newMeRequest(session, new Request.GraphUserCallback() { + @Override + public void onCompleted(GraphUser user, Response response) { + if (session == Session.getActiveSession()) { + if (user != null) { + profilePictureView.setProfileId(user.getId()); + userNameView.setText(user.getName()); + } + } + if (response.getError() != null) { + handleError(response.getError()); } } - if (response.getError() != null) { - handleError(response.getError()); - } - } - }); - request.executeAsync(); + }); + request.executeAsync(); + } } }