CommentMentionDialog.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.ouling.weibo;
  2. import android.app.Activity;
  3. import android.app.AlertDialog;
  4. import android.content.Context;
  5. import android.content.DialogInterface;
  6. import android.text.TextUtils;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.widget.CheckBox;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12. import com.ouling.weibo.OAuth.OAuthConstant;
  13. import com.ouling.weibo.basic.Weibo;
  14. import com.ouling.weibo.basic.WeiboException;
  15. //用于显示评论转发的提示
  16. public class CommentMentionDialog {
  17. private CheckBox checkBox;
  18. private EditText editText;
  19. public CommentMentionDialog(final Context context, final boolean isComment,
  20. final long weiboID, final String cid) {
  21. LayoutInflater inflater = ((Activity) context).getLayoutInflater();
  22. View layout = inflater.inflate(R.layout.dialog, null);
  23. new AlertDialog.Builder(context)
  24. .setView(layout)
  25. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  26. @Override
  27. public void onClick(DialogInterface dialog, int which) {
  28. try {
  29. Weibo weibo = OAuthConstant.getInstance().getWeibo();
  30. String text = editText.getText().toString();
  31. String msg = "";
  32. if (TextUtils.isEmpty(text)) {
  33. Toast.makeText(context, "说点什么吧",
  34. Toast.LENGTH_LONG).show();
  35. return;
  36. }
  37. if (text.length() > 140) {
  38. Toast.makeText(context, "要评论的内容太长了",
  39. Toast.LENGTH_LONG).show();
  40. return;
  41. }
  42. if (isComment) {
  43. weibo.updateComment(text, weiboID + "", cid);
  44. msg = "评论成功";
  45. if (checkBox.isChecked()) {
  46. weibo.updateStatus(text, weiboID);
  47. msg = "评论且转发成功";
  48. }
  49. } else {
  50. weibo.updateStatus(text, weiboID);
  51. msg = "转发成功";
  52. if (checkBox.isChecked()) {
  53. weibo.updateComment(text, weiboID + "", cid);
  54. msg = "评论且转发成功";
  55. }
  56. }
  57. Toast.makeText(context, msg, Toast.LENGTH_LONG)
  58. .show();
  59. } catch (WeiboException e) {
  60. e.printStackTrace();
  61. Toast.makeText(context, "评论或转发失败",
  62. Toast.LENGTH_LONG).show();
  63. }
  64. }
  65. })
  66. .setNegativeButton("取消", new DialogInterface.OnClickListener() {
  67. @Override
  68. public void onClick(DialogInterface dialog, int which) {
  69. }
  70. }).setTitle(isComment ? "评论微博" : "转发微博").show();
  71. checkBox = (CheckBox) layout.findViewById(R.id.dialog_cb);
  72. editText = (EditText) layout.findViewById(R.id.dialog_et);
  73. }
  74. }