/
CommentPub.java
160 lines (141 loc) · 4.83 KB
/
CommentPub.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package net.oschina.app.ui;
import net.oschina.app.AppContext;
import net.oschina.app.AppException;
import net.oschina.app.R;
import net.oschina.app.bean.CommentList;
import net.oschina.app.bean.Result;
import net.oschina.app.common.StringUtils;
import net.oschina.app.common.UIHelper;
import net.oschina.app.widget.LinkView;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
/**
* 发表评论
* @author liux (http://my.oschina.net/liux)
* @version 1.0
* @created 2012-3-21
*/
public class CommentPub extends BaseActivity{
public final static int CATALOG_NEWS = 1;
public final static int CATALOG_POST = 2;
public final static int CATALOG_TWEET = 3;
public final static int CATALOG_ACTIVE = 4;
public final static int CATALOG_MESSAGE = 4;//动态与留言都属于消息中心
public final static int CATALOG_BLOG = 5;
private ImageView mBack;
private EditText mContent;
private CheckBox mZone;
private Button mPublish;
private LinkView mQuote;
private ProgressDialog mProgress;
private int _catalog;
private int _id;
private int _uid;
private String _content;
private int _isPostToMyZone;
//-------对评论回复还需加2变量------
private int _replyid;//被回复的单个评论id
private int _authorid;//该评论的原始作者id
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.comment_pub);
this.initView();
}
//初始化视图控件
private void initView()
{
_id = getIntent().getIntExtra("id", 0);
_catalog = getIntent().getIntExtra("catalog", 0);
_replyid = getIntent().getIntExtra("reply_id", 0);
_authorid = getIntent().getIntExtra("author_id", 0);
mBack = (ImageView)findViewById(R.id.comment_list_back);
mPublish = (Button)findViewById(R.id.comment_pub_publish);
mContent = (EditText)findViewById(R.id.comment_pub_content);
mZone = (CheckBox)findViewById(R.id.comment_pub_zone);
if(_catalog == CommentList.CATALOG_TWEET){
mZone.setVisibility(View.VISIBLE);
}
mBack.setOnClickListener(UIHelper.finish(this));
mPublish.setOnClickListener(publishClickListener);
mQuote = (LinkView)findViewById(R.id.comment_pub_quote);
mQuote.setText(UIHelper.parseQuoteSpan(getIntent().getStringExtra("author"),getIntent().getStringExtra("content")));
mQuote.parseLinkText();
}
private View.OnClickListener publishClickListener = new View.OnClickListener() {
public void onClick(View v) {
_content = mContent.getText().toString();
if(StringUtils.isEmpty(_content)){
UIHelper.ToastMessage(v.getContext(), "请输入评论内容");
return;
}
final AppContext ac = (AppContext)getApplication();
if(!ac.isLogin()){
UIHelper.showLoginDialog(CommentPub.this);
return;
}
if(mZone.isChecked())
_isPostToMyZone = 1;
_uid = ac.getLoginUid();
mProgress = ProgressDialog.show(v.getContext(), null, "发表中···",true,true);
final Handler handler = new Handler(){
public void handleMessage(Message msg) {
if(mProgress!=null)mProgress.dismiss();
if(msg.what == 1){
Result res = (Result)msg.obj;
UIHelper.ToastMessage(CommentPub.this, res.getErrorMessage());
if(res.OK()){
//发送通知广播
if(res.getNotice() != null){
UIHelper.sendBroadCast(CommentPub.this, res.getNotice());
}
//返回刚刚发表的评论
Intent intent = new Intent();
intent.putExtra("COMMENT_SERIALIZABLE", res.getComment());
setResult(RESULT_OK, intent);
//跳转到文章详情
finish();
}
}
else {
((AppException)msg.obj).makeToast(CommentPub.this);
}
}
};
new Thread(){
public void run() {
Message msg = new Message();
Result res = new Result();
try {
//发表评论
if(_replyid == 0){
res = ac.pubComment(_catalog, _id, _uid, _content, _isPostToMyZone);
}
//对评论进行回复
else if(_replyid > 0){
if(_catalog == CATALOG_BLOG)
res = ac.replyBlogComment(_id, _uid, _content, _replyid, _authorid);
else
res = ac.replyComment(_id, _catalog, _replyid, _authorid, _uid, _content);
}
msg.what = 1;
msg.obj = res;
} catch (AppException e) {
e.printStackTrace();
msg.what = -1;
msg.obj = e;
}
handler.sendMessage(msg);
}
}.start();
}
};
}