I'm working on a small Android player I have found on github.
I managed to compile the code, but I'm using the 0.10.16 SDK. it seems the player on github was written for a previous version.
I can log in but when I click on Playlists on the home screen and the code bellow executes, I get a blank screen:
private void getUserPlaylists() {
DeezerRequest request = DeezerRequestFactory.requestCurrentUserPlaylists();
AsyncDeezerTask task = new AsyncDeezerTask(mDeezerConnect,
new JsonRequestListener() {
@SuppressWarnings("unchecked")
@Override
public void onResult(final Object result, final Object requestId) {
mPlaylistList.clear();
try {
mPlaylistList.addAll((List<Playlist>) result);
}
catch (ClassCastException e) {
handleError(e);
}
if (mPlaylistList.isEmpty()) {
Toast.makeText(UserPlaylistsActivity.this, getResources()
.getString(R.string.no_results), Toast.LENGTH_LONG).show();
}
mPlaylistAdapter.notifyDataSetChanged();
}
@Override
public void onComplete(final String response, Object requestId) {
//TODO
Toast.makeText(UserPlaylistsActivity.this, "Playlist_onComplete",
Toast.LENGTH_LONG).show();
}
@Override
public void onUnparsedResult(final String response, Object requestId) {
//TODO
}
@Override
public void onException(Exception exception, Object requestId) {
if(exception instanceof OAuthException){
handleError(exception);
}
else if(exception instanceof MalformedURLException){
handleError(exception);
}
else if(exception instanceof IOException){
handleError(exception);
}
else if(exception instanceof DeezerError){
handleError(exception);
}
else if(exception instanceof JSONException){
handleError(exception);
}
else{
//do nothing
}
}
});
task.execute(request);
}
I think the reason is, that the code above was written for the previous SDK version, which apparently worked with "onResult". The latest SDK however works with "onComplete", which returns an unparsed JSON string.
My questions are:
I was looking through the documentation, but did not find anything useful.
Did anyone implement this with the latest SDK?
EDIT:
private void getUserPlaylists() {
DeezerRequest request = DeezerRequestFactory.requestCurrentUserPlaylists();
AsyncDeezerTask task = new AsyncDeezerTask(mDeezerConnect,
new JsonRequestListener() {
@SuppressWarnings("unchecked")
@Override
public void onResult(final Object result, final Object requestId) {
mPlaylistList.clear();
try {
mPlaylistList.addAll((List<Playlist>) result);
}
catch (ClassCastException e) {
handleError(e);
}
if (mPlaylistList.isEmpty()) {
Toast.makeText(UserPlaylistsActivity.this, getResources()
.getString(R.string.no_results), Toast.LENGTH_LONG).show();
}
mPlaylistAdapter.notifyDataSetChanged();
}
@Override
public void onUnparsedResult(final String response, Object requestId) {
//TODO
}
@Override
public void onException(Exception exception, Object requestId) {
if(exception instanceof OAuthException){
handleError(exception);
}
else if(exception instanceof MalformedURLException){
handleError(exception);
}
else if(exception instanceof IOException){
handleError(exception);
}
else if(exception instanceof DeezerError){
handleError(exception);
}
else if(exception instanceof JSONException){
handleError(exception);
}
else{
//do nothing
}
}
});
task.execute(request);
}
This works now with 0.10.16 SDK. Removed onComplete() and all data is now beeing parsed correctly. Menus are OK, playback is successful.
The issue is that you're overriding the onComplete(String, Object)
method. This method is already present in the JsonRequestListener
implementation, so you should not rewrite it yourself, at least not without calling super.onComplete(response, requestId)
.
When overriding the JsonResultListener
class, you should only implement the onResult(Object, Object)
as you did, the onUnparsedResult(String, Object)
method in case the json can't be parsed automatically, and the onException(Exception, Object)
in case an exception occurs.