add okhttp request retry logic

This commit is contained in:
CsHeng
2017-07-21 19:58:03 +08:00
parent f6c82dd767
commit caeecce50b
16 changed files with 175 additions and 116 deletions

View File

@ -442,8 +442,8 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
// 完成评论操作,添加评论数
adapter.addCommentCount();
//修改评论缓存
CommentManager.updateOkhttpCacheForId(newsId);
CommentManager.updateOkhttpCache(newsId);
CommentManager.updateOkhttpCacheForId(MessageDetailActivity.this, newsId);
CommentManager.updateOkhttpCache(MessageDetailActivity.this, newsId);
adapter.notifyItemInserted(adapter.getHotCommentListSize() + 2);
adapter.notifyItemChanged(adapter.getItemCount() - 1); //刷新脚布局高度
} else {
@ -497,7 +497,7 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
private void modifyNewsCommentOkhttpCache(int offset, JSONObject commentData, String id) {
String key = TimestampUtils.addTimestamp(Config.COMMENT_HOST + "article/" + id + "/comment?limit=10&offset=" + offset);
byte[] data = OkHttpCache.getCache(key);
byte[] data = OkHttpCache.getCache(this, key);
if (data != null) {
try {
JSONArray jsonArray = new JSONArray(new String(data));
@ -506,7 +506,7 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
for (int i = 0, size = jsonArray.length() > 9 ? 9 : jsonArray.length(); i < size; i++) {
newComment.put(jsonArray.get(i));
}
OkHttpCache.updateCache(key, newComment.toString().getBytes());
OkHttpCache.updateCache(this, key, newComment.toString().getBytes());
if (jsonArray.length() == 10) {
modifyNewsCommentOkhttpCache(offset + 10, jsonArray.getJSONObject(9), id);
}