CommentActivity.java
4.94 KB
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
package com.cnlive.im.ui;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.cnlive.im.R;
import com.cnlive.im.adapter.CommentAdapter;
import com.cnlive.libs.util.comment.CommentUtil;
import com.cnlive.libs.util.comment.base.CommentCallback;
import com.cnlive.libs.util.comment.base.CommentListCallback;
import com.cnlive.libs.util.comment.base.CommentProgramCallback;
import com.cnlive.libs.util.comment.model.CommentItem;
import com.cnlive.libs.util.comment.model.CommentPage;
import com.cnlive.libs.util.comment.model.CommentProgram;
import com.cnlive.libs.util.comment.model.ErrorMessage;
import java.util.List;
/**
* @author 陈硕
* @time 2017/6/9 9:28
* @desc ${TODD}
*/
public class CommentActivity extends AppCompatActivity implements View.OnClickListener, CommentAdapter.OnImageViewClick {
private Button btn_sent;
private EditText edit_comment;
private CommentUtil commentUtil;
private CommentAdapter commentAdapter;
private RecyclerView recyclerView;
private String programID = "123";
private String userID = "12344";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comment);
commentAdapter = new CommentAdapter(CommentActivity.this);
initUI();
}
private void initUI() {
recyclerView = (RecyclerView) findViewById(R.id.comment_content);
recyclerView.setLayoutManager(new LinearLayoutManager(CommentActivity.this));
btn_sent = (Button) findViewById(R.id.sendBtn_comment);
edit_comment = (EditText) findViewById(R.id.et_search);
btn_sent.setOnClickListener(this);
commentAdapter.setOnImageViewClick(this);
intiDate();
}
private void intiDate() {
if (commentUtil == null) {
commentUtil = new CommentUtil();
}
getCommentProgram();
getCommentMesaage();
}
@Override
public void onClick(View v) {
final String text = edit_comment.getText().toString();
if (TextUtils.isEmpty(text)) {
Toast.makeText(CommentActivity.this, "输入内容不能为空", Toast.LENGTH_SHORT).show();
} else {
commentUtil.insertComment(programID, userID, text, new CommentCallback() {
@Override
public void onResponse(ErrorMessage errorMessage) {
if (errorMessage != null && errorMessage.getErrorCode().equals("0")) {
Toast.makeText(CommentActivity.this, "评论成功", Toast.LENGTH_SHORT).show();
edit_comment.setText("");
commentAdapter.clearItems();
getCommentMesaage();
} else
Toast.makeText(CommentActivity.this, "评论失败 : " + errorMessage.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
public void getCommentMesaage() {
commentUtil.readAllComment(programID, 1, 10, new CommentListCallback() {
@Override
public void onResponse(CommentPage commentPage) {
if (commentPage.getData() != null) {
Log.v("commentPage", commentPage.getErrorMessage() + "");
List<CommentItem> comments = commentPage.getData().getComments();
recyclerView.setAdapter(commentAdapter);
if (comments != null) {
commentAdapter.addItems(comments);
}
}
}
});
}
public void getCommentProgram() {
commentUtil.programComment(programID, new CommentProgramCallback() {
@Override
public void onResponse(CommentProgram commentProgram) {
if (commentProgram.getData() != null && commentProgram.getData().getComments() != null)
Log.v("commentProgram", commentProgram.getData().getComments().size() + "");
}
});
}
@Override
public void praiseComment(CommentItem commentItem) {
commentUtil.praiseComment(programID, userID, commentItem.getId(), new CommentCallback() {
@Override
public void onResponse(ErrorMessage errorMessage) {
if (errorMessage != null && errorMessage.getErrorCode().equals("0")) {
Toast.makeText(CommentActivity.this, "点赞成功", Toast.LENGTH_SHORT).show();
commentAdapter.clearItems();
getCommentMesaage();
} else Toast.makeText(CommentActivity.this, "点赞失败", Toast.LENGTH_SHORT).show();
}
});
}
}