use of com.spotify.sdk.android.authentication.AuthenticationResponse in project SpotiQ by ZinoKader.
the class SpotifyAuthenticationActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == ApplicationConstants.LOGIN_INTENT_REQUEST_CODE) {
AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
switch(response.getType()) {
case TOKEN:
Log.d(LogTag.LOG_LOGIN, "Logged in successfully!");
// refresh our authentication token
spotifyCommunicatorService.getAuthenticator().setExpiryTimeStamp(response.getExpiresIn());
spotifyCommunicatorService.getAuthenticator().setAccessToken(response.getAccessToken());
spotifyCommunicatorService.getWebApi().getMe(new Callback<UserPrivate>() {
@Override
public void success(UserPrivate userPrivate, Response response) {
if (userPrivate.product.equals(SpotifyConstants.PRODUCT_PREMIUM)) {
setResult(SpotifyConstants.RESULT_CODE_AUTHENTICATED);
} else {
setResult(SpotifyConstants.RESULT_CODE_NO_PREMIUM);
}
finish();
}
@Override
public void failure(RetrofitError error) {
setResult(SpotifyConstants.RESULT_CODE_CONNECTION_FAILURE);
finish();
}
});
break;
case CODE:
setResult(SpotifyConstants.RESULT_CODE_SPOTIFY_CODE);
finish();
case EMPTY:
setResult(SpotifyConstants.RESULT_CODE_EMPTY);
finish();
case ERROR:
setResult(SpotifyConstants.RESULT_CODE_ERROR);
finish();
case UNKNOWN:
setResult(SpotifyConstants.RESULT_CODE_UNKNOWN);
finish();
default:
setResult(SpotifyConstants.RESULT_CODE_WRONG_REQUEST_CODE);
Log.d(LogTag.LOG_LOGIN, "Something went wrong on login");
finish();
}
} else {
setResult(SpotifyConstants.RESULT_CODE_WRONG_REQUEST_CODE);
Log.d(LogTag.LOG_LOGIN, "Wrong request code for Spotify login");
finish();
}
}
Aggregations