Commit 019b582b816604ff95b238977b888604300202ce
1 parent
e6e09bde
添加互动demo
Showing
18 changed files
with
372 additions
and
7 deletions
.idea/modules.xml
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | <modules> |
| 5 | 5 | <module fileurl="file://$PROJECT_DIR$/CNChatNDemo.iml" filepath="$PROJECT_DIR$/CNChatNDemo.iml" /> |
| 6 | 6 | <module fileurl="file://$PROJECT_DIR$/CNIMDemo.iml" filepath="$PROJECT_DIR$/CNIMDemo.iml" /> |
| 7 | + <module fileurl="file://$PROJECT_DIR$/CNIMDemo5.iml" filepath="$PROJECT_DIR$/CNIMDemo5.iml" /> | |
| 7 | 8 | <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> |
| 8 | 9 | </modules> |
| 9 | 10 | </component> | ... | ... |
app/build.gradle
app/libs/libcnliveutil.jar
No preview for this file type
app/src/main/AndroidManifest.xml
| ... | ... | @@ -62,6 +62,14 @@ |
| 62 | 62 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
| 63 | 63 | |
| 64 | 64 | <activity |
| 65 | + android:name="com.cnlive.im.ui.CommentActivity" | |
| 66 | + android:launchMode="singleTop" | |
| 67 | + android:screenOrientation="portrait" | |
| 68 | + android:windowSoftInputMode="adjustResize" | |
| 69 | + android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | |
| 70 | + | |
| 71 | + | |
| 72 | + <activity | |
| 65 | 73 | android:name=".ui.ChatItemActivity" |
| 66 | 74 | android:launchMode="singleTop" |
| 67 | 75 | android:screenOrientation="portrait" | ... | ... |
app/src/main/java/com/cnlive/im/adapter/CommentAdapter.java
0 → 100644
| 1 | +package com.cnlive.im.adapter; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | +import android.support.v7.widget.RecyclerView; | |
| 5 | +import android.view.LayoutInflater; | |
| 6 | +import android.view.View; | |
| 7 | +import android.view.ViewGroup; | |
| 8 | +import android.widget.ImageView; | |
| 9 | +import android.widget.TextView; | |
| 10 | + | |
| 11 | +import com.cnlive.im.R; | |
| 12 | +import com.cnlive.libs.util.model.CommentItem; | |
| 13 | + | |
| 14 | +import java.util.ArrayList; | |
| 15 | +import java.util.List; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * @author 陈硕 | |
| 19 | + * @time 2017/6/9 10:56 | |
| 20 | + * @desc ${TODD} | |
| 21 | + */ | |
| 22 | +public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.CommentHolder> { | |
| 23 | + | |
| 24 | + protected List<CommentItem> mItems = new ArrayList<CommentItem>(); | |
| 25 | + | |
| 26 | + Context context; | |
| 27 | + private final LayoutInflater mLayoutInflater; | |
| 28 | + private CommentHolder commentHolder; | |
| 29 | + | |
| 30 | + public CommentAdapter(Context context) { | |
| 31 | + this.context = context; | |
| 32 | + mLayoutInflater = LayoutInflater.from(context); | |
| 33 | + | |
| 34 | + } | |
| 35 | + | |
| 36 | + public void addItems(List<CommentItem> items) { | |
| 37 | + mItems.addAll(items); | |
| 38 | + notifyDataSetChanged(); | |
| 39 | + } | |
| 40 | + | |
| 41 | + public void refreshItems(List<CommentItem> items) { | |
| 42 | + mItems.clear(); | |
| 43 | + mItems.addAll(items); | |
| 44 | + notifyDataSetChanged(); | |
| 45 | + } | |
| 46 | + | |
| 47 | + public void clearItems() { | |
| 48 | + mItems.clear(); | |
| 49 | + } | |
| 50 | + | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public CommentHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
| 54 | + View view = mLayoutInflater.inflate(R.layout.commet_item, parent, false); | |
| 55 | + commentHolder = new CommentHolder(view); | |
| 56 | + return commentHolder; | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Override | |
| 60 | + public void onBindViewHolder(CommentHolder holder, int position) { | |
| 61 | + | |
| 62 | + CommentItem commentItem = mItems.get(position); | |
| 63 | + commentHolder.nick_name.setText(commentItem.getNick()); | |
| 64 | + commentHolder.comment_message.setText(commentItem.getContent()); | |
| 65 | + commentHolder.comment_good_count.setText(commentItem.getPraise()); | |
| 66 | + | |
| 67 | + | |
| 68 | + } | |
| 69 | + | |
| 70 | + @Override | |
| 71 | + public int getItemCount() { | |
| 72 | + return mItems.size(); | |
| 73 | + } | |
| 74 | + | |
| 75 | + | |
| 76 | + class CommentHolder extends RecyclerView.ViewHolder { | |
| 77 | + | |
| 78 | + public final TextView nick_name; | |
| 79 | + public final TextView comment_message; | |
| 80 | + public final TextView comment_good_count; | |
| 81 | + public final ImageView good_imv1; | |
| 82 | + | |
| 83 | + public CommentHolder(View itemView) { | |
| 84 | + super(itemView); | |
| 85 | + nick_name = (TextView) itemView.findViewById(R.id.nick_name); | |
| 86 | + good_imv1 = (ImageView) itemView.findViewById(R.id.good_imv); | |
| 87 | + comment_message = (TextView) itemView.findViewById(R.id.comment_message); | |
| 88 | + comment_good_count = (TextView) itemView.findViewById(R.id.comment_good_count); | |
| 89 | + | |
| 90 | + | |
| 91 | + } | |
| 92 | + | |
| 93 | + | |
| 94 | + } | |
| 95 | + | |
| 96 | + | |
| 97 | +} | ... | ... |
app/src/main/java/com/cnlive/im/ui/ChatRoomActivity.java
| ... | ... | @@ -63,7 +63,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 63 | 63 | initUI(); |
| 64 | 64 | //设置监听 |
| 65 | 65 | mHandler = new Handler(); |
| 66 | - ChatUtil.setConnectStatusListener(connectStatusListener); | |
| 66 | + ChatUtil.setOnConnectStatusListener(connectStatusListener); | |
| 67 | 67 | ChatUtil.setOnChatRoomActionListener(chatRoomActionListener); |
| 68 | 68 | ChatUtil.setOnReceiveMessageListener(receiveMessageListener); |
| 69 | 69 | |
| ... | ... | @@ -312,12 +312,13 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 312 | 312 | |
| 313 | 313 | |
| 314 | 314 | private IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { |
| 315 | + | |
| 316 | + | |
| 315 | 317 | @Override |
| 316 | - public void onTokenIncorrect() { | |
| 318 | + public void onTokenIncorrect(String s) { | |
| 317 | 319 | Log.e(TAG, "ConnectListener TokenIncorrect"); |
| 318 | 320 | Toast.makeText(ChatRoomActivity.this, "TokenIncorrect", Toast.LENGTH_SHORT).show(); |
| 319 | 321 | finish(); |
| 320 | - | |
| 321 | 322 | } |
| 322 | 323 | |
| 323 | 324 | @Override | ... | ... |
app/src/main/java/com/cnlive/im/ui/CommentActivity.java
0 → 100644
| 1 | +package com.cnlive.im.ui; | |
| 2 | + | |
| 3 | +import android.os.Bundle; | |
| 4 | +import android.support.v7.app.AppCompatActivity; | |
| 5 | +import android.support.v7.widget.LinearLayoutManager; | |
| 6 | +import android.support.v7.widget.RecyclerView; | |
| 7 | +import android.text.TextUtils; | |
| 8 | +import android.util.Log; | |
| 9 | +import android.view.View; | |
| 10 | +import android.widget.Button; | |
| 11 | +import android.widget.EditText; | |
| 12 | +import android.widget.Toast; | |
| 13 | + | |
| 14 | +import com.cnlive.im.R; | |
| 15 | +import com.cnlive.im.adapter.CommentAdapter; | |
| 16 | +import com.cnlive.libs.util.chat.model.ErrorMessage; | |
| 17 | +import com.cnlive.libs.util.comment.CommentUtil; | |
| 18 | +import com.cnlive.libs.util.comment.base.CommentCallback; | |
| 19 | +import com.cnlive.libs.util.comment.base.CommentListCallback; | |
| 20 | +import com.cnlive.libs.util.model.CommentItem; | |
| 21 | +import com.cnlive.libs.util.model.CommentPage; | |
| 22 | + | |
| 23 | +import java.util.ArrayList; | |
| 24 | +import java.util.List; | |
| 25 | + | |
| 26 | +/** | |
| 27 | + * @author 陈硕 | |
| 28 | + * @time 2017/6/9 9:28 | |
| 29 | + * @desc ${TODD} | |
| 30 | + */ | |
| 31 | +public class CommentActivity extends AppCompatActivity implements View.OnClickListener { | |
| 32 | + | |
| 33 | + | |
| 34 | + private Button btn_sent; | |
| 35 | + private EditText edit_comment; | |
| 36 | + private RecyclerView comment_receycel; | |
| 37 | + private CommentUtil commentUtil; | |
| 38 | + private List<CommentItem> items = new ArrayList<>(); | |
| 39 | + private CommentAdapter commentAdapter; | |
| 40 | + private RecyclerView recyclerView; | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + protected void onCreate(Bundle savedInstanceState) { | |
| 44 | + super.onCreate(savedInstanceState); | |
| 45 | + setContentView(R.layout.activity_comment); | |
| 46 | + commentAdapter = new CommentAdapter(CommentActivity.this); | |
| 47 | + initUI(); | |
| 48 | + | |
| 49 | + | |
| 50 | + } | |
| 51 | + | |
| 52 | + private void initUI() { | |
| 53 | + recyclerView = (RecyclerView) findViewById(R.id.comment_content); | |
| 54 | + recyclerView.setLayoutManager(new LinearLayoutManager(CommentActivity.this)); | |
| 55 | + btn_sent = (Button) findViewById(R.id.sendBtn_comment); | |
| 56 | + edit_comment = (EditText) findViewById(R.id.et_search); | |
| 57 | + btn_sent.setOnClickListener(this); | |
| 58 | + intiDate(); | |
| 59 | + | |
| 60 | + } | |
| 61 | + | |
| 62 | + private void intiDate() { | |
| 63 | + if (commentUtil == null) { | |
| 64 | + commentUtil = new CommentUtil(); | |
| 65 | + } | |
| 66 | + getCommentMesaage(); | |
| 67 | + } | |
| 68 | + | |
| 69 | + | |
| 70 | + @Override | |
| 71 | + public void onClick(View v) { | |
| 72 | + final String text = edit_comment.getText().toString(); | |
| 73 | + if (TextUtils.isEmpty(text)) { | |
| 74 | + Toast.makeText(CommentActivity.this, "输入内容不能为空", Toast.LENGTH_SHORT).show(); | |
| 75 | + } else { | |
| 76 | + commentUtil.insertComment("123", "12344", text, new CommentCallback() { | |
| 77 | + @Override | |
| 78 | + public void onResponse(ErrorMessage errorMessage) { | |
| 79 | + Log.v("errorMessage", errorMessage.getErrorMessage()); | |
| 80 | + edit_comment.setText(""); | |
| 81 | + commentAdapter.clearItems(); | |
| 82 | + getCommentMesaage(); | |
| 83 | + } | |
| 84 | + }); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + | |
| 88 | + | |
| 89 | + public void getCommentMesaage() { | |
| 90 | + commentUtil.readAllComment("123", 1, 10, new CommentListCallback() { | |
| 91 | + @Override | |
| 92 | + public void onResponse(CommentPage commentPage) { | |
| 93 | + if (commentPage.getData() != null) { | |
| 94 | + | |
| 95 | + List<CommentItem> comments = commentPage.getData().getComments(); | |
| 96 | + | |
| 97 | + recyclerView.setAdapter(commentAdapter); | |
| 98 | + commentAdapter.addItems(comments); | |
| 99 | + Log.v("comments", commentPage.toString()); | |
| 100 | + | |
| 101 | + | |
| 102 | + } | |
| 103 | + } | |
| 104 | + }); | |
| 105 | + } | |
| 106 | +} | ... | ... |
app/src/main/java/com/cnlive/im/ui/MainActivity.java
| ... | ... | @@ -15,6 +15,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | private Button connectedBtn; |
| 18 | + private Button commentBtn; | |
| 18 | 19 | |
| 19 | 20 | @Override |
| 20 | 21 | protected void onCreate(Bundle savedInstanceState) { |
| ... | ... | @@ -26,13 +27,22 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe |
| 26 | 27 | private void initUI() { |
| 27 | 28 | connectedBtn = (Button) findViewById(R.id.connected); |
| 28 | 29 | connectedBtn.setOnClickListener(this); |
| 30 | + commentBtn = (Button) findViewById(R.id.comment); | |
| 31 | + commentBtn.setOnClickListener(new View.OnClickListener() { | |
| 32 | + @Override | |
| 33 | + public void onClick(View v) { | |
| 34 | + startActivity(new Intent(MainActivity.this,CommentActivity.class)); | |
| 35 | + } | |
| 36 | + }); | |
| 29 | 37 | } |
| 30 | 38 | |
| 31 | 39 | |
| 32 | 40 | |
| 33 | 41 | IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { |
| 42 | + | |
| 43 | + | |
| 34 | 44 | @Override |
| 35 | - public void onTokenIncorrect() { | |
| 45 | + public void onTokenIncorrect(String s) { | |
| 36 | 46 | connectedBtn.setText("重新连接"); |
| 37 | 47 | } |
| 38 | 48 | ... | ... |
app/src/main/java/com/cnlive/im/ui/PrivateChatActivity.java
| ... | ... | @@ -66,7 +66,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli |
| 66 | 66 | setContentView(R.layout.activity_private_chat); |
| 67 | 67 | initView(); |
| 68 | 68 | mHandler = new Handler(); |
| 69 | - ChatUtil.setConnectStatusListener(connectStatusListener); | |
| 69 | + ChatUtil.setOnConnectStatusListener(connectStatusListener); | |
| 70 | 70 | ChatUtil.setOnReceiveMessageListener(receiveMessageListener); |
| 71 | 71 | } |
| 72 | 72 | |
| ... | ... | @@ -168,8 +168,10 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli |
| 168 | 168 | |
| 169 | 169 | //连接监听 |
| 170 | 170 | private IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { |
| 171 | + | |
| 172 | + | |
| 171 | 173 | @Override |
| 172 | - public void onTokenIncorrect() { | |
| 174 | + public void onTokenIncorrect(String s) { | |
| 173 | 175 | Log.e(TAG, "ConnectListener TokenIncorrect"); |
| 174 | 176 | Toast.makeText(PrivateChatActivity.this, "TokenIncorrect", Toast.LENGTH_SHORT).show(); |
| 175 | 177 | } | ... | ... |
app/src/main/res/drawable-hdpi/vod_detail_good_off.png
0 → 100644
2.01 KB
app/src/main/res/drawable-hdpi/vod_detail_good_on.png
0 → 100644
1.94 KB
app/src/main/res/drawable/btn_back_ground.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<shape | |
| 3 | + xmlns:android="http://schemas.android.com/apk/res/android" | |
| 4 | + android:shape="rectangle"> | |
| 5 | + <!-- 填充的颜色 --> | |
| 6 | + <solid android:color="#FFFFFF" /> | |
| 7 | + <!-- 设置按钮的四个角为弧形 --> | |
| 8 | + <!-- android:radius 弧形的半径 --> | |
| 9 | + <corners android:radius="5dip" /> | |
| 10 | + | |
| 11 | + <!-- padding:Button里面的文字与Button边界的间隔 --> | |
| 12 | + <padding | |
| 13 | + android:left="10dp" | |
| 14 | + android:top="10dp" | |
| 15 | + android:right="10dp" | |
| 16 | + android:bottom="10dp" | |
| 17 | + /> | |
| 18 | +</shape> | |
| 0 | 19 | \ No newline at end of file | ... | ... |
app/src/main/res/drawable/home_search_edittet_bg.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + android:shape="rectangle"> | |
| 4 | + <!-- 填充的颜色 --> | |
| 5 | + <solid android:color="#3e3d43" /> | |
| 6 | + <!-- 设置按钮的四个角为弧形 --> | |
| 7 | + <!-- android:radius 弧形的半径 --> | |
| 8 | + <corners android:radius="6dp" /> | |
| 9 | + | |
| 10 | + <!-- padding:Button里面的文字与Button边界的间隔 --> | |
| 11 | + <padding | |
| 12 | + android:bottom="1dp" | |
| 13 | + android:left="6dp" | |
| 14 | + android:right="6dp" | |
| 15 | + android:top="1dp" /> | |
| 16 | +</shape> | |
| 0 | 17 | \ No newline at end of file | ... | ... |
app/src/main/res/drawable/vod_detail_good.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + <item android:state_pressed="true" android:drawable="@drawable/vod_detail_good_on" /> | |
| 4 | + <item android:state_pressed="false" android:drawable="@drawable/vod_detail_good_off" /> | |
| 5 | +</selector> | |
| 0 | 6 | \ No newline at end of file | ... | ... |
app/src/main/res/layout/activity_comment.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + android:layout_width="match_parent" | |
| 4 | + android:layout_height="match_parent" | |
| 5 | + android:orientation="vertical"> | |
| 6 | + | |
| 7 | + <RelativeLayout | |
| 8 | + android:layout_width="match_parent" | |
| 9 | + android:layout_height="wrap_content"> | |
| 10 | + | |
| 11 | + <Button | |
| 12 | + android:id="@+id/sendBtn_comment" | |
| 13 | + android:layout_width="wrap_content" | |
| 14 | + android:layout_height="wrap_content" | |
| 15 | + android:layout_alignParentRight="true" | |
| 16 | + android:text="发送" /> | |
| 17 | + | |
| 18 | + | |
| 19 | + <EditText | |
| 20 | + android:id="@+id/et_search" | |
| 21 | + android:layout_width="match_parent" | |
| 22 | + android:layout_height="29dp" | |
| 23 | + android:layout_centerVertical="true" | |
| 24 | + android:layout_toLeftOf="@+id/sendBtn_comment" | |
| 25 | + android:background="@drawable/home_search_edittet_bg" | |
| 26 | + android:drawablePadding="8dp" | |
| 27 | + android:hint="评论内容" | |
| 28 | + android:imeOptions="actionGo" | |
| 29 | + android:singleLine="true" | |
| 30 | + android:textColor="@android:color/white" | |
| 31 | + android:textColorHint="@android:color/black" | |
| 32 | + android:textSize="12sp" /> | |
| 33 | + | |
| 34 | + | |
| 35 | + </RelativeLayout> | |
| 36 | + | |
| 37 | + | |
| 38 | + <android.support.v7.widget.RecyclerView | |
| 39 | + android:id="@+id/comment_content" | |
| 40 | + android:layout_width="match_parent" | |
| 41 | + android:layout_height="match_parent"> | |
| 42 | + | |
| 43 | + </android.support.v7.widget.RecyclerView> | |
| 44 | + | |
| 45 | +</LinearLayout> | |
| 0 | 46 | \ No newline at end of file | ... | ... |
app/src/main/res/layout/activity_groupchat.xml
app/src/main/res/layout/activity_main.xml
| ... | ... | @@ -15,4 +15,15 @@ |
| 15 | 15 | android:text="连接" |
| 16 | 16 | /> |
| 17 | 17 | |
| 18 | + | |
| 19 | + <Button | |
| 20 | + android:id="@+id/comment" | |
| 21 | + android:layout_marginBottom="40dp" | |
| 22 | + android:layout_below="@+id/connected" | |
| 23 | + android:layout_width="match_parent" | |
| 24 | + android:layout_height="wrap_content" | |
| 25 | + android:layout_centerInParent="true" | |
| 26 | + android:text="评论" | |
| 27 | + /> | |
| 28 | + | |
| 18 | 29 | </RelativeLayout> | ... | ... |
app/src/main/res/layout/commet_item.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + android:layout_width="match_parent" | |
| 4 | + android:layout_height="wrap_content" | |
| 5 | + > | |
| 6 | + <TextView | |
| 7 | + android:id="@+id/nick_name" | |
| 8 | + android:text="游客" | |
| 9 | + android:layout_width="wrap_content" | |
| 10 | + android:layout_height="wrap_content" /> | |
| 11 | + | |
| 12 | + <TextView | |
| 13 | + android:layout_toRightOf="@+id/nick_name" | |
| 14 | + android:layout_toLeftOf="@+id/good_imv" | |
| 15 | + android:layout_marginLeft="5dp" | |
| 16 | + android:layout_marginRight="5dp" | |
| 17 | + android:id="@+id/comment_message" | |
| 18 | + android:text="我爱大中国" | |
| 19 | + android:layout_width="wrap_content" | |
| 20 | + android:layout_height="wrap_content" /> | |
| 21 | + | |
| 22 | + <ImageView android:id="@+id/good_imv" | |
| 23 | + | |
| 24 | + android:layout_width="24dp" | |
| 25 | + android:layout_height="24dp" | |
| 26 | + android:src="@drawable/vod_detail_good_off" | |
| 27 | + android:layout_toLeftOf="@+id/comment_good_count" | |
| 28 | + android:layout_marginLeft="5dp" | |
| 29 | + android:layout_centerVertical="true" | |
| 30 | + /> | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + <TextView | |
| 35 | + android:id="@+id/comment_good_count" | |
| 36 | + android:text="10" | |
| 37 | + android:layout_centerVertical="true" | |
| 38 | + android:layout_width="wrap_content" | |
| 39 | + android:layout_height="wrap_content" | |
| 40 | + android:layout_alignParentRight="true" | |
| 41 | + android:layout_marginLeft="5dp"/> | |
| 42 | + | |
| 43 | + | |
| 44 | +</RelativeLayout> | |
| 0 | 45 | \ No newline at end of file | ... | ... |