Skip to content

Commit

Permalink
Updating Scrumptious to simplify session handling.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mingflifb committed Dec 12, 2012
1 parent dfee756 commit a14ba51
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,33 @@ public void onDestroy() {
/**
* Notifies that the session token has been updated.
*/
public void tokenUpdated() {
private void tokenUpdated() {
if (pendingAnnounce) {
handleAnnounce();
}
}

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();
}
}
}

Expand Down

0 comments on commit a14ba51

Please sign in to comment.