CommentActivity.java
3.27 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
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.chat.model.ErrorMessage;
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.model.CommentItem;
import com.cnlive.libs.util.model.CommentPage;
import java.util.ArrayList;
import java.util.List;
/**
* @author 陈硕
* @time 2017/6/9 9:28
* @desc ${TODD}
*/
public class CommentActivity extends AppCompatActivity implements View.OnClickListener {
private Button btn_sent;
private EditText edit_comment;
private RecyclerView comment_receycel;
private CommentUtil commentUtil;
private List<CommentItem> items = new ArrayList<>();
private CommentAdapter commentAdapter;
private RecyclerView recyclerView;
@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);
intiDate();
}
private void intiDate() {
if (commentUtil == null) {
commentUtil = new CommentUtil();
}
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("123", "12344", text, new CommentCallback() {
@Override
public void onResponse(ErrorMessage errorMessage) {
Log.v("errorMessage", errorMessage.getErrorMessage());
edit_comment.setText("");
commentAdapter.clearItems();
getCommentMesaage();
}
});
}
}
public void getCommentMesaage() {
commentUtil.readAllComment("123", 1, 10, new CommentListCallback() {
@Override
public void onResponse(CommentPage commentPage) {
if (commentPage.getData() != null) {
List<CommentItem> comments = commentPage.getData().getComments();
recyclerView.setAdapter(commentAdapter);
commentAdapter.addItems(comments);
Log.v("comments", commentPage.toString());
}
}
});
}
}