This commit is contained in:
@ -303,96 +303,99 @@ public class MessageDetailFragment extends NormalFragment implements OnCommentCa
|
||||
return;
|
||||
}
|
||||
|
||||
mSendingDialog = DialogUtils.showWaitDialog(getActivity(), getString(R.string.post_dialog_hint));
|
||||
CheckLoginUtils.checkLogin(requireContext(), () -> {
|
||||
mSendingDialog = DialogUtils.showWaitDialog(getActivity(), getString(R.string.post_dialog_hint));
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("content", content);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (newsId == null && mConcernEntity == null ||
|
||||
newsId == null && mConcernEntity.getId() == null) {
|
||||
Utils.toast(getContext(), "评论异常 id null");
|
||||
mSendingDialog.cancel();
|
||||
return;
|
||||
} else if (newsId == null) {
|
||||
newsId = mConcernEntity.getId();
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("content", content);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (newsId == null && mConcernEntity == null ||
|
||||
newsId == null && mConcernEntity.getId() == null) {
|
||||
Utils.toast(getContext(), "评论异常 id null");
|
||||
mSendingDialog.cancel();
|
||||
return;
|
||||
} else if (newsId == null) {
|
||||
newsId = mConcernEntity.getId();
|
||||
}
|
||||
|
||||
PostCommentUtils.addCommentData(getContext(), newsId, jsonObject.toString(), mCommentEntity,
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
mSendingDialog.dismiss();
|
||||
toast("发表成功");
|
||||
mMessageDetailEt.setText("");
|
||||
PostCommentUtils.addCommentData(getContext(), newsId, jsonObject.toString(), mCommentEntity,
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
mSendingDialog.dismiss();
|
||||
toast("发表成功");
|
||||
mMessageDetailEt.setText("");
|
||||
|
||||
try {
|
||||
JSONObject cacheObject = new JSONObject();
|
||||
JSONObject cacheUser = new JSONObject();
|
||||
JSONObject userData = new JSONObject();
|
||||
cacheUser.put("_id", mUserInfo.getId());
|
||||
cacheUser.put("icon", mUserInfo.getIcon());
|
||||
cacheUser.put("name", mUserInfo.getName());
|
||||
userData.put("is_comment_own", true);
|
||||
cacheObject.put("_id", response.getString("_id"));
|
||||
cacheObject.put("content", content);
|
||||
cacheObject.put("time", System.currentTimeMillis() / 1000);
|
||||
cacheObject.put("vote", 0);
|
||||
cacheObject.put("user", cacheUser);
|
||||
cacheObject.put("me", userData);
|
||||
|
||||
if (mCommentEntity != null) {
|
||||
JSONObject cacheParent = new JSONObject();
|
||||
JSONObject cacheParentUser = new JSONObject();
|
||||
cacheParentUser.put("_id", mCommentEntity.getId());
|
||||
cacheParentUser.put("name", mCommentEntity.getUser().getName());
|
||||
cacheParent.put("user", cacheParentUser);
|
||||
cacheParent.put("comment", mCommentEntity.getContent());
|
||||
cacheObject.put("parent", cacheParent);
|
||||
}
|
||||
|
||||
CommentEntity commentEntity = new Gson().fromJson(cacheObject.toString(), CommentEntity.class);
|
||||
if (mConcernEntity != null) {
|
||||
adapter.addNormalComment(commentEntity);
|
||||
}
|
||||
|
||||
modifyNewsCommentOkhttpCache(adapter.findTheLastPriorComment(), cacheObject, newsId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (mConcernEntity != null) {
|
||||
// 完成评论操作,添加评论数
|
||||
adapter.addCommentCount();
|
||||
//修改评论缓存
|
||||
CommentManager.updateOkhttpCacheForId(getContext(), newsId);
|
||||
CommentManager.updateOkhttpCache(getContext(), newsId);
|
||||
adapter.notifyItemInserted(adapter.getHotCommentListSize() + 2);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1); //刷新脚布局高度
|
||||
} else {
|
||||
showNoConnection(false);
|
||||
}
|
||||
|
||||
setSoftInput(false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFailed(Throwable e) {
|
||||
mSendingDialog.dismiss();
|
||||
String errorString = null;
|
||||
if (e instanceof HttpException) {
|
||||
try {
|
||||
errorString = ((HttpException) e).response().errorBody().string();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
JSONObject cacheObject = new JSONObject();
|
||||
JSONObject cacheUser = new JSONObject();
|
||||
JSONObject userData = new JSONObject();
|
||||
cacheUser.put("_id", mUserInfo.getId());
|
||||
cacheUser.put("icon", mUserInfo.getIcon());
|
||||
cacheUser.put("name", mUserInfo.getName());
|
||||
userData.put("is_comment_own", true);
|
||||
cacheObject.put("_id", response.getString("_id"));
|
||||
cacheObject.put("content", content);
|
||||
cacheObject.put("time", System.currentTimeMillis() / 1000);
|
||||
cacheObject.put("vote", 0);
|
||||
cacheObject.put("user", cacheUser);
|
||||
cacheObject.put("me", userData);
|
||||
|
||||
if (mCommentEntity != null) {
|
||||
JSONObject cacheParent = new JSONObject();
|
||||
JSONObject cacheParentUser = new JSONObject();
|
||||
cacheParentUser.put("_id", mCommentEntity.getId());
|
||||
cacheParentUser.put("name", mCommentEntity.getUser().getName());
|
||||
cacheParent.put("user", cacheParentUser);
|
||||
cacheParent.put("comment", mCommentEntity.getContent());
|
||||
cacheObject.put("parent", cacheParent);
|
||||
}
|
||||
|
||||
CommentEntity commentEntity = new Gson().fromJson(cacheObject.toString(), CommentEntity.class);
|
||||
if (mConcernEntity != null) {
|
||||
adapter.addNormalComment(commentEntity);
|
||||
}
|
||||
|
||||
modifyNewsCommentOkhttpCache(adapter.findTheLastPriorComment(), cacheObject, newsId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (mConcernEntity != null) {
|
||||
// 完成评论操作,添加评论数
|
||||
adapter.addCommentCount();
|
||||
//修改评论缓存
|
||||
CommentManager.updateOkhttpCacheForId(getContext(), newsId);
|
||||
CommentManager.updateOkhttpCache(getContext(), newsId);
|
||||
adapter.notifyItemInserted(adapter.getHotCommentListSize() + 2);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1); //刷新脚布局高度
|
||||
} else {
|
||||
showNoConnection(false);
|
||||
}
|
||||
|
||||
setSoftInput(false);
|
||||
|
||||
}
|
||||
LoginUtils.userPostErrorToast(errorString, getContext(), false);
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void postFailed(Throwable e) {
|
||||
mSendingDialog.dismiss();
|
||||
String errorString = null;
|
||||
if (e instanceof HttpException) {
|
||||
try {
|
||||
errorString = ((HttpException) e).response().errorBody().string();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
LoginUtils.userPostErrorToast(errorString, getContext(), false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void modifyNewsCommentOkhttpCache(int offset, JSONObject commentData, String id) {
|
||||
|
||||
Reference in New Issue
Block a user