Skip to content

Commit

Permalink
Add SimpleRequestListener<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
yongjhih committed May 1, 2016
1 parent 4f1e1f9 commit c9f5864
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
import com.sina.weibo.sdk.net.RequestListener;
import com.sina.weibo.sdk.net.WeiboParameters;
import com.sina.weibo.sdk.utils.LogUtil;
import com.sina.weibo.sdk.openapi.models.*;
import com.sina.weibo.sdk.net.ListRequestListener;
import java.util.List;
import java.util.Collection;
import java.util.Collections;

/**
* 微博 OpenAPI 的基类,每个接口类都继承了此抽象类。
Expand Down Expand Up @@ -58,6 +63,26 @@ public AbsOpenAPI(Context context, String appKey, Oauth2AccessToken accessToken)
mAccessToken = accessToken;
}

public abstract class SimpleRequestListener<T> implements RequestListener, ListRequestListener<T> {
@Override public void onComplete(String json) {
onComplete(parse(json, (T) null));
}

private List<Status> parse(String json, Status defValue) {
StatusList statusList = StatusList.parse(json);
return statusList.statusList;
}

private List<Comment> parse(String json, Comment defValue) {
CommentList list = CommentList.parse(json);
return list.commentList;
}

private List<T> parse(String json, T defValue) {
return null;
}
}

/**
* HTTP 异步请求。
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.sina.weibo.sdk.openapi.models;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -33,7 +34,7 @@
public class CommentList {

/** 微博列表 */
public ArrayList<Comment> commentList;
public List<Comment> commentList;
public String previous_cursor;
public String next_cursor;
public int total_number;
Expand Down

0 comments on commit c9f5864

Please sign in to comment.