/** 获取并初始化评论的对话框 */ @Override protected CommentDialog getCommentDialog() { if (mCommentDialog == null) { mCommentDialog = new CommentDialog(this); mCommentDialog.setOnCommentCallListener(this); } return mCommentDialog; }
/** 发送评论 */ @Override public void onCommentCall(final String text) { final int uid = mApplication.getLoginUid(); if (uid <= 0) { Toast.makeText(this, R.string.msg_login_request, Toast.LENGTH_LONG).show(); startActivity(new Intent(this, LoginActivity.class)); return; } // 隐藏评论对话框 if (mCommentDialog != null) { mCommentDialog.dismiss(); } final ProgressDialog dialog = new ProgressDialog(this); dialog.setMessage(getString(R.string.comment_publish_loading)); // 异步发表 new AsyncTask<Void, Void, Message>() { @Override protected void onPreExecute() { dialog.show(); } @Override protected Message doInBackground(Void... params) { Message msg = new Message(); try { Result res = getOsChinaApplication().pubComment(1, mNewsId, uid, text, 0); msg.what = 1; msg.obj = res; } catch (AppException e) { e.printStackTrace(); msg.what = -1; msg.obj = e; } return msg; } @Override protected void onPostExecute(Message msg) { if (isFinishing()) { return; } final Context context = NewsDetailActivity.this; dialog.dismiss(); if (msg.what == 1) { Result res = (Result) msg.obj; if (res.OK()) { UIHelper.ToastMessage(context, R.string.comment_publish_success); // 显示评论数 mCommentCount++; updateButton(); // 更新评论界面 updateCommentFragment(mNewsId); // 更新缓存数据 loadDatas(true); } else { UIHelper.ToastMessage(context, res.getErrorMessage()); } } else { ((AppException) msg.obj).makeToast(context); } } }.execute(); }