Commit 5ec5c5f44cec511a5b40521a897ed29265087830

Authored by 陈硕
1 parent 0b6ad818

修改逻辑,修改布局

app/src/main/java/com/cnlive/im/ui/ChatItemActivity.java
... ... @@ -49,7 +49,7 @@ public class ChatItemActivity extends AppCompatActivity implements View.OnClickL
49 49 doIntentChatRoom(ChatRoomActivity.class);
50 50 break;
51 51 case R.id.private_chat:
52   - doIntentPriRoom(PrivateChatActivity.class);
  52 + doIntentChatRoom(PrivateChatActivity.class);
53 53 break;
54 54 }
55 55 }
... ... @@ -61,10 +61,4 @@ public class ChatItemActivity extends AppCompatActivity implements View.OnClickL
61 61 intent.putExtra("user_id_string",user_id_string);
62 62 startActivity(intent);
63 63 }
64   -
65   - private void doIntentPriRoom(Class classes) {
66   - Intent intent = new Intent();
67   - intent.setClass(this, classes);
68   - startActivity(intent);
69   - }
70 64 }
... ...
app/src/main/java/com/cnlive/im/ui/ChatRoomActivity.java
... ... @@ -65,6 +65,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
65 65 String user_id_string = intent.getStringExtra("user_id_string");
66 66 if(user_name_string!=null){
67 67 ChatUtil.login(new CNUserInfo(user_id_string,user_name_string,""),connectListener);
  68 + }else {
  69 + ChatUtil.logOut(connectListener);
68 70 }
69 71 }
70 72  
... ... @@ -117,7 +119,6 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
117 119 mHandler.post(new Runnable() {
118 120 @Override
119 121 public void run() {
120   - Toast.makeText(ChatRoomActivity.this, "发送成功", Toast.LENGTH_SHORT).show();
121 122 if ((roomIdOne).equals(cnMessage.getTargetId())) {
122 123 groupChatOneListMy.add(cnMessage);
123 124 chatListAdapterOne.updateItems(groupChatOneListMy);
... ...
app/src/main/java/com/cnlive/im/ui/PrivateChatActivity.java
... ... @@ -48,6 +48,12 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
48 48 private EditText opposite_name_edit;
49 49 private String user_name_string;
50 50 private String user_id_string;
  51 + private int sendInfo = 1;
  52 + private Button agree_btn;
  53 + private Button reject_btn;
  54 + private LinearLayout agree_reject_lin;
  55 + boolean isCanSendMeaasge = false;
  56 + private Button vistor_btn;
51 57  
52 58 @Override
53 59 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -57,7 +63,6 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
57 63 mHandler = new Handler();
58 64 ChatUtil.setConnectStatusListener(connectStatusListener);
59 65 ChatUtil.setOnReceiveMessageListener(receiveMessageListener);
60   -
61 66 }
62 67  
63 68 private void initView() {
... ... @@ -76,20 +81,40 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
76 81 Intent intent = getIntent();
77 82 user_name_string = intent.getStringExtra("user_name_string");
78 83 user_id_string = intent.getStringExtra("user_id_string");
  84 + agree_btn = (Button) findViewById(R.id.agree_btn);
  85 + reject_btn = (Button) findViewById(R.id.reject_btn);
  86 + agree_btn.setOnClickListener(this);
  87 + reject_btn.setOnClickListener(this);
  88 + agree_reject_lin = (LinearLayout) findViewById(R.id.agree_reject_lin);
  89 + vistor_btn = (Button) findViewById(R.id.vistor_Btn);
  90 + vistor_btn.setOnClickListener(this);
79 91 }
80 92  
81 93  
82 94 @Override
83 95 public void onClick(View v) {
  96 +
84 97 switch (v.getId()) {
85 98 case R.id.send_message:
86 99 //发送私聊消息,需要传入目标ID与发送的消息内容
87   - if (messageContent.getText().toString().isEmpty()) {
88   - Toast.makeText(this, "不能发送空消息呦~", Toast.LENGTH_SHORT).show();
  100 + if (sendInfo == 2) {
  101 + Toast.makeText(this, "等待对方接受邀请", Toast.LENGTH_SHORT).show();
  102 +
  103 + } else if (sendInfo == 4) {
  104 + Toast.makeText(this, "对方已经拒绝不能发送", Toast.LENGTH_SHORT).show();
  105 +
89 106 } else {
90   - ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, messageContent.getText().toString(), sendMessageListener);
91   - messageContent.setText("");
  107 +
  108 + if (messageContent.getText().toString().isEmpty()) {
  109 + Toast.makeText(this, "不能发送空消息呦~", Toast.LENGTH_SHORT).show();
  110 + } else {
  111 + ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, messageContent.getText().toString(), sendMessageListener);
  112 + messageContent.setText("");
  113 + }
  114 +
  115 +
92 116 }
  117 +
93 118 break;
94 119 case R.id.userId_btn_top:
95 120 //发送私聊消息,需要传入目标ID与发送的消息内容
... ... @@ -98,16 +123,31 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
98 123 } else if (opposite_name_edit.getText().toString().isEmpty()) {
99 124 Toast.makeText(this, "对方name不能为空", Toast.LENGTH_SHORT).show();
100 125 } else {
101   - user_id_edit.getText().toString();
  126 +
102 127 oppositeID = user_id_edit.getText().toString();
103 128 linearLayoutUseID.setVisibility(View.INVISIBLE);
104 129 edit_layout.setVisibility(View.VISIBLE);
105 130 chatListView.setVisibility(View.VISIBLE);
106 131 CNUserInfo cnName = new CNUserInfo(user_id_string, user_name_string, "");
107 132 ChatUtil.login(cnName, connectListener);
  133 +
108 134 }
109 135  
110 136 break;
  137 +
  138 + case R.id.agree_btn:
  139 + ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, "同意", sendMessageListener);
  140 + agree_reject_lin.setVisibility(View.GONE);
  141 + break;
  142 +
  143 + case R.id.reject_btn:
  144 + ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, "拒绝", sendMessageListener);
  145 + agree_reject_lin.setVisibility(View.GONE);
  146 + break;
  147 + case R.id.vistor_Btn:
  148 + ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, "你好我们可以进行私聊吗", sendMessageListener);
  149 +
  150 + break;
111 151 }
112 152 }
113 153  
... ... @@ -118,6 +158,30 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
118 158 public void onTokenIncorrect() {
119 159 Log.e(TAG, "ConnectListener TokenIncorrect");
120 160 Toast.makeText(PrivateChatActivity.this, "TokenIncorrect", Toast.LENGTH_SHORT).show();
  161 + ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, "你好我们可以进行私聊吗", sendMessageListener);
  162 + }
  163 +
  164 + @Override
  165 + public void onSuccess(String s) {
  166 + Log.e(TAG, "ConnectListener 连接监听" + s);
  167 + Toast.makeText(PrivateChatActivity.this, s, Toast.LENGTH_SHORT).show();
  168 +
  169 + }
  170 +
  171 + @Override
  172 + public void onError(int i, String s) {
  173 + Log.e(TAG, "ConnectListener errorCode : " + i + " : errorMessage : " + s);
  174 + Toast.makeText(PrivateChatActivity.this, s, Toast.LENGTH_SHORT).show();
  175 +
  176 + }
  177 + };
  178 +
  179 +
  180 + private IChat.OnConnectListener connectListener1 = new IChat.OnConnectListener() {
  181 + @Override
  182 + public void onTokenIncorrect() {
  183 + Log.e(TAG, "ConnectListener TokenIncorrect");
  184 + Toast.makeText(PrivateChatActivity.this, "TokenIncorrect", Toast.LENGTH_SHORT).show();
121 185  
122 186 }
123 187  
... ... @@ -148,14 +212,25 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
148 212  
149 213 @Override
150 214 public void onSuccess(final CNMessage cnMessage) {
  215 +
  216 + if(View.VISIBLE==vistor_btn.getVisibility()){
  217 + vistor_btn.setVisibility(View.GONE);
  218 + }
151 219 mHandler.post(new Runnable() {
152 220 @Override
153 221 public void run() {
154 222 Toast.makeText(PrivateChatActivity.this, "发送消息成功", Toast.LENGTH_SHORT).show();
  223 + if (messageList.size() == 0 && cnMessage.getContent().equals("你好我们可以进行私聊吗")) {
  224 + sendInfo = 2;
  225 + Toast.makeText(PrivateChatActivity.this, "申请已发送等待对方验证", Toast.LENGTH_SHORT).show();
  226 + } else if (messageList.size() == 0 && cnMessage.getContent().equals("拒绝")) {
  227 + } else if (messageList.size() == 0 && cnMessage.getContent().equals("同意")) {
  228 + } else {
  229 + messageList.add(cnMessage);
  230 + chatListAdapter.updateItems(messageList);
  231 + chatListAdapter.notifyDataSetChanged();
  232 + }
155 233  
156   - messageList.add(cnMessage);
157   - chatListAdapter.updateItems(messageList);
158   - chatListAdapter.notifyDataSetChanged();
159 234 }
160 235 });
161 236  
... ... @@ -171,7 +246,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
171 246 @Override
172 247 public void run() {
173 248 Toast.makeText(PrivateChatActivity.this, "发送消息失败", Toast.LENGTH_SHORT).show();
174   -
  249 + vistor_btn.setText("重新邀请");
175 250  
176 251 }
177 252 });
... ... @@ -188,7 +263,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
188 263  
189 264 }
190 265 };
191   -
  266 + private boolean isvistor = false;
192 267 //接收消息监听
193 268 private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() {
194 269 @Override
... ... @@ -197,11 +272,25 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
197 272 mHandler.post(new Runnable() {
198 273 @Override
199 274 public void run() {
200   - messageList.add(cnMessage);
201   - chatListAdapter.updateItems(messageList);
202   - chatListAdapter.notifyDataSetChanged();
  275 + vistor_btn.setVisibility(View.GONE);
  276 + if (messageList.size() == 0 && cnMessage.getContent().equals("你好我们可以进行私聊吗")) {
  277 + agree_reject_lin.setVisibility(View.VISIBLE);
  278 + } else if (messageList.size() == 0 && cnMessage.getContent().equals("拒绝")) {
  279 + sendInfo = 4;
  280 + Toast.makeText(PrivateChatActivity.this, "对方已经决绝了您", Toast.LENGTH_SHORT).show();
  281 + } else if (messageList.size() == 0 && cnMessage.getContent().equals("同意")) {
  282 + Toast.makeText(PrivateChatActivity.this, "对方已经同意了您", Toast.LENGTH_SHORT).show();
  283 + sendInfo = 5;
  284 + } else {
  285 + messageList.add(cnMessage);
  286 + chatListAdapter.updateItems(messageList);
  287 + chatListAdapter.notifyDataSetChanged();
  288 + }
  289 +
  290 +
203 291 }
204 292 });
  293 +
205 294 }
206 295 };
207 296 }
... ...
app/src/main/res/drawable/slel_back.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<shape xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <solid android:color="#55000000" />
  4 + <corners android:topLeftRadius="10dp"
  5 + android:topRightRadius="10dp"
  6 + android:bottomRightRadius="10dp"
  7 + android:bottomLeftRadius="10dp"
  8 +
  9 + />
  10 +
  11 +</shape>
0 12 \ No newline at end of file
... ...
app/src/main/res/layout/activity_lin_top.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="match_parent"
  5 + android:orientation="vertical">
  6 +
  7 + <Button
  8 + android:id="@+id/button"
  9 + android:layout_width="wrap_content"
  10 + android:layout_height="wrap_content"
  11 + android:text="Button" />
  12 +
  13 + <Button
  14 + android:id="@+id/button2"
  15 + android:layout_width="wrap_content"
  16 + android:layout_height="wrap_content"
  17 + android:text="Button"
  18 + android:layout_marginRight="41dp"
  19 + android:layout_marginEnd="41dp"
  20 + android:layout_alignParentTop="true"
  21 + android:layout_alignParentRight="true"
  22 + android:layout_alignParentEnd="true" />
  23 +</RelativeLayout>
0 24 \ No newline at end of file
... ...
app/src/main/res/layout/activity_private_chat.xml
... ... @@ -4,88 +4,159 @@
4 4 android:layout_width="match_parent"
5 5 android:layout_height="match_parent">
6 6  
7   - <ListView
8   - android:id="@+id/private_list_view"
  7 + <LinearLayout
9 8 android:layout_width="match_parent"
10   - android:layout_height="300dp"
11   - android:divider="@null"
12   - android:scrollbars="none"
13   - android:transcriptMode="alwaysScroll"
14   - android:visibility="invisible" />
  9 + android:layout_height="wrap_content"
  10 + android:orientation="vertical">
  11 +
  12 +
  13 + <ListView
  14 + android:id="@+id/private_list_view"
  15 + android:layout_width="match_parent"
  16 + android:layout_height="300dp"
  17 + android:divider="@null"
  18 + android:scrollbars="none"
  19 + android:transcriptMode="alwaysScroll"
  20 + android:visibility="invisible" />
  21 + </LinearLayout>
15 22  
16 23 <LinearLayout
17 24 android:id="@+id/edit_layout"
18 25 android:layout_width="match_parent"
19 26 android:layout_height="wrap_content"
20 27 android:layout_alignParentBottom="true"
21   - android:orientation="horizontal"
  28 + android:orientation="vertical"
22 29 android:visibility="invisible">
23 30  
24   - <EditText
25   - android:id="@+id/message_content"
26   - android:layout_width="0dp"
27   - android:layout_height="wrap_content"
28   - android:layout_gravity="center"
29   - android:layout_weight="0.7" />
30 31  
31 32 <Button
32   - android:id="@+id/send_message"
33   - android:layout_width="0dp"
  33 + android:id="@+id/vistor_Btn"
  34 + android:layout_width="wrap_content"
34 35 android:layout_height="wrap_content"
35   - android:layout_gravity="center"
36   - android:layout_weight="0.2"
37   - android:text="发送" />
38   - </LinearLayout>
  36 + android:text="邀请对方聊天" />
  37 +
  38 +
  39 + <LinearLayout
  40 + android:layout_width="match_parent"
  41 + android:layout_height="wrap_content"
  42 + android:orientation="horizontal">
  43 +
  44 + <EditText
  45 + android:id="@+id/message_content"
  46 + android:layout_width="0dp"
  47 + android:layout_height="wrap_content"
  48 + android:layout_gravity="center"
  49 + android:layout_weight="0.7" />
39 50  
  51 + <Button
  52 + android:id="@+id/send_message"
  53 + android:layout_width="0dp"
  54 + android:layout_height="wrap_content"
  55 + android:layout_gravity="center"
  56 + android:layout_weight="0.2"
  57 + android:text="发送" />
  58 + </LinearLayout>
40 59  
  60 + </LinearLayout>
41 61  
42 62  
43 63 <LinearLayout
44 64 android:id="@+id/opposite_liner_useID"
45 65 android:layout_width="match_parent"
46 66 android:layout_height="wrap_content"
47   - android:layout_centerInParent="true"
48   - android:orientation="horizontal">
  67 + android:layout_alignParentLeft="true"
  68 + android:layout_alignParentStart="true"
  69 + android:layout_centerVertical="true"
  70 + android:orientation="vertical">
49 71  
50   - <TextView
51   - android:layout_width="wrap_content"
  72 + <LinearLayout
  73 + android:layout_width="match_parent"
52 74 android:layout_height="wrap_content"
53   - android:layout_gravity="center"
54   - android:gravity="center"
55   - android:text="对方id :"
56   - android:textSize="22dp"
57   - android:textStyle="bold" />
58   -
59   - <EditText
60   - android:id="@+id/opposite_id_edit"
61   - android:layout_width="0dp"
  75 + android:orientation="horizontal">
  76 +
  77 +
  78 + <TextView
  79 + android:layout_width="wrap_content"
  80 + android:layout_height="wrap_content"
  81 + android:layout_gravity="center"
  82 + android:gravity="center"
  83 + android:text="对方id :"
  84 + android:textSize="22dp"
  85 + android:textStyle="bold" />
  86 +
  87 + <EditText
  88 + android:id="@+id/opposite_id_edit"
  89 + android:layout_width="0dp"
  90 + android:layout_height="wrap_content"
  91 + android:layout_gravity="center"
  92 + android:layout_weight="1" />
  93 + </LinearLayout>
  94 +
  95 + <LinearLayout
  96 + android:layout_width="match_parent"
  97 + android:layout_height="wrap_content">
  98 +
  99 + <TextView
  100 + android:layout_width="wrap_content"
  101 + android:layout_height="wrap_content"
  102 + android:layout_gravity="center"
  103 + android:gravity="center"
  104 + android:text="name:"
  105 + android:textSize="22dp"
  106 + android:textStyle="bold" />
  107 +
  108 + <EditText
  109 + android:id="@+id/opposite_name_edit"
  110 + android:layout_width="0dp"
  111 + android:layout_height="wrap_content"
  112 + android:layout_gravity="center"
  113 + android:layout_weight="1" />
  114 +
  115 + </LinearLayout>
  116 +
  117 +
  118 + <Button
  119 + android:id="@+id/userId_btn_top"
  120 + android:layout_width="match_parent"
62 121 android:layout_height="wrap_content"
63 122 android:layout_gravity="center"
64   - android:layout_weight="1" />
  123 + android:text="确定" />
  124 + </LinearLayout>
  125 +
  126 + <LinearLayout
  127 + android:id="@+id/agree_reject_lin"
  128 + android:layout_width="wrap_content"
  129 + android:layout_height="wrap_content"
  130 + android:layout_centerInParent="true"
  131 + android:background="@drawable/slel_back"
  132 + android:orientation="vertical"
  133 + android:visibility="invisible">
  134 +
65 135 <TextView
66   - android:layout_width="wrap_content"
67   - android:layout_height="wrap_content"
68   - android:layout_gravity="center"
69   - android:gravity="center"
70   - android:text="name:"
71   - android:textSize="22dp"
72   - android:textStyle="bold" />
73   - <EditText
74   - android:id="@+id/opposite_name_edit"
75   - android:layout_width="0dp"
  136 + android:layout_width="match_parent"
76 137 android:layout_height="wrap_content"
77   - android:layout_gravity="center"
78   - android:layout_weight="1"/>
  138 + android:text="有人请求和您进行私聊"
  139 + android:gravity="center"/>
79 140  
80   - <Button
81   - android:id="@+id/userId_btn_top"
  141 + <LinearLayout
82 142 android:layout_width="wrap_content"
83   - android:layout_height="wrap_content"
84   - android:layout_gravity="center"
85   - android:text="完成" />
  143 + android:layout_height="wrap_content">
86 144  
87   - </LinearLayout>
  145 + <Button
  146 + android:id="@+id/agree_btn"
  147 + android:background="#00000000"
  148 + android:layout_width="wrap_content"
  149 + android:layout_height="wrap_content"
  150 + android:text="同意" />
88 151  
  152 + <Button
  153 + android:id="@+id/reject_btn"
  154 + android:background="#00000000"
  155 + android:layout_width="wrap_content"
  156 + android:layout_height="wrap_content"
  157 + android:text="拒绝" />
  158 + </LinearLayout>
89 159  
  160 + </LinearLayout>
90 161  
91 162 </RelativeLayout>
... ...