Commit 93daa41ab87f0c7a44e69241a524f4933e500e65

Authored by 陈硕
1 parent 019b582b

添加互动添加接口测试

app/libs/libcnliveutil.jar
No preview for this file type
app/note/聊天SDK文档.pdf
No preview for this file type
app/src/main/java/com/cnlive/im/adapter/CommentAdapter.java
... ... @@ -22,7 +22,7 @@ import java.util.List;
22 22 public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.CommentHolder> {
23 23  
24 24 protected List<CommentItem> mItems = new ArrayList<CommentItem>();
25   -
  25 + protected OnImageViewClick onImageViewClick;
26 26 Context context;
27 27 private final LayoutInflater mLayoutInflater;
28 28 private CommentHolder commentHolder;
... ... @@ -59,10 +59,18 @@ public class CommentAdapter extends RecyclerView.Adapter&lt;CommentAdapter.CommentH
59 59 @Override
60 60 public void onBindViewHolder(CommentHolder holder, int position) {
61 61  
62   - CommentItem commentItem = mItems.get(position);
63   - commentHolder.nick_name.setText(commentItem.getNick());
  62 + final CommentItem commentItem = mItems.get(position);
  63 + commentHolder.nick_name.setText(commentItem.getUid());
64 64 commentHolder.comment_message.setText(commentItem.getContent());
65 65 commentHolder.comment_good_count.setText(commentItem.getPraise());
  66 + commentHolder.good_imv1.setOnClickListener(new View.OnClickListener() {
  67 + @Override
  68 + public void onClick(View v) {
  69 + if (onImageViewClick != null) {
  70 + onImageViewClick.praiseComment(commentItem);
  71 + }
  72 + }
  73 + });
66 74  
67 75  
68 76 }
... ... @@ -72,6 +80,13 @@ public class CommentAdapter extends RecyclerView.Adapter&lt;CommentAdapter.CommentH
72 80 return mItems.size();
73 81 }
74 82  
  83 + public void setOnImageViewClick(OnImageViewClick onImageViewClick) {
  84 + this.onImageViewClick = onImageViewClick;
  85 + }
  86 +
  87 + public interface OnImageViewClick {
  88 + void praiseComment(CommentItem commentItem);
  89 + }
75 90  
76 91 class CommentHolder extends RecyclerView.ViewHolder {
77 92  
... ...
app/src/main/java/com/cnlive/im/ui/CommentActivity.java
... ... @@ -17,10 +17,11 @@ import com.cnlive.libs.util.chat.model.ErrorMessage;
17 17 import com.cnlive.libs.util.comment.CommentUtil;
18 18 import com.cnlive.libs.util.comment.base.CommentCallback;
19 19 import com.cnlive.libs.util.comment.base.CommentListCallback;
  20 +import com.cnlive.libs.util.comment.base.CommentProgramCallback;
20 21 import com.cnlive.libs.util.model.CommentItem;
21 22 import com.cnlive.libs.util.model.CommentPage;
  23 +import com.cnlive.libs.util.model.CommentProgram;
22 24  
23   -import java.util.ArrayList;
24 25 import java.util.List;
25 26  
26 27 /**
... ... @@ -28,16 +29,16 @@ import java.util.List;
28 29 * @time 2017/6/9 9:28
29 30 * @desc ${TODD}
30 31 */
31   -public class CommentActivity extends AppCompatActivity implements View.OnClickListener {
  32 +public class CommentActivity extends AppCompatActivity implements View.OnClickListener, CommentAdapter.OnImageViewClick {
32 33  
33 34  
34 35 private Button btn_sent;
35 36 private EditText edit_comment;
36   - private RecyclerView comment_receycel;
37 37 private CommentUtil commentUtil;
38   - private List<CommentItem> items = new ArrayList<>();
39 38 private CommentAdapter commentAdapter;
40 39 private RecyclerView recyclerView;
  40 + private String programID = "123";
  41 + private String userID = "12344";
41 42  
42 43 @Override
43 44 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -55,6 +56,7 @@ public class CommentActivity extends AppCompatActivity implements View.OnClickLi
55 56 btn_sent = (Button) findViewById(R.id.sendBtn_comment);
56 57 edit_comment = (EditText) findViewById(R.id.et_search);
57 58 btn_sent.setOnClickListener(this);
  59 + commentAdapter.setOnImageViewClick(this);
58 60 intiDate();
59 61  
60 62 }
... ... @@ -63,6 +65,7 @@ public class CommentActivity extends AppCompatActivity implements View.OnClickLi
63 65 if (commentUtil == null) {
64 66 commentUtil = new CommentUtil();
65 67 }
  68 + getCommentProgram();
66 69 getCommentMesaage();
67 70 }
68 71  
... ... @@ -73,13 +76,16 @@ public class CommentActivity extends AppCompatActivity implements View.OnClickLi
73 76 if (TextUtils.isEmpty(text)) {
74 77 Toast.makeText(CommentActivity.this, "输入内容不能为空", Toast.LENGTH_SHORT).show();
75 78 } else {
76   - commentUtil.insertComment("123", "12344", text, new CommentCallback() {
  79 + commentUtil.insertComment(programID, userID, text, new CommentCallback() {
77 80 @Override
78 81 public void onResponse(ErrorMessage errorMessage) {
79   - Log.v("errorMessage", errorMessage.getErrorMessage());
80   - edit_comment.setText("");
81   - commentAdapter.clearItems();
82   - getCommentMesaage();
  82 + if (errorMessage != null && errorMessage.getErrorCode().equals("0")) {
  83 + Toast.makeText(CommentActivity.this, "评论成功", Toast.LENGTH_SHORT).show();
  84 + edit_comment.setText("");
  85 + commentAdapter.clearItems();
  86 + getCommentMesaage();
  87 + } else Toast.makeText(CommentActivity.this, "评论失败", Toast.LENGTH_SHORT).show();
  88 +
83 89 }
84 90 });
85 91 }
... ... @@ -87,20 +93,46 @@ public class CommentActivity extends AppCompatActivity implements View.OnClickLi
87 93  
88 94  
89 95 public void getCommentMesaage() {
90   - commentUtil.readAllComment("123", 1, 10, new CommentListCallback() {
  96 + commentUtil.readAllComment(programID, 1, 10, new CommentListCallback() {
91 97 @Override
92 98 public void onResponse(CommentPage commentPage) {
93 99 if (commentPage.getData() != null) {
94   -
  100 +Log.v("commentPage",commentPage.getErrorMessage()+"");
95 101 List<CommentItem> comments = commentPage.getData().getComments();
96 102  
97 103 recyclerView.setAdapter(commentAdapter);
98 104 commentAdapter.addItems(comments);
99   - Log.v("comments", commentPage.toString());
100 105  
101 106  
102 107 }
103 108 }
104 109 });
105 110 }
  111 +
  112 + public void getCommentProgram() {
  113 + commentUtil.programComment(programID, new CommentProgramCallback() {
  114 + @Override
  115 + public void onResponse(CommentProgram commentProgram) {
  116 + Log.v("commentProgram",commentProgram.getData().getComments().size()+"");
  117 +
  118 + }
  119 + });
  120 + }
  121 +
  122 + @Override
  123 + public void praiseComment(CommentItem commentItem) {
  124 + commentUtil.praiseComment(programID, userID, commentItem.getId(), new CommentCallback() {
  125 + @Override
  126 + public void onResponse(ErrorMessage errorMessage) {
  127 + if (errorMessage != null && errorMessage.getErrorCode().equals("0")) {
  128 + Toast.makeText(CommentActivity.this, "点赞成功", Toast.LENGTH_SHORT).show();
  129 + commentAdapter.clearItems();
  130 + getCommentMesaage();
  131 + } else Toast.makeText(CommentActivity.this, "点赞失败", Toast.LENGTH_SHORT).show();
  132 +
  133 + }
  134 + });
  135 + }
  136 +
  137 +
106 138 }
... ...
app/src/main/res/layout/activity_main.xml
... ... @@ -26,4 +26,6 @@
26 26 android:text="评论"
27 27 />
28 28  
  29 +
  30 +
29 31 </RelativeLayout>
... ...
app/src/main/res/layout/commet_item.xml
1 1 <?xml version="1.0" encoding="utf-8"?>
2 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 3 android:layout_width="match_parent"
4   - android:layout_height="wrap_content"
  4 + android:layout_height="30dp"
5 5 >
6 6 <TextView
7 7 android:id="@+id/nick_name"
8 8 android:text="游客"
9 9 android:layout_width="wrap_content"
10   - android:layout_height="wrap_content" />
  10 + android:layout_height="wrap_content"
  11 + android:layout_marginRight="10dp"/>
11 12  
12 13 <TextView
13 14 android:layout_toRightOf="@+id/nick_name"
... ... @@ -20,13 +21,13 @@
20 21 android:layout_height="wrap_content" />
21 22  
22 23 <ImageView android:id="@+id/good_imv"
23   -
24 24 android:layout_width="24dp"
25 25 android:layout_height="24dp"
26   - android:src="@drawable/vod_detail_good_off"
  26 + android:src="@drawable/vod_detail_good"
27 27 android:layout_toLeftOf="@+id/comment_good_count"
28 28 android:layout_marginLeft="5dp"
29 29 android:layout_centerVertical="true"
  30 + android:clickable="true"
30 31 />
31 32  
32 33  
... ... @@ -38,7 +39,8 @@
38 39 android:layout_width="wrap_content"
39 40 android:layout_height="wrap_content"
40 41 android:layout_alignParentRight="true"
41   - android:layout_marginLeft="5dp"/>
  42 + android:layout_marginLeft="10dp"
  43 + android:layout_marginRight="10dp"/>
42 44  
43 45  
44 46 </RelativeLayout>
45 47 \ No newline at end of file
... ...