Commit be545209c06a353f3e06594ff5b8621a79acf6e6
1 parent
781b4848
修改方法
Showing
2 changed files
with
20 additions
and
11 deletions
app/src/main/java/com/cnlive/im/ui/ChatRoomActivity.java
| @@ -44,6 +44,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | @@ -44,6 +44,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | ||
| 44 | private Button user_imfor_send; | 44 | private Button user_imfor_send; |
| 45 | private EditText user_id, user_name; | 45 | private EditText user_id, user_name; |
| 46 | private CNUserInfo cnUser; | 46 | private CNUserInfo cnUser; |
| 47 | + private Button exit_chat2; | ||
| 48 | + private Button exit_chat1; | ||
| 47 | 49 | ||
| 48 | 50 | ||
| 49 | @Override | 51 | @Override |
| @@ -62,6 +64,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | @@ -62,6 +64,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | ||
| 62 | 64 | ||
| 63 | 65 | ||
| 64 | private void initUI() { | 66 | private void initUI() { |
| 67 | + exit_chat2 = (Button) findViewById(R.id.exit_chat2); | ||
| 68 | + exit_chat1 = (Button) findViewById(R.id.exit_chat1); | ||
| 65 | user_id = (EditText) findViewById(R.id.user_ID); | 69 | user_id = (EditText) findViewById(R.id.user_ID); |
| 66 | user_name = (EditText) findViewById(R.id.user_name); | 70 | user_name = (EditText) findViewById(R.id.user_name); |
| 67 | user_imfor_send = (Button) findViewById(R.id.user_imfor_send); | 71 | user_imfor_send = (Button) findViewById(R.id.user_imfor_send); |
| @@ -78,6 +82,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | @@ -78,6 +82,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | ||
| 78 | editText = (EditText) findViewById(R.id.message_content); | 82 | editText = (EditText) findViewById(R.id.message_content); |
| 79 | send_messageOneBtn = (Button) findViewById(R.id.send_messageOne); | 83 | send_messageOneBtn = (Button) findViewById(R.id.send_messageOne); |
| 80 | send_messageOneTwo = (Button) findViewById(R.id.send_messageTwo); | 84 | send_messageOneTwo = (Button) findViewById(R.id.send_messageTwo); |
| 85 | + exit_chat1.setOnClickListener(this); | ||
| 86 | + exit_chat2.setOnClickListener(this); | ||
| 81 | user_imfor_send.setOnClickListener(this); | 87 | user_imfor_send.setOnClickListener(this); |
| 82 | disconnectBtn.setOnClickListener(this); | 88 | disconnectBtn.setOnClickListener(this); |
| 83 | foundChatBtn.setOnClickListener(this); | 89 | foundChatBtn.setOnClickListener(this); |
| @@ -262,12 +268,12 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | @@ -262,12 +268,12 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | ||
| 262 | // 加入聊天室监听 | 268 | // 加入聊天室监听 |
| 263 | private IChat.OnOperationListener onOperationListener = new IChat.OnOperationListener() { | 269 | private IChat.OnOperationListener onOperationListener = new IChat.OnOperationListener() { |
| 264 | @Override | 270 | @Override |
| 265 | - public void onSuccess(int what, String extra) { | ||
| 266 | - Log.v(TAG, "加入聊天室" + what + extra); | 271 | + public void onSuccess(int what, final String extra) { |
| 272 | + Log.v(TAG, + what + extra); | ||
| 267 | mHandler.post(new Runnable() { | 273 | mHandler.post(new Runnable() { |
| 268 | @Override | 274 | @Override |
| 269 | public void run() { | 275 | public void run() { |
| 270 | - Toast.makeText(ChatRoomActivity.this, "加入聊天室成功", Toast.LENGTH_SHORT).show(); | 276 | + Toast.makeText(ChatRoomActivity.this, extra, Toast.LENGTH_SHORT).show(); |
| 271 | 277 | ||
| 272 | } | 278 | } |
| 273 | }); | 279 | }); |
| @@ -332,11 +338,19 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | @@ -332,11 +338,19 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | ||
| 332 | ChatUtil.joinChatRoom(roomIdTwo, -1, onOperationListener); | 338 | ChatUtil.joinChatRoom(roomIdTwo, -1, onOperationListener); |
| 333 | break; | 339 | break; |
| 334 | 340 | ||
| 341 | + case R.id.exit_chat2: | ||
| 342 | + ChatUtil.quitChatRoom(roomIdTwo, onOperationListener); | ||
| 343 | + break; | ||
| 344 | + | ||
| 345 | + case R.id.exit_chat1: | ||
| 346 | + ChatUtil.quitChatRoom(roomIdOne, onOperationListener); | ||
| 347 | + break; | ||
| 348 | + | ||
| 335 | 349 | ||
| 336 | case R.id.user_imfor_send: | 350 | case R.id.user_imfor_send: |
| 337 | if (user_id.getText().toString().isEmpty()) | 351 | if (user_id.getText().toString().isEmpty()) |
| 338 | Toast.makeText(ChatRoomActivity.this, "用户id不能为空", Toast.LENGTH_SHORT).show(); | 352 | Toast.makeText(ChatRoomActivity.this, "用户id不能为空", Toast.LENGTH_SHORT).show(); |
| 339 | - else if (user_name.getText().toString().isEmpty()) | 353 | + else if (user_name.getText().toString().isEmpty()) |
| 340 | Toast.makeText(ChatRoomActivity.this, "用户名不能为空", Toast.LENGTH_SHORT).show(); | 354 | Toast.makeText(ChatRoomActivity.this, "用户名不能为空", Toast.LENGTH_SHORT).show(); |
| 341 | else { | 355 | else { |
| 342 | cnUser = new CNUserInfo(user_id.getText().toString(), user_name.getText().toString(), ""); | 356 | cnUser = new CNUserInfo(user_id.getText().toString(), user_name.getText().toString(), ""); |
| @@ -349,11 +363,11 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | @@ -349,11 +363,11 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL | ||
| 349 | } | 363 | } |
| 350 | } | 364 | } |
| 351 | 365 | ||
| 352 | - | ||
| 353 | @Override | 366 | @Override |
| 354 | protected void onPause() { | 367 | protected void onPause() { |
| 355 | super.onPause(); | 368 | super.onPause(); |
| 356 | - ChatUtil.disconnect(false); | 369 | + ChatUtil.quitChatRoom(roomIdTwo, onOperationListener); |
| 370 | + ChatUtil.quitChatRoom(roomIdOne, onOperationListener); | ||
| 357 | } | 371 | } |
| 358 | 372 | ||
| 359 | 373 |
app/src/main/java/com/cnlive/im/ui/PrivateChatActivity.java
| @@ -207,12 +207,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli | @@ -207,12 +207,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli | ||
| 207 | }; | 207 | }; |
| 208 | 208 | ||
| 209 | 209 | ||
| 210 | - @Override | ||
| 211 | - protected void onPause() { | ||
| 212 | - super.onPause(); | ||
| 213 | - ChatUtil.disconnect(false); | ||
| 214 | 210 | ||
| 215 | - } | ||
| 216 | 211 | ||
| 217 | 212 | ||
| 218 | } | 213 | } |