修改点赞逻辑,评论数据同步
This commit is contained in:
@ -12,6 +12,7 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
@ -79,6 +80,7 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
@BindView(R.id.message_detail_sv) ScrollView mMessageDetailSv;
|
||||
@BindView(R.id.message_detail_hint_line) View mMessageDetailLine;
|
||||
@BindView(R.id.reuse_no_connection) LinearLayout mNoConnection;
|
||||
@BindView(R.id.message_detail_close_comment) View mColseCommentV;
|
||||
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
|
||||
@ -90,28 +92,31 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
|
||||
private CommentDao mCommentDao;
|
||||
|
||||
private ConcernEntity mConcernEntity;
|
||||
|
||||
private String newsId;
|
||||
|
||||
private int commentNum = -1; //区分来源 -1:资讯关注列表 !=-1 :新闻详情
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
AppController.put("ConcernEntity", adapter.getConcernEntity());
|
||||
}
|
||||
|
||||
private ConcernEntity mConcernEntity;
|
||||
|
||||
private String newsId;
|
||||
|
||||
private int commentNum;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mConcernEntity = (ConcernEntity) AppController.get("ConcernEntity", true);
|
||||
|
||||
if (mConcernEntity == null) {
|
||||
Intent intent = getIntent();
|
||||
newsId = intent.getExtras().getString("newsId");
|
||||
commentNum = intent.getExtras().getInt("commentNum");
|
||||
Intent intent = getIntent();
|
||||
newsId = intent.getExtras().getString("newsId");
|
||||
commentNum = intent.getExtras().getInt("commentNum");
|
||||
|
||||
//复用问题 mConcernEntity对应的文章有可能和跳转之前的文章不一致
|
||||
if (mConcernEntity != null && newsId != null && !newsId.equals(mConcernEntity.getId())) {
|
||||
mConcernEntity = null;
|
||||
}
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_messagedetail, null);
|
||||
@ -194,7 +199,7 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
});
|
||||
}
|
||||
|
||||
if (newsId != null ) {
|
||||
if (newsId != null && mConcernEntity == null ) {
|
||||
getConcernDigest();
|
||||
}
|
||||
}
|
||||
@ -276,7 +281,17 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
setSoftInput(true);
|
||||
}
|
||||
|
||||
@OnTouch(R.id.message_detail_rv)
|
||||
@OnClick(R.id.actionbar_rl_back)
|
||||
public void OnBackClikListener() {
|
||||
if (commentNum != -1 && commentNum != adapter.getConcernEntity().getCommentnum()) {
|
||||
Intent intent= new Intent();
|
||||
intent.putExtra("commentNum", adapter.getConcernEntity().getCommentnum());
|
||||
setResult(1001, intent);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@OnTouch(R.id.message_detail_close_comment)
|
||||
public boolean OnRecyclerTouchListener() {
|
||||
if (mMessageDetailCommentRl.getVisibility() == View.VISIBLE) {
|
||||
setSoftInput(false);
|
||||
@ -341,6 +356,7 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
// 完成评论操作,添加评论数
|
||||
adapter.addCommentCount();
|
||||
//修改评论缓存
|
||||
CommentManager.updateOkhttpCacheForId(newsId);
|
||||
CommentManager.updateOkhttpCache(newsId);
|
||||
adapter.notifyItemInserted(adapter.getHotCommentListSize() + 2);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1); //刷新脚布局高度
|
||||
@ -365,7 +381,7 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
JSONObject errorJson = new JSONObject(errorData);
|
||||
String detail = errorJson.getString("detail");
|
||||
if ("too frequent".equals(detail)) {
|
||||
Utils.toast(MessageDetailActivity.this, "@_@ 别话痨哦~休息一会再来评论吧~");
|
||||
Utils.toast(MessageDetailActivity.this, "别话痨哦~休息一会再来评论吧~");
|
||||
} else if ("user blocked".equals(detail)) {
|
||||
Utils.toast(MessageDetailActivity.this, "账号状态异常,暂时无法发表评论");
|
||||
} else if ("article blocked".equals(detail)) {
|
||||
@ -442,6 +458,7 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
mMessageDetailEt.setFocusable(true);
|
||||
mMessageDetailEt.setFocusableInTouchMode(true);
|
||||
mMessageDetailEt.requestFocus();
|
||||
mColseCommentV.setVisibility(View.VISIBLE);
|
||||
|
||||
} else {
|
||||
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
|
||||
@ -449,6 +466,7 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
mMessageDetailLine.setVisibility(View.VISIBLE);
|
||||
mMessageDetailCommentRl.setVisibility(View.GONE);
|
||||
mMessageDetailUserRl.setVisibility(View.GONE);
|
||||
mColseCommentV.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -457,4 +475,15 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
setSoftInput(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
|
||||
if (commentNum != -1 && commentNum != adapter.getConcernEntity().getCommentnum()) {
|
||||
Intent intent= new Intent();
|
||||
intent.putExtra("commentNum", adapter.getConcernEntity().getCommentnum());
|
||||
setResult(1001, intent);
|
||||
}
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user