Commit 0b036bf6e9bc25d6f3c5b78c83931398c5981bc4

Authored by 谷俊
2 parents dcb12a4f 67043045

Merge branch 'master' of bj.gitlab.cnlive.com:cnlive-team/CNLiveApp

app/src/main/java/com/cnlive/gundam/stream/ui/activity/StreamActivity.java
... ... @@ -27,6 +27,7 @@ import com.cnlive.gundam.stream.model.ShowView;
27 27 import com.cnlive.gundam.stream.ui.adapter.SimpleAdapter;
28 28 import com.cnlive.gundam.stream.util.ChatConnect;
29 29 import com.cnlive.gundam.stream.util.TimerUtil;
  30 +import com.cnlive.gundam.video.model.CNMessageModle;
30 31 import com.cnlive.libs.stream.base.IStreamer;
31 32 import com.cnlive.libs.stream.model.ActivityConfig;
32 33 import com.cnlive.libs.stream.model.Filters;
... ... @@ -37,9 +38,6 @@ import com.cnlive.libs.util.chat.model.CNMessage;
37 38 import com.cnlive.libs.util.chat.model.CNUserInfo;
38 39 import com.google.gson.Gson;
39 40  
40   -import org.json.JSONException;
41   -import org.json.JSONObject;
42   -
43 41 import java.util.ArrayList;
44 42 import java.util.List;
45 43  
... ... @@ -104,7 +102,6 @@ public class StreamActivity extends BaseStreamActivity implements ChatConnect.Ch
104 102 binding.setIsShow(showView);
105 103 binding.chatRecyclerView.setLayoutManager(new LinearLayoutManager(this));
106 104 chatItemList = new ArrayList<>();
107   -
108 105 timerUtil = new TimerUtil(this);
109 106 }
110 107  
... ... @@ -118,7 +115,7 @@ public class StreamActivity extends BaseStreamActivity implements ChatConnect.Ch
118 115 ExtensionModel extensionModel = new ExtensionModel(channelName, coverImgUrl);
119 116 extensions = new Gson().toJson(extensionModel);
120 117  
121   - roomId = activityId;
  118 + roomId = channelId;
122 119 }
123 120  
124 121 public void onClick(View view) {
... ... @@ -390,24 +387,29 @@ public class StreamActivity extends BaseStreamActivity implements ChatConnect.Ch
390 387 @Override
391 388 public void onChatState(int what) {
392 389  
  390 +
393 391 }
394 392  
395 393 @Override
396 394 public void onChatMessage(CNMessage cnMessage) {
397   - //// TODO: 5/23/2017 Recyclerview添加数据
398   - String headUrl = cnMessage.getUserInfo().getHeadUrl() == null ? "" : cnMessage.getUserInfo().getHeadUrl();
399   - String userName = cnMessage.getUserInfo().getUserName() == null ? "" : cnMessage.getUserInfo().getUserName();
400   - String content = null;
401 395 try {
402   - content = cnMessage.getContent() == null ? "" : (String) new JSONObject(cnMessage.getContent()).get("message");
403   - } catch (JSONException e) {
  396 + Gson gson = new Gson();
  397 + CNMessageModle cnMessageModle = gson.fromJson(cnMessage.getContent(), CNMessageModle.class);
  398 + String messagecontent = cnMessageModle.getMessage().getContent();
  399 + String messageType = cnMessageModle.getType();
  400 + if (messageType.equals("giftType")) {
  401 + chatItemList.add(new ChatItem(cnMessage.getUserInfo().getHeadUrl(), cnMessage.getUserInfo().getUserName(), "送了" + messagecontent));
  402 + } else if (messageType.equals("chatRoom")) {
  403 + chatItemList.add(new ChatItem(cnMessage.getUserInfo().getHeadUrl(), cnMessage.getUserInfo().getUserName(), messagecontent));
  404 +
  405 + } else if (messageType.equals("joinType")) {
  406 + chatItemList.add(new ChatItem(cnMessage.getUserInfo().getHeadUrl(), cnMessage.getUserInfo().getUserName(), "加入"));
  407 + }
  408 + } catch (Exception e) {
404 409 e.printStackTrace();
405 410 }
406   - ChatItem chatItem = new ChatItem(headUrl, userName, content);
407   - chatItemList.add(chatItem);
408 411 chatAdapter = new SimpleAdapter(this, chatItemList, R.layout.item_chat, com.cnlive.gundam.BR.chat);
409 412 binding.setChatAdapter(chatAdapter);
410   -
411 413 }
412 414  
413 415 private void getOnlinePerson() {
... ...
app/src/main/java/com/cnlive/gundam/video/fragment/PlayerLiveFragment.java
... ... @@ -50,7 +50,8 @@ public class PlayerLiveFragment extends Fragment implements PlayerAccelerometerS
50 50 @Override
51 51 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
52 52 binding = DataBindingUtil.inflate(inflater, R.layout.fragment_player_live, container, false);
53   - getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.contentLayout, ChatRoomFragment.newInstance(), "chatRoomFragment").commit();
  53 + program = (VideoListProgram) getArguments().getSerializable("program");
  54 + getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.contentLayout, ChatRoomFragment.newInstance(program.getChannelId()), "chatRoomFragment").commit();
54 55 return binding.getRoot();
55 56 }
56 57  
... ...
app/src/main/java/com/cnlive/gundam/video/fragment/PlayerUgcLiveFragment.java
... ... @@ -16,7 +16,7 @@ import android.widget.Toast;
16 16 import com.cnlive.gundam.R;
17 17 import com.cnlive.gundam.databinding.FragmentPlayerUgcLiveBinding;
18 18 import com.cnlive.gundam.main.model.VideoListProgram;
19   -import com.cnlive.gundam.video.fragment.chat.UgcLiveChatFragment;
  19 +import com.cnlive.gundam.video.fragment.chat.ChatRoomFragment;
20 20 import com.cnlive.gundam.video.model.VideoModel;
21 21 import com.cnlive.gundam.video.utils.PlayerUtils;
22 22 import com.cnlive.gundam.video.view.BaseVideoView;
... ... @@ -57,8 +57,8 @@ public class PlayerUgcLiveFragment extends Fragment implements BaseVideoView.OnU
57 57 @Override
58 58 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
59 59 binding = DataBindingUtil.inflate(inflater, R.layout.fragment_player_ugc_live, container, false);
60   - getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.contentLayout, UgcLiveChatFragment.newInstance(), "ugcLiveChatFragment").commit();
61 60 initData();
  61 + getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.contentLayout, ChatRoomFragment.newInstance(id), "chatRoomFragment").commit();
62 62 return binding.getRoot();
63 63 }
64 64  
... ...
app/src/main/java/com/cnlive/gundam/video/fragment/chat/ChatRoomFragment.java
... ... @@ -8,7 +8,6 @@ import android.support.v4.app.Fragment;
8 8 import android.support.v7.widget.GridLayoutManager;
9 9 import android.support.v7.widget.OrientationHelper;
10 10 import android.support.v7.widget.SwitchCompat;
11   -import android.util.Log;
12 11 import android.view.LayoutInflater;
13 12 import android.view.View;
14 13 import android.view.ViewGroup;
... ... @@ -48,14 +47,15 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback
48 47 private FragmentChatBinding fragmentChatBinding;
49 48 private ArrayList<GiftModle> giftArray;
50 49 private CommonAdapter<MessageContent> messageContentCommonAdapter;
51   - private String roomId = "ChatRoom06";
52 50 private MessageContentInfo messageContentInfo;
53 51 public SwitchCompat switchCompatBottom;
54 52 private BarrageLayout barrageLayout;
  53 + private String roomId;
55 54  
56 55  
57   - public static ChatRoomFragment newInstance() {
  56 + public static ChatRoomFragment newInstance(String id ) {
58 57 Bundle args = new Bundle();
  58 + args.putString("roomID",id);
59 59 ChatRoomFragment fragment = new ChatRoomFragment();
60 60 fragment.setArguments(args);
61 61 return fragment;
... ... @@ -66,6 +66,7 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback
66 66 @Override
67 67 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
68 68 fragmentChatBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_chat, container, false);
  69 + roomId = getArguments().getString("roomID");
69 70 return fragmentChatBinding.getRoot();
70 71  
71 72 }
... ... @@ -140,7 +141,6 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback
140 141 @Override
141 142 public void onDestroy() {
142 143 super.onDestroy();
143   - Log.v("fdfsfaf","dfasdfsafdfadf");
144 144 ChatUtil.disconnect(false);
145 145 }
146 146  
... ...
app/src/main/java/com/cnlive/gundam/video/fragment/chat/MessageContentInfo.java
... ... @@ -3,7 +3,6 @@ package com.cnlive.gundam.video.fragment.chat;
3 3 import android.content.Context;
4 4 import android.os.Handler;
5 5 import android.text.TextUtils;
6   -import android.util.Log;
7 6  
8 7 import com.cnlive.gundam.user.auth.UserService;
9 8 import com.cnlive.gundam.video.barrage.BarrageBaseMessage;
... ... @@ -34,19 +33,19 @@ public class MessageContentInfo {
34 33 private Context mContext;
35 34 private SendAndRecevieSucessCall mSendAndRecevieSucessCall;
36 35 private String roomId;
37   - private BarrageLayout barrageLayout;
  36 + private BarrageLayout barrageLayout;
38 37 private String JoinType = "joinType";
39   - private String ChatRoom ="chatRoom";
40   - private String giftType = "giftType";
  38 + private String ChatRoom = "chatRoom";
  39 + private String giftType = "giftType";
41 40  
42 41  
43   - public void setOnReceiveAndSendListener(BarrageLayout barrageLayout,String roomID, Context context, SendAndRecevieSucessCall sendAndRecevieSucessCall) {
  42 + public void setOnReceiveAndSendListener(BarrageLayout barrageLayout, String roomID, Context context, SendAndRecevieSucessCall sendAndRecevieSucessCall) {
44 43 this.roomId = roomID;
45 44 this.mContext = context;
46 45 this.mSendAndRecevieSucessCall = sendAndRecevieSucessCall;
47 46 mHandler = new Handler();
48 47 messageContentArrayList = new ArrayList<>();
49   - this.barrageLayout =barrageLayout;
  48 + this.barrageLayout = barrageLayout;
50 49 initListener();
51 50  
52 51 }
... ... @@ -66,12 +65,9 @@ public class MessageContentInfo {
66 65  
67 66 Gson gson = new Gson();
68 67 CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class);
69   - String messagecontent =cnMessageModle.getMessage().getContent();
  68 + String messagecontent = cnMessageModle.getMessage().getContent();
70 69 String messageType = cnMessageModle.getType();
71   -
72   -
73 70 if (messageType.equals(giftType)) {
74   -
75 71 barrageLayout.addMessage(new BarrageBaseMessage(message.getUserInfo().getUserName(), "送了" + messagecontent, ""));
76 72 messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), ": 送了" + messagecontent, message.getUserInfo().getHeadUrl(), true));
77 73 } else if (messageType.equals(ChatRoom)) {
... ... @@ -79,11 +75,9 @@ public class MessageContentInfo {
79 75 messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), messagecontent + " :", message.getUserInfo().getHeadUrl(), false));
80 76 } else {
81 77 messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), " :" + messagecontent, message.getUserInfo().getHeadUrl(), true));
82   -
83 78 }
84 79 barrageLayout.addMessage(new BarrageBaseMessage(message.getUserInfo().getUserName(), messagecontent, ""));
85 80  
86   -
87 81 } else if (messageType.equals(JoinType)) {
88 82 String userName = message.getUserInfo().getUserName();
89 83 if (TextUtils.isEmpty(userName)) {
... ... @@ -123,7 +117,7 @@ public class MessageContentInfo {
123 117  
124 118 Gson gson = new Gson();
125 119 CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class);
126   - String messagecontent =cnMessageModle.getMessage().getContent();
  120 + String messagecontent = cnMessageModle.getMessage().getContent();
127 121 String messageType = cnMessageModle.getType();
128 122  
129 123  
... ... @@ -152,14 +146,13 @@ public class MessageContentInfo {
152 146 onConnectListener = new IChat.OnConnectListener() {
153 147 @Override
154 148 public void onTokenIncorrect(String s) {
155   -
156 149 }
157 150  
158 151 @Override
159 152 public void onSuccess(String s) {
160 153 joinChatRoom();
161 154  
162   - }
  155 + }
163 156  
164 157  
165 158 @Override
... ... @@ -175,10 +168,9 @@ public class MessageContentInfo {
175 168 ChatUtil.joinChatRoom(roomId, 0, new IChat.OnOperationListener() {
176 169 @Override
177 170 public void onSuccess(int what, String extra) {
178   - CNMessageModle cnMessageModle = new CNMessageModle(JoinType,new MessageInfo("","","","",""));
179   - Gson gson2=new Gson();
180   - String obj2=gson2.toJson(cnMessageModle);
181   - Log.v("dfsd",obj2);
  171 + CNMessageModle cnMessageModle = new CNMessageModle(JoinType, new MessageInfo("", "", "", "", ""));
  172 + Gson gson2 = new Gson();
  173 + String obj2 = gson2.toJson(cnMessageModle);
182 174 ChatUtil.sendMessage(IChat.CHATROOM, roomId, obj2, onSendMessageListener);
183 175 }
184 176  
... ... @@ -196,5 +188,4 @@ public class MessageContentInfo {
196 188 }
197 189  
198 190  
199   -
200 191 }
... ...
app/src/main/java/com/cnlive/gundam/video/fragment/chat/UgcLiveChatFragment.java deleted 100644 → 0
1   -package com.cnlive.gundam.video.fragment.chat;
2   -
3   -import android.os.Bundle;
4   -import android.support.annotation.Nullable;
5   -import android.support.v7.widget.SwitchCompat;
6   -import android.view.LayoutInflater;
7   -import android.view.View;
8   -import android.view.ViewGroup;
9   -
10   -import com.cnlive.gundam.R;
11   -import com.cnlive.gundam.video.view.PlayerControllerView;
12   -
13   -/**
14   - * @author 陈硕
15   - * @time 2017/6/29 19:36
16   - * @desc ${TODD}
17   - */
18   -public class UgcLiveChatFragment extends ChatRoomFragment {
19   -
20   - public static UgcLiveChatFragment newInstance() {
21   - Bundle args = new Bundle();
22   - UgcLiveChatFragment fragment = new UgcLiveChatFragment();
23   - fragment.setArguments(args);
24   - return fragment;
25   - }
26   -
27   - @Nullable
28   - @Override
29   - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
30   - return super.onCreateView(inflater, container, savedInstanceState);
31   - }
32   -
33   -
34   - @Override
35   - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
36   - super.onViewCreated(view, savedInstanceState);
37   - PlayerControllerView viewById = getActivity().findViewById(R.id.controllerView);
38   - viewById.setonswitchCompatChangeListene(new PlayerControllerView.SwitchCompatChangeListener() {
39   - @Override
40   - public void onSwitchCompatChange(SwitchCompat barrageTop) {
41   - barrageTop.setVisibility(View.INVISIBLE);
42   - }
43   - });
44   - }
45   -}