消息详情代码整理
This commit is contained in:
@ -7,8 +7,11 @@ import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/9.
|
||||
*
|
||||
@ -20,17 +23,16 @@ public class PostCommentUtils {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Request.Method.POST, url, content,
|
||||
new Response.Listener<String>() {
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
public void onResponse(JSONObject response) {
|
||||
if (listener != null){
|
||||
listener.postSucced(response);
|
||||
}
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (error.networkResponse != null && error.networkResponse.statusCode == 401) {
|
||||
@ -50,30 +52,19 @@ public class PostCommentUtils {
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static void addCommentVoto(final String newsId, final Context context, final PostCommentListener listener) {
|
||||
public static void addCommentVoto(final String newsId, final Context context) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
Request.Method.POST, Config.COMMENT_HOST + "comment/" + newsId + "/vote" ,
|
||||
new Response.Listener<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
if (listener != null){
|
||||
listener.postSucced(response);
|
||||
}
|
||||
}
|
||||
},
|
||||
null,
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (error.networkResponse != null && error.networkResponse.statusCode == 401) {
|
||||
TokenUtils.getToken(context, false);
|
||||
addCommentVoto(newsId, context, listener);
|
||||
return;
|
||||
}
|
||||
if (listener != null){
|
||||
listener.postFailed(error);
|
||||
addCommentVoto(newsId, context);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -85,7 +76,7 @@ public class PostCommentUtils {
|
||||
}
|
||||
|
||||
public interface PostCommentListener {
|
||||
void postSucced(String str);
|
||||
void postSucced(JSONObject response);
|
||||
void postFailed(VolleyError error);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user