评论举报功能-完成

This commit is contained in:
khy
2016-12-06 17:06:00 +08:00
parent d02a136e2f
commit 4f0f1672c7
5 changed files with 150 additions and 1 deletions

View File

@ -7,11 +7,17 @@ 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.retrofit.RetrofitManager;
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
import org.json.JSONObject;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.adapter.rxjava.HttpException;
/**
* Created by khy on 2016/11/9.
*
@ -89,6 +95,36 @@ public class PostCommentUtils {
}).start();
}
public static void addReportData(Context context, String reportData, PostCommentListener listener) {
addReportData(context, reportData, listener, true);
}
private static void addReportData(final Context context, final String reportData,
final PostCommentListener listener, boolean isCheck) {
RequestBody body = RequestBody.create(MediaType.parse("application/json"), reportData);
RetrofitManager.getComment().postReportData(body,TokenUtils.getToken(context, isCheck),
new com.gh.gamecenter.retrofit.Response<ResponseBody>(){
@Override
public void onNext(ResponseBody response) {
super.onNext(response);
listener.postSucced(null);
}
@Override
public void onError(Throwable e) {
super.onError(e);
if (e instanceof HttpException) {
if (((HttpException) e).code() == 401) {
addReportData(context, reportData, listener, false);
return;
}
}
Utils.log("addReportData=onError::" + e.toString());
listener.postFailed(null);
}
});
}
public interface PostCommentListener {
void postSucced(JSONObject response);
void postFailed(VolleyError error);