Skip to content

Instantly share code, notes, and snippets.

@skyler
Created June 10, 2010 20:02
Show Gist options
  • Save skyler/433557 to your computer and use it in GitHub Desktop.
Save skyler/433557 to your computer and use it in GitHub Desktop.
private void login(String username, String password)
{
LoginCredentials creds = new LoginCredentials(username, password);
AsyncAPI.getInstance().login(this, creds, new ITaskCallback<Boolean>() {
@Override
public void onResult(AbstractRunnable<Boolean> task)
{
handler.sendEmptyMessage(DISMISS_LOGIN_DIALOG);
boolean accountOK = false;
if (task.getResult()) { // boolean "logged-in"
LoggedInUser loggedInUser = GroovesharkAPI.getInstance().getLoggedInUser();
if (loggedInUser.isPremium) {
accountOK = true;
} else {
TrialController trial = TrialController.getInstance();
if (trial.isInTrial()) {
ExpirationInfo info = trial.getExpirationInfo();
if (!info.hasExpired && info.numPlaysRemaining > 0) {
accountOK = true;
} else {
handler.sendEmptyMessage(SHOW_TRIAL_EXPIRED_DIALOG);
}
} else {
Log.d(TAG, "user NOT VIP, prompting upgrade/trial");
handler.sendEmptyMessage(SHOW_START_TRIAL_DIALOG);
}
}
} else {
handler.sendEmptyMessage(DISMISS_LOGIN_DIALOG);
handler.sendEmptyMessage(SHOW_LOGIN_FAILED_DIALOG);
}
if (accountOK) {
FavoritesController.getInstance().loadFavorites(Login.this, loggedInUser.userID);
PlaylistsController.getInstance().clearPlaylists(Login.this);
Intent intent = new Intent(Login.this, Home.class);
startActivity(intent);
finish();
}
}
@Override
public void onError()
{
//
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment