diff options
author | Appu Goundan <appu@google.com> | 2014-07-10 15:49:23 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-07-10 00:50:10 +0000 |
commit | 9464499aba4769eaf8df4b2ea8cd3d714196388d (patch) | |
tree | 2901729292f644b052429797b13e1370de44e053 | |
parent | 56f02866e1f3c97a17a9bba3062c13c2b5eed947 (diff) | |
parent | aef9f3c9cd78d8e66c63c8e90d14155939ee82ff (diff) | |
download | cloud-9464499aba4769eaf8df4b2ea8cd3d714196388d.tar.gz |
Merge "Add a callback function to the GoogleLogin#logIn and GoogleLogin#promptToLogin functions." into idea133
-rw-r--r-- | login/src/com/google/gct/login/CredentialedUser.java | 6 | ||||
-rw-r--r-- | login/src/com/google/gct/login/GoogleLogin.java | 28 | ||||
-rw-r--r-- | login/src/com/google/gct/login/IGoogleLoginCompletedCallback.java (renamed from login/src/com/google/gct/login/IGoogleLoginUpdateUser.java) | 10 |
3 files changed, 29 insertions, 15 deletions
diff --git a/login/src/com/google/gct/login/CredentialedUser.java b/login/src/com/google/gct/login/CredentialedUser.java index 957f03b..8a42a6f 100644 --- a/login/src/com/google/gct/login/CredentialedUser.java +++ b/login/src/com/google/gct/login/CredentialedUser.java @@ -44,7 +44,7 @@ public class CredentialedUser { googleLoginState = null; } - public CredentialedUser(GoogleLoginState state, final IGoogleLoginUpdateUser updateUserCallback) { + public CredentialedUser(GoogleLoginState state, final IGoogleLoginCompletedCallback updateUserCallback) { this.email = state.getEmail(); googleLoginState = state; credential = googleLoginState.makeCredential(); @@ -95,7 +95,7 @@ public class CredentialedUser { this.isActive = isActive; } - private void initializeUserInfo(Userinfoplus userInfo, final IGoogleLoginUpdateUser updateUserCallback) { + private void initializeUserInfo(Userinfoplus userInfo, final IGoogleLoginCompletedCallback updateUserCallback) { if(userInfo == null) { name = null; image = null; @@ -105,7 +105,7 @@ public class CredentialedUser { @Override public void setProperty(Image newImage) { image = newImage; - updateUserCallback.updateUser(); + updateUserCallback.onLoginCompleted(); } }; GoogleLoginUtils.getUserPicture(userInfo, pictureCallback); diff --git a/login/src/com/google/gct/login/GoogleLogin.java b/login/src/com/google/gct/login/GoogleLogin.java index 8db1356..f2e1aae 100644 --- a/login/src/com/google/gct/login/GoogleLogin.java +++ b/login/src/com/google/gct/login/GoogleLogin.java @@ -90,7 +90,7 @@ public class GoogleLogin { * @throws InvalidThreadTypeException */ public static void promptToLogIn() throws InvalidThreadTypeException { - promptToLogIn(null); + promptToLogIn(null, null); } /** @@ -98,12 +98,15 @@ public class GoogleLogin { * if there is current no active user. Does nothing if there is an active * user. This function must be called from the event dispatch thread (EDT). * @param message If not null, this message would be the title of the dialog. + * @param callback if not null, then this callback is called when the login + * either succeeds or fails. * @throws InvalidThreadTypeException */ - public static void promptToLogIn(final String message) throws InvalidThreadTypeException { + public static void promptToLogIn(final String message, @Nullable final IGoogleLoginCompletedCallback callback) + throws InvalidThreadTypeException { if (!instance.isLoggedIn()) { if(ApplicationManager.getApplication().isDispatchThread()) { - getInstance().logIn(message); + getInstance().logIn(message, callback); } else { throw new InvalidThreadTypeException("promptToLogin"); } @@ -276,7 +279,7 @@ public class GoogleLogin { */ public void logIn() { users.removeActiveUser(); - logIn(null); + logIn(null, null); } /** @@ -291,8 +294,10 @@ public class GoogleLogin { * as accessing Google API services. It should say something like * "Importing a project from Google Project Hosting requires signing * in." + * @param callback if not null, then this callback is called when the login + * either succeeds or fails. */ - public void logIn(final String message) { + public void logIn(final String message, @Nullable final IGoogleLoginCompletedCallback callback) { final GoogleLoginState state = createGoogleLoginState(); ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @@ -303,13 +308,16 @@ public class GoogleLogin { // TODO: add user preference to chose to use pop-up copy and paste dialog if(loggedIn) { - IGoogleLoginUpdateUser callback = new IGoogleLoginUpdateUser() { + IGoogleLoginCompletedCallback localCallback = new IGoogleLoginCompletedCallback() { @Override - public void updateUser() { + public void onLoginCompleted() { uiFacade.notifyStatusIndicator(); + if(callback != null) { + callback.onLoginCompleted(); + } } }; - users.addUser(new CredentialedUser(state, callback)); + users.addUser(new CredentialedUser(state, localCallback)); } } }); @@ -610,9 +618,9 @@ public class GoogleLogin { // CredentialedUser's credentials will be updated from the persistent storage in GoogleLoginState constructor GoogleLoginState delegate = createGoogleLoginState(); - IGoogleLoginUpdateUser callback = new IGoogleLoginUpdateUser() { + IGoogleLoginCompletedCallback callback = new IGoogleLoginCompletedCallback() { @Override - public void updateUser() { + public void onLoginCompleted() { uiFacade.notifyStatusIndicator(); } }; diff --git a/login/src/com/google/gct/login/IGoogleLoginUpdateUser.java b/login/src/com/google/gct/login/IGoogleLoginCompletedCallback.java index 771081b..5661916 100644 --- a/login/src/com/google/gct/login/IGoogleLoginUpdateUser.java +++ b/login/src/com/google/gct/login/IGoogleLoginCompletedCallback.java @@ -15,6 +15,12 @@ */ package com.google.gct.login; -public interface IGoogleLoginUpdateUser { - public void updateUser(); +/** + * Callback for when a login is completed. + */ +public interface IGoogleLoginCompletedCallback { + /** + * Called when log in is complete. + */ + public void onLoginCompleted(); } |