Commit 5eb0f41fa97ff83f8fa131d256b43fc643d6ae2f

Authored by 陈硕
1 parent 8b6a7deb

修改布局,添加修改逻辑

app/src/main/java/com/cnlive/im/ui/ChatItemActivity.java deleted 100644 → 0
1   -package com.cnlive.im.ui;
2   -
3   -import android.content.Intent;
4   -import android.os.Bundle;
5   -import android.support.annotation.Nullable;
6   -import android.support.v7.app.AppCompatActivity;
7   -import android.view.View;
8   -import android.widget.Button;
9   -
10   -import com.cnlive.im.R;
11   -
12   -
13   -/**
14   - * @author 陈硕
15   - * @time 2017/3/20 10:32
16   - * @desc ${TODD}
17   - */
18   -public class ChatItemActivity extends AppCompatActivity implements View.OnClickListener {
19   -
20   - private Button grounp_chat, private_chat;
21   - private String user_name_string;
22   - private String user_id_string;
23   -
24   - @Override
25   - protected void onCreate(@Nullable Bundle savedInstanceState) {
26   - super.onCreate(savedInstanceState);
27   - setContentView(R.layout.activity_chat_item);
28   - intUI();
29   -
30   - }
31   -
32   - private void intUI() {
33   - grounp_chat = (Button) findViewById(R.id.grounp_chat);
34   - private_chat = (Button) findViewById(R.id.private_chat);
35   - grounp_chat.setOnClickListener(this);
36   - private_chat.setOnClickListener(this);
37   - Intent intent = getIntent();
38   - user_name_string = intent.getStringExtra("user_name_string");
39   - user_id_string = intent.getStringExtra("user_id_string");
40   -
41   -
42   - }
43   -
44   - @Override
45   - public void onClick(View v) {
46   - switch (v.getId()) {
47   - case R.id.grounp_chat:
48   - doIntentChatRoom(ChatRoomActivity.class);
49   - break;
50   - case R.id.private_chat:
51   - doIntentChatRoom(PrivateChatActivity.class);
52   - break;
53   - }
54   - }
55   -
56   - private void doIntentChatRoom(Class classes) {
57   - Intent intent = new Intent();
58   - intent.setClass(this, classes);
59   - intent.putExtra("user_name_string",user_name_string);
60   - intent.putExtra("user_id_string",user_id_string);
61   - startActivity(intent);
62   - }
63   -}
app/src/main/java/com/cnlive/im/ui/ChatRoomActivity.java
... ... @@ -52,8 +52,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
52 52 private Button exit_chat1;
53 53 private Button chat_info_mationBtn;
54 54 public static String user_name_string;
55   - int i=0;
56   - private boolean isUserLogin=false;
  55 + int i = 0;
  56 + private boolean isUserLogin = false;
57 57  
58 58 @Override
59 59 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -70,9 +70,9 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
70 70 Intent intent = getIntent();
71 71 user_name_string = intent.getStringExtra("user_name_string");
72 72 String user_id_string = intent.getStringExtra("user_id_string");
73   - if (user_name_string != null) {
  73 + if (user_name_string != null)
74 74 ChatUtil.login(new CNUserInfo(user_id_string, user_name_string, ""), connectListener);
75   - }
  75 + else ChatUtil.logOut(connectListener);
76 76  
77 77 }
78 78  
... ... @@ -107,6 +107,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
107 107 public void onAttached(CNMessage cnMessage) {
108 108 Log.v(TAG, "SendMessageListener onAttached" + cnMessage.getTargetId() + cnMessage.getUserInfo().getUserName());
109 109 }
  110 +
110 111 @Override
111 112 public void onSuccess(final CNMessage cnMessage) {
112 113 mHandler.post(new Runnable() {
... ... @@ -128,6 +129,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
128 129 });
129 130  
130 131 }
  132 +
131 133 @Override
132 134 public void onError(CNMessage cnMessage, int i, final String s) {
133 135 Log.v(TAG, "SendMessageListener 失败 " + i + " s" + s);
... ... @@ -160,7 +162,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
160 162 JSONObject jsonObject = new JSONObject(cnMessage.getContent().toString());
161 163 String type = (String) jsonObject.get("type");
162 164 if ("2".equals(type)) {
163   - Toast.makeText(ChatRoomActivity.this, cnMessage.getUserInfo().getUserName()+"加入聊天室", Toast.LENGTH_SHORT).show();
  165 + Toast.makeText(ChatRoomActivity.this, cnMessage.getUserInfo().getUserName() + "加入聊天室", Toast.LENGTH_SHORT).show();
164 166 return;
165 167 }
166 168 } catch (JSONException e) {
... ... @@ -183,14 +185,17 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
183 185 public void onJoining(String s) {
184 186 Log.i(TAG, "chatRoomActionListener" + " onJoining" + s);
185 187 }
  188 +
186 189 @Override
187 190 public void onJoined(String s) {
188 191 Log.i(TAG, "chatRoomActionListener " + "onJoined" + s);
189 192 }
  193 +
190 194 @Override
191 195 public void onQuited(String s) {
192 196 Log.i(TAG, "chatRoomActionListener " + "onQuited" + s);
193 197 }
  198 +
194 199 @Override
195 200 public void onError(String s, int i, String s1) {
196 201 Log.i(TAG, "chatRoomActionListener " + "onError" + s);
... ... @@ -210,6 +215,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
210 215 }
211 216 });
212 217 }
  218 +
213 219 @Override
214 220 public void conByDevId(final int what, final String extra) {
215 221 Log.e(TAG, what + " : " + extra);
... ... @@ -232,7 +238,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
232 238 mHandler.post(new Runnable() {
233 239 @Override
234 240 public void run() {
235   - if(i==0){
  241 + if (i == 0) {
236 242 String objToJsonString = ToStringUtils.objToJsonString(new CNMessageModole(user_name_string + "加入聊天室", "2"));
237 243 ChatUtil.sendMessage(IChat.CHATROOM, roomIdOne, objToJsonString, sendMessageListener);
238 244 ++i;
... ... @@ -299,6 +305,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
299 305 public void onTokenIncorrect() {
300 306 Log.e(TAG, "ConnectListener TokenIncorrect");
301 307 Toast.makeText(ChatRoomActivity.this, "TokenIncorrect", Toast.LENGTH_SHORT).show();
  308 + finish();
302 309  
303 310 }
304 311  
... ... @@ -313,16 +320,12 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
313 320 public void onError(int i, String s) {
314 321 Log.e(TAG, "ConnectListener errorCode : " + i + " : errorMessage : " + s);
315 322 Toast.makeText(ChatRoomActivity.this, s, Toast.LENGTH_SHORT).show();
  323 + finish();
316 324  
317 325 }
318 326 };
319 327  
320 328  
321   -
322   -
323   -
324   -
325   -
326 329 public static class CNMessageInfo {
327 330 CNMessage cnMessage;
328 331 boolean sendMesageInfo;
... ...
app/src/main/java/com/cnlive/im/ui/LoGinActivity.java
... ... @@ -9,7 +9,6 @@ import android.widget.Button;
9 9  
10 10 import com.cnlive.im.R;
11 11 import com.cnlive.libs.util.chat.ChatUtil;
12   -import com.cnlive.libs.util.chat.base.IChat;
13 12  
14 13 /**
15 14 * @author 陈硕
... ... @@ -56,19 +55,4 @@ public class LoGinActivity extends AppCompatActivity implements View.OnClickList
56 55 }
57 56  
58 57  
59   - IChat.OnConnectListener connectListener = new IChat.OnConnectListener() {
60   - @Override
61   - public void onTokenIncorrect() {
62   - }
63   -
64   - @Override
65   - public void onSuccess(String s) {
66   - }
67   -
68   - @Override
69   - public void onError(int i, String s) {
70   -
71   - }
72   - };
73   -
74 58 }
... ...
app/src/main/java/com/cnlive/im/ui/PrivateChatActivity.java
... ... @@ -218,7 +218,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
218 218 Toast.makeText(PrivateChatActivity.this, "申请已发送等待对方验证", Toast.LENGTH_SHORT).show();
219 219 } else if ("3".equals(type) && message.equals("拒绝")) {
220 220 } else if ("3".equals(type) && message.equals("同意")) {
221   - } else if("4".equals(type)) {
  221 + } else if ("4".equals(type)) {
222 222 messageList.add(new ChatRoomActivity.CNMessageInfo(cnMessage, true));
223 223 chatListAdapter.updateItems(messageList);
224 224 chatListAdapter.notifyDataSetChanged();
... ... @@ -280,8 +280,8 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
280 280 sendInfo = 1;
281 281 } else if ("3".equals(type) && "拒绝".equals(jsonObject.get("message"))) {
282 282 sendInfo = 4;
283   - }else if("4".equals(type) ){
284   - Log.v(TAG,cnMessage.getContent().toString());
  283 + } else if ("4".equals(type)) {
  284 + Log.v(TAG, cnMessage.getContent().toString());
285 285 messageList.add(new ChatRoomActivity.CNMessageInfo(cnMessage, false));
286 286 chatListAdapter.updateItems(messageList);
287 287 chatListAdapter.notifyDataSetChanged();
... ...
app/src/main/java/com/cnlive/im/ui/UserLoginActivity.java
... ... @@ -17,11 +17,13 @@ import com.cnlive.im.R;
17 17 * @time 2017/3/16 18:29
18 18 * @desc ${TODD}
19 19 */
20   -public class UserLoginActivity extends AppCompatActivity implements View.OnClickListener {
  20 +public class UserLoginActivity extends AppCompatActivity implements View.OnClickListener {
21 21  
22 22 private EditText user_name;
23 23 private EditText user_id;
24   - private Button userBtn;
  24 + private Button group_chatBtn, private_chatBtn;
  25 + private String user_name_string;
  26 + private String user_id_string;
25 27  
26 28 @Override
27 29 protected void onCreate(@Nullable Bundle savedInstanceState) {
... ... @@ -34,24 +36,44 @@ public class UserLoginActivity extends AppCompatActivity implements View.OnCli
34 36 private void intUI() {
35 37 user_name = (EditText) findViewById(R.id.user_name);
36 38 user_id = (EditText) findViewById(R.id.user_ID);
37   - userBtn = (Button) findViewById(R.id.uconnect);
38   - userBtn.setOnClickListener(this);
  39 + group_chatBtn = (Button) findViewById(R.id.group_chat);
  40 + group_chatBtn.setOnClickListener(this);
  41 + private_chatBtn = (Button) findViewById(R.id.private_chat);
  42 + private_chatBtn.setOnClickListener(this);
39 43 }
40 44  
41 45  
42 46 @Override
43 47 public void onClick(View v) {
44   - if(user_id.getText().toString().isEmpty()){
45   - Toast.makeText(UserLoginActivity.this,"id不能为空",Toast.LENGTH_SHORT).show();
46   - }else if(user_name.getText().toString().isEmpty()){
47   - Toast.makeText(UserLoginActivity.this,"用户名不能为空",Toast.LENGTH_SHORT).show();
48   - }else {
49   - String user_name_string = user_name.getText().toString();
50   - String user_id_string = user_id.getText().toString();
51   - Intent intent = new Intent(UserLoginActivity.this, ChatItemActivity.class);
52   - intent.putExtra("user_name_string",user_name_string);
53   - intent.putExtra("user_id_string",user_id_string);
  48 + switch (v.getId()) {
  49 + case R.id.group_chat:
  50 + doIntentChatRoom(ChatRoomActivity.class);
  51 + break;
  52 + case R.id.private_chat:
  53 + doIntentChatRoom(PrivateChatActivity.class);
  54 +
  55 + break;
  56 + }
  57 +
  58 + }
  59 +
  60 +
  61 + private void doIntentChatRoom(Class classes) {
  62 + if (user_id.getText().toString().isEmpty()) {
  63 + Toast.makeText(UserLoginActivity.this, "id不能为空", Toast.LENGTH_SHORT).show();
  64 + } else if (user_name.getText().toString().isEmpty()) {
  65 + Toast.makeText(UserLoginActivity.this, "用户名不能为空", Toast.LENGTH_SHORT).show();
  66 + } else {
  67 + user_name_string = user_name.getText().toString();
  68 + user_id_string = user_id.getText().toString();
  69 + Intent intent = new Intent();
  70 + intent.setClass(this, classes);
  71 + intent.putExtra("user_name_string", user_name_string);
  72 + intent.putExtra("user_id_string", user_id_string);
54 73 startActivity(intent);
55 74 }
  75 +
  76 +
56 77 }
  78 +
57 79 }
... ...
app/src/main/res/layout/activity_user.xml
... ... @@ -4,10 +4,13 @@
4 4 android:layout_height="match_parent">
5 5  
6 6 <LinearLayout
  7 + android:id="@+id/linearLayout"
7 8 android:layout_width="match_parent"
8 9 android:layout_height="wrap_content"
9   - android:layout_centerInParent="true"
10   - android:orientation="vertical">
  10 + android:orientation="vertical"
  11 + android:layout_centerVertical="true"
  12 + android:layout_alignParentLeft="true"
  13 + android:layout_alignParentStart="true">
11 14  
12 15 <LinearLayout
13 16 android:layout_width="match_parent"
... ... @@ -44,11 +47,38 @@
44 47 android:layout_weight="1" />
45 48 </LinearLayout>
46 49  
47   - <Button
48   - android:id="@+id/uconnect"
49   - android:layout_width="match_parent"
  50 +
  51 +
  52 + <RelativeLayout
  53 + android:layout_width="wrap_content"
50 54 android:layout_height="wrap_content"
51   - android:text="连接" />
  55 + android:orientation="horizontal">
  56 +
  57 + <Button
  58 + android:id="@+id/group_chat"
  59 + android:layout_width="wrap_content"
  60 + android:layout_height="wrap_content"
  61 + android:text="群聊"
  62 + android:layout_alignParentTop="true"
  63 + android:layout_alignParentLeft="true"
  64 + android:layout_alignParentStart="true"
  65 + android:layout_marginLeft="60dp"
  66 + android:layout_marginStart="60dp" />
  67 +
  68 + <Button
  69 + android:id="@+id/private_chat"
  70 + android:layout_width="wrap_content"
  71 + android:layout_height="wrap_content"
  72 + android:text="私聊"
  73 + android:layout_marginRight="65dp"
  74 + android:layout_marginEnd="65dp"
  75 + android:layout_alignParentTop="true"
  76 + android:layout_alignParentRight="true"
  77 + android:layout_alignParentEnd="true" />
  78 +
  79 + </RelativeLayout>
  80 +
  81 +
52 82 </LinearLayout>
53 83  
54 84  
... ...