消息评论功能 基本完成
This commit is contained in:
87
app/src/main/java/com/gh/common/util/PostCommentUtils.java
Normal file
87
app/src/main/java/com/gh/common/util/PostCommentUtils.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.volley.Request;
|
||||
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.StringExtendedRequest;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/9.
|
||||
*/
|
||||
public class PostCommentUtils {
|
||||
public static void addCommentData(final String url, final String content, final Context context, final PostCommentListener listener) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Utils.log("url::" + url, "/ content::" + content);
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
Request.Method.POST, url, content,
|
||||
new Response.Listener<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
if (listener != null){
|
||||
listener.postSucced(response.toString());
|
||||
}
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (listener != null){
|
||||
listener.postFailed(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
request.addHeader("TOKEN",TokenUtils.getToken(context));
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
public static void addCommentVoto(final String newsId, final Context context, final PostCommentListener listener) {
|
||||
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) {
|
||||
Log.e("======onResponse", "onResponse");
|
||||
if (listener != null){
|
||||
listener.postSucced(response.toString());
|
||||
}
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Log.e("======onErrorResponse", new String(error.networkResponse.data));
|
||||
if (listener != null){
|
||||
listener.postFailed(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
request.addHeader("TOKEN",TokenUtils.getToken(context));
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
public interface PostCommentListener {
|
||||
void postSucced(String str);
|
||||
void postFailed(VolleyError error);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user