Commit fa3b3f03c5f1e173aa1f1c02aa9a4ed389e3b66d
1 parent
87fb84bd
优化代码
Showing
8 changed files
with
55 additions
and
129 deletions
app/src/main/java/com/cnlive/gundam/video/adpter/GiftAdapter.java
| @@ -33,12 +33,15 @@ public class GiftAdapter extends RecyclerView.Adapter<GiftAdapter.RVHolder> { | @@ -33,12 +33,15 @@ public class GiftAdapter extends RecyclerView.Adapter<GiftAdapter.RVHolder> { | ||
| 33 | private int mLayoutId; // 条目布局文件ID | 33 | private int mLayoutId; // 条目布局文件ID |
| 34 | private int mVariableId; // DataBinding变量ID | 34 | private int mVariableId; // DataBinding变量ID |
| 35 | private String roomId; | 35 | private String roomId; |
| 36 | + private final Gson gson2; | ||
| 37 | + | ||
| 36 | public GiftAdapter(String roomId,Context context, List<GiftModle> list, int layoutId, int variableId) { | 38 | public GiftAdapter(String roomId,Context context, List<GiftModle> list, int layoutId, int variableId) { |
| 37 | this.mContext = context; | 39 | this.mContext = context; |
| 38 | this.mDataList = list; | 40 | this.mDataList = list; |
| 39 | this.mLayoutId = layoutId; | 41 | this.mLayoutId = layoutId; |
| 40 | mVariableId = variableId; | 42 | mVariableId = variableId; |
| 41 | this.roomId=roomId; | 43 | this.roomId=roomId; |
| 44 | + gson2 = new Gson(); | ||
| 42 | 45 | ||
| 43 | 46 | ||
| 44 | } | 47 | } |
| @@ -59,7 +62,6 @@ public class GiftAdapter extends RecyclerView.Adapter<GiftAdapter.RVHolder> { | @@ -59,7 +62,6 @@ public class GiftAdapter extends RecyclerView.Adapter<GiftAdapter.RVHolder> { | ||
| 59 | @Override | 62 | @Override |
| 60 | public void onClick(View v) { | 63 | public void onClick(View v) { |
| 61 | CNMessageModle cnMessageModle = new CNMessageModle("giftType",new MessageInfo("0",mDataList.get(position).getGiftMessage(),"1","0",mDataList.get(position).getGiftMessage())); | 64 | CNMessageModle cnMessageModle = new CNMessageModle("giftType",new MessageInfo("0",mDataList.get(position).getGiftMessage(),"1","0",mDataList.get(position).getGiftMessage())); |
| 62 | - Gson gson2=new Gson(); | ||
| 63 | String obj2=gson2.toJson(cnMessageModle); | 65 | String obj2=gson2.toJson(cnMessageModle); |
| 64 | ChatUtil.sendMessage(IChat.CHATROOM, roomId, obj2, new IChat.OnSendMessageListener() { | 66 | ChatUtil.sendMessage(IChat.CHATROOM, roomId, obj2, new IChat.OnSendMessageListener() { |
| 65 | @Override | 67 | @Override |
| @@ -70,7 +72,6 @@ public class GiftAdapter extends RecyclerView.Adapter<GiftAdapter.RVHolder> { | @@ -70,7 +72,6 @@ public class GiftAdapter extends RecyclerView.Adapter<GiftAdapter.RVHolder> { | ||
| 70 | @Override | 72 | @Override |
| 71 | public void onSuccess(CNMessage message) { | 73 | public void onSuccess(CNMessage message) { |
| 72 | PlayerActivity context = (PlayerActivity) GiftAdapter.this.mContext; | 74 | PlayerActivity context = (PlayerActivity) GiftAdapter.this.mContext; |
| 73 | - | ||
| 74 | ChatRoomFragment chatRoomFragment = (ChatRoomFragment) context.getSupportFragmentManager().findFragmentByTag("chatRoomFragment"); | 75 | ChatRoomFragment chatRoomFragment = (ChatRoomFragment) context.getSupportFragmentManager().findFragmentByTag("chatRoomFragment"); |
| 75 | chatRoomFragment.giftItem(position); | 76 | chatRoomFragment.giftItem(position); |
| 76 | 77 |
app/src/main/java/com/cnlive/gundam/video/fragment/PlayerLiveFragment.java
| @@ -107,9 +107,6 @@ public class PlayerLiveFragment extends Fragment implements PlayerAccelerometerS | @@ -107,9 +107,6 @@ public class PlayerLiveFragment extends Fragment implements PlayerAccelerometerS | ||
| 107 | getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); | 107 | getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | - ChatRoomFragment chatRoomFragment = (ChatRoomFragment) getActivity().getSupportFragmentManager().findFragmentByTag("chatRoomFragment"); | ||
| 111 | - chatRoomFragment.doBarrage(); | ||
| 112 | - | ||
| 113 | } | 110 | } |
| 114 | 111 | ||
| 115 | 112 |
app/src/main/java/com/cnlive/gundam/video/fragment/PlayerUgcLiveFragment.java
| @@ -22,6 +22,7 @@ import com.cnlive.gundam.video.utils.PlayerUtils; | @@ -22,6 +22,7 @@ import com.cnlive.gundam.video.utils.PlayerUtils; | ||
| 22 | import com.cnlive.gundam.video.view.BaseVideoView; | 22 | import com.cnlive.gundam.video.view.BaseVideoView; |
| 23 | import com.cnlive.gundam.video.view.VideoView; | 23 | import com.cnlive.gundam.video.view.VideoView; |
| 24 | 24 | ||
| 25 | + | ||
| 25 | /** | 26 | /** |
| 26 | * Created by gujun on 2017/4/5. | 27 | * Created by gujun on 2017/4/5. |
| 27 | */ | 28 | */ |
app/src/main/java/com/cnlive/gundam/video/fragment/chat/ChatRoomFragment.java
| @@ -24,11 +24,10 @@ import com.cnlive.gundam.user.model.User; | @@ -24,11 +24,10 @@ import com.cnlive.gundam.user.model.User; | ||
| 24 | import com.cnlive.gundam.user.util.InputUtil; | 24 | import com.cnlive.gundam.user.util.InputUtil; |
| 25 | import com.cnlive.gundam.video.adpter.CommonAdapter; | 25 | import com.cnlive.gundam.video.adpter.CommonAdapter; |
| 26 | import com.cnlive.gundam.video.adpter.GiftAdapter; | 26 | import com.cnlive.gundam.video.adpter.GiftAdapter; |
| 27 | +import com.cnlive.gundam.video.barrage.BarrageBaseMessage; | ||
| 27 | import com.cnlive.gundam.video.barrage.BarrageBaseView; | 28 | import com.cnlive.gundam.video.barrage.BarrageBaseView; |
| 28 | import com.cnlive.gundam.video.model.GiftModle; | 29 | import com.cnlive.gundam.video.model.GiftModle; |
| 29 | import com.cnlive.gundam.video.model.MessageContent; | 30 | import com.cnlive.gundam.video.model.MessageContent; |
| 30 | -import com.cnlive.gundam.video.utils.PlayerUtils; | ||
| 31 | -import com.cnlive.gundam.video.view.PlayerControllerView; | ||
| 32 | import com.cnlive.libs.util.chat.ChatUtil; | 31 | import com.cnlive.libs.util.chat.ChatUtil; |
| 33 | import com.cnlive.libs.util.chat.base.IChat; | 32 | import com.cnlive.libs.util.chat.base.IChat; |
| 34 | import com.cnlive.libs.util.chat.model.CNUserInfo; | 33 | import com.cnlive.libs.util.chat.model.CNUserInfo; |
| @@ -37,14 +36,14 @@ import com.cnlive.libs.video.barrage.BarrageLayout; | @@ -37,14 +36,14 @@ import com.cnlive.libs.video.barrage.BarrageLayout; | ||
| 37 | import java.util.ArrayList; | 36 | import java.util.ArrayList; |
| 38 | 37 | ||
| 39 | 38 | ||
| 39 | + | ||
| 40 | /** | 40 | /** |
| 41 | * @author 陈硕 | 41 | * @author 陈硕 |
| 42 | * @time 2017/5/27 13:57 | 42 | * @time 2017/5/27 13:57 |
| 43 | * @desc ${TODD} | 43 | * @desc ${TODD} |
| 44 | */ | 44 | */ |
| 45 | -public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback, MessageContentInfo.SendAndRecevieSucessCall { | 45 | +public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback, MessageContentInfo.OnChatListener { |
| 46 | 46 | ||
| 47 | - PlayerControllerView.SwitchCompatChangeListener switchCompatChangeListener; | ||
| 48 | private FragmentChatBinding fragmentChatBinding; | 47 | private FragmentChatBinding fragmentChatBinding; |
| 49 | private ArrayList<GiftModle> giftArray; | 48 | private ArrayList<GiftModle> giftArray; |
| 50 | private CommonAdapter<MessageContent> messageContentCommonAdapter; | 49 | private CommonAdapter<MessageContent> messageContentCommonAdapter; |
| @@ -125,15 +124,6 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback | @@ -125,15 +124,6 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback | ||
| 125 | ChatUtil.sendMessage(IChat.CHATROOM, roomId, message, messageContentInfo.onSendMessageListener); | 124 | ChatUtil.sendMessage(IChat.CHATROOM, roomId, message, messageContentInfo.onSendMessageListener); |
| 126 | } | 125 | } |
| 127 | 126 | ||
| 128 | - @Override | ||
| 129 | - public void sentSucess(ArrayList<MessageContent> messageContents) { | ||
| 130 | - messageContentCommonAdapter.addItems((messageContents)); | ||
| 131 | - } | ||
| 132 | - | ||
| 133 | - @Override | ||
| 134 | - public void receaviceSucess(ArrayList<MessageContent> messageContents) { | ||
| 135 | - messageContentCommonAdapter.addItems((messageContents)); | ||
| 136 | - } | ||
| 137 | 127 | ||
| 138 | 128 | ||
| 139 | @Override | 129 | @Override |
| @@ -144,14 +134,20 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback | @@ -144,14 +134,20 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback | ||
| 144 | 134 | ||
| 145 | private void initChat() { | 135 | private void initChat() { |
| 146 | User activeAccountInfo = UserService.getInstance(getActivity()).getActiveAccountInfo(); | 136 | User activeAccountInfo = UserService.getInstance(getActivity()).getActiveAccountInfo(); |
| 147 | - String faceurl = activeAccountInfo.getFaceurl(); | ||
| 148 | - String nickname = activeAccountInfo.getNickname(); | ||
| 149 | - int uid = activeAccountInfo.getUid(); | 137 | + final String faceurl = activeAccountInfo.getFaceurl(); |
| 138 | + final String nickname = activeAccountInfo.getNickname(); | ||
| 139 | + final int uid = activeAccountInfo.getUid(); | ||
| 140 | + | ||
| 150 | if (uid != 0) { | 141 | if (uid != 0) { |
| 142 | + | ||
| 151 | ChatUtil.connect(new CNUserInfo(uid + "", nickname, faceurl), messageContentInfo.onConnectListener); | 143 | ChatUtil.connect(new CNUserInfo(uid + "", nickname, faceurl), messageContentInfo.onConnectListener); |
| 152 | } else { | 144 | } else { |
| 145 | + | ||
| 153 | ChatUtil.connect(messageContentInfo.onConnectListener); | 146 | ChatUtil.connect(messageContentInfo.onConnectListener); |
| 147 | + | ||
| 154 | } | 148 | } |
| 149 | + | ||
| 150 | + | ||
| 155 | ChatUtil.setOnReceiveMessageListener(messageContentInfo.onReceiveMessageListener); | 151 | ChatUtil.setOnReceiveMessageListener(messageContentInfo.onReceiveMessageListener); |
| 156 | 152 | ||
| 157 | } | 153 | } |
| @@ -213,38 +209,7 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback | @@ -213,38 +209,7 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback | ||
| 213 | barrageBottom(); | 209 | barrageBottom(); |
| 214 | initMessageAdapter(); | 210 | initMessageAdapter(); |
| 215 | messageContentInfo = new MessageContentInfo(); | 211 | messageContentInfo = new MessageContentInfo(); |
| 216 | - messageContentInfo.setOnReceiveAndSendListener(barrageLayout, roomId, getActivity(), ChatRoomFragment.this); | ||
| 217 | - } | ||
| 218 | - | ||
| 219 | - | ||
| 220 | - public void doBarrage() { | ||
| 221 | - boolean isPortrait = PlayerUtils.isPortrait(getActivity()); | ||
| 222 | - final BarrageLayout barrageLayout = getActivity().findViewById(R.id.private_message); | ||
| 223 | - barrageLayout.pause(); | ||
| 224 | - SwitchCompat switchCompat = getActivity().findViewById(R.id.barrage); | ||
| 225 | - switchCompat.setChecked(false); | ||
| 226 | - if (!isPortrait) { | ||
| 227 | - PlayerControllerView viewById = getActivity().findViewById(R.id.controllerView); | ||
| 228 | - viewById.setonswitchCompatChangeListene(switchCompatChangeListener = new PlayerControllerView.SwitchCompatChangeListener() { | ||
| 229 | - @Override | ||
| 230 | - public void onSwitchCompatChange(SwitchCompat barrageTop) { | ||
| 231 | - barrageTop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | ||
| 232 | - @Override | ||
| 233 | - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { | ||
| 234 | - if (b) { | ||
| 235 | - barrageLayout.resume(); | ||
| 236 | - | ||
| 237 | - } else { | ||
| 238 | - barrageLayout.pause(); | ||
| 239 | - | ||
| 240 | - } | ||
| 241 | - } | ||
| 242 | - }); | ||
| 243 | - } | ||
| 244 | - }); | ||
| 245 | - | ||
| 246 | - | ||
| 247 | - } | 212 | + messageContentInfo.setOnReceiveAndSendListener( roomId, getActivity(), ChatRoomFragment.this); |
| 248 | } | 213 | } |
| 249 | 214 | ||
| 250 | 215 | ||
| @@ -253,4 +218,14 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback | @@ -253,4 +218,14 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback | ||
| 253 | } | 218 | } |
| 254 | 219 | ||
| 255 | 220 | ||
| 221 | + @Override | ||
| 222 | + public void onchat(ArrayList<MessageContent> messageContents) { | ||
| 223 | + messageContentCommonAdapter.addItems((messageContents)); | ||
| 224 | + | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + @Override | ||
| 228 | + public void onbarrage(BarrageBaseMessage barrageBaseMessage) { | ||
| 229 | + barrageLayout.addMessage(barrageBaseMessage); | ||
| 230 | + } | ||
| 256 | } | 231 | } |
app/src/main/java/com/cnlive/gundam/video/fragment/chat/CommentFragment.java
| 1 | package com.cnlive.gundam.video.fragment.chat; | 1 | package com.cnlive.gundam.video.fragment.chat; |
| 2 | 2 | ||
| 3 | -import android.content.Context; | ||
| 4 | import android.os.Bundle; | 3 | import android.os.Bundle; |
| 5 | import android.support.annotation.Nullable; | 4 | import android.support.annotation.Nullable; |
| 6 | import android.support.v4.app.Fragment; | 5 | import android.support.v4.app.Fragment; |
| 7 | import android.support.v7.widget.LinearLayoutManager; | 6 | import android.support.v7.widget.LinearLayoutManager; |
| 8 | import android.support.v7.widget.RecyclerView; | 7 | import android.support.v7.widget.RecyclerView; |
| 9 | -import android.telephony.TelephonyManager; | ||
| 10 | import android.util.Log; | 8 | import android.util.Log; |
| 11 | import android.view.LayoutInflater; | 9 | import android.view.LayoutInflater; |
| 12 | import android.view.View; | 10 | import android.view.View; |
| @@ -18,7 +16,6 @@ import com.cnlive.gundam.R; | @@ -18,7 +16,6 @@ import com.cnlive.gundam.R; | ||
| 18 | import com.cnlive.gundam.user.auth.UserService; | 16 | import com.cnlive.gundam.user.auth.UserService; |
| 19 | import com.cnlive.gundam.user.util.InputUtil; | 17 | import com.cnlive.gundam.user.util.InputUtil; |
| 20 | import com.cnlive.gundam.video.adpter.CommentAdapter; | 18 | import com.cnlive.gundam.video.adpter.CommentAdapter; |
| 21 | -import com.cnlive.libs.util.Config; | ||
| 22 | import com.cnlive.libs.util.chat.model.ErrorMessage; | 19 | import com.cnlive.libs.util.chat.model.ErrorMessage; |
| 23 | import com.cnlive.libs.util.comment.CommentUtil; | 20 | import com.cnlive.libs.util.comment.CommentUtil; |
| 24 | import com.cnlive.libs.util.comment.base.CommentCallback; | 21 | import com.cnlive.libs.util.comment.base.CommentCallback; |
| @@ -29,6 +26,7 @@ import com.cnlive.libs.util.model.CommentPage; | @@ -29,6 +26,7 @@ import com.cnlive.libs.util.model.CommentPage; | ||
| 29 | import com.cnlive.libs.util.model.CommentProgram; | 26 | import com.cnlive.libs.util.model.CommentProgram; |
| 30 | 27 | ||
| 31 | import java.util.List; | 28 | import java.util.List; |
| 29 | +import java.util.Random; | ||
| 32 | 30 | ||
| 33 | /** | 31 | /** |
| 34 | * @author 陈硕 | 32 | * @author 陈硕 |
| @@ -78,10 +76,9 @@ public class CommentFragment extends Fragment implements View.OnClickListener, C | @@ -78,10 +76,9 @@ public class CommentFragment extends Fragment implements View.OnClickListener, C | ||
| 78 | inputUtil.setonSendCommentCallBack(this); | 76 | inputUtil.setonSendCommentCallBack(this); |
| 79 | int uid = UserService.getInstance(getActivity()).getActiveAccountInfo().getUid(); | 77 | int uid = UserService.getInstance(getActivity()).getActiveAccountInfo().getUid(); |
| 80 | if(uid!=0){ | 78 | if(uid!=0){ |
| 81 | - userID=uid+""; | 79 | + userID=String.valueOf(uid); |
| 82 | }else { | 80 | }else { |
| 83 | - TelephonyManager telephonyManager = (TelephonyManager) Config.getContext().getSystemService(Context.TELEPHONY_SERVICE); | ||
| 84 | - userID=telephonyManager.getDeviceId();} | 81 | + userID=String.valueOf(new Random().nextInt(100));} |
| 85 | 82 | ||
| 86 | } | 83 | } |
| 87 | 84 | ||
| @@ -172,7 +169,7 @@ public class CommentFragment extends Fragment implements View.OnClickListener, C | @@ -172,7 +169,7 @@ public class CommentFragment extends Fragment implements View.OnClickListener, C | ||
| 172 | if (errorMessage != null && errorMessage.getErrorCode().equals("0")) { | 169 | if (errorMessage != null && errorMessage.getErrorCode().equals("0")) { |
| 173 | 170 | ||
| 174 | Toast.makeText(getActivity(), "评论成功", Toast.LENGTH_SHORT).show(); | 171 | Toast.makeText(getActivity(), "评论成功", Toast.LENGTH_SHORT).show(); |
| 175 | - edit_comment.setText(""); | 172 | + edit_comment.setText("我来说两句....."); |
| 176 | commentAdapter.clearItems(); | 173 | commentAdapter.clearItems(); |
| 177 | getCommentMesaage(); | 174 | getCommentMesaage(); |
| 178 | } else Toast.makeText(getActivity(), "评论失败", Toast.LENGTH_SHORT).show(); | 175 | } else Toast.makeText(getActivity(), "评论失败", Toast.LENGTH_SHORT).show(); |
app/src/main/java/com/cnlive/gundam/video/fragment/chat/MessageContentInfo.java
| @@ -12,7 +12,6 @@ import com.cnlive.gundam.video.model.MessageInfo; | @@ -12,7 +12,6 @@ import com.cnlive.gundam.video.model.MessageInfo; | ||
| 12 | import com.cnlive.libs.util.chat.ChatUtil; | 12 | import com.cnlive.libs.util.chat.ChatUtil; |
| 13 | import com.cnlive.libs.util.chat.base.IChat; | 13 | import com.cnlive.libs.util.chat.base.IChat; |
| 14 | import com.cnlive.libs.util.chat.model.CNMessage; | 14 | import com.cnlive.libs.util.chat.model.CNMessage; |
| 15 | -import com.cnlive.libs.video.barrage.BarrageLayout; | ||
| 16 | import com.google.gson.Gson; | 15 | import com.google.gson.Gson; |
| 17 | 16 | ||
| 18 | import java.util.ArrayList; | 17 | import java.util.ArrayList; |
| @@ -31,46 +30,40 @@ public class MessageContentInfo { | @@ -31,46 +30,40 @@ public class MessageContentInfo { | ||
| 31 | private Handler mHandler; | 30 | private Handler mHandler; |
| 32 | private ArrayList<com.cnlive.gundam.video.model.MessageContent> messageContentArrayList; | 31 | private ArrayList<com.cnlive.gundam.video.model.MessageContent> messageContentArrayList; |
| 33 | private Context mContext; | 32 | private Context mContext; |
| 34 | - private SendAndRecevieSucessCall mSendAndRecevieSucessCall; | 33 | + private OnChatListener onChatListener; |
| 35 | private String roomId; | 34 | private String roomId; |
| 36 | - private BarrageLayout barrageLayout; | ||
| 37 | private String JoinType = "joinType"; | 35 | private String JoinType = "joinType"; |
| 38 | private String ChatRoom = "chatRoom"; | 36 | private String ChatRoom = "chatRoom"; |
| 39 | private String giftType = "giftType"; | 37 | private String giftType = "giftType"; |
| 40 | private Gson gson; | 38 | private Gson gson; |
| 41 | 39 | ||
| 42 | 40 | ||
| 43 | - public void setOnReceiveAndSendListener(BarrageLayout barrageLayout, String roomID, Context context, SendAndRecevieSucessCall sendAndRecevieSucessCall) { | 41 | + public void setOnReceiveAndSendListener(String roomID, Context context, OnChatListener sendAndRecevieSucessCall) { |
| 44 | this.roomId = roomID; | 42 | this.roomId = roomID; |
| 45 | this.mContext = context; | 43 | this.mContext = context; |
| 46 | gson = new Gson(); | 44 | gson = new Gson(); |
| 47 | - this.mSendAndRecevieSucessCall = sendAndRecevieSucessCall; | 45 | + this.onChatListener = sendAndRecevieSucessCall; |
| 48 | mHandler = new Handler(); | 46 | mHandler = new Handler(); |
| 49 | messageContentArrayList = new ArrayList<>(); | 47 | messageContentArrayList = new ArrayList<>(); |
| 50 | - this.barrageLayout = barrageLayout; | ||
| 51 | initListener(); | 48 | initListener(); |
| 52 | 49 | ||
| 53 | } | 50 | } |
| 54 | 51 | ||
| 55 | - | ||
| 56 | private void initListener() { | 52 | private void initListener() { |
| 57 | - | ||
| 58 | - | ||
| 59 | onReceiveMessageListener = new IChat.OnReceiveMessageListener() { | 53 | onReceiveMessageListener = new IChat.OnReceiveMessageListener() { |
| 60 | @Override | 54 | @Override |
| 61 | public void processMessage(final CNMessage message) { | 55 | public void processMessage(final CNMessage message) { |
| 62 | - | ||
| 63 | mHandler.post(new Runnable() { | 56 | mHandler.post(new Runnable() { |
| 64 | @Override | 57 | @Override |
| 65 | public void run() { | 58 | public void run() { |
| 66 | try { | 59 | try { |
| 67 | - | ||
| 68 | - | ||
| 69 | CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class); | 60 | CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class); |
| 70 | String messagecontent = cnMessageModle.getMessage().getContent(); | 61 | String messagecontent = cnMessageModle.getMessage().getContent(); |
| 71 | String messageType = cnMessageModle.getType(); | 62 | String messageType = cnMessageModle.getType(); |
| 72 | if (messageType.equals(giftType)) { | 63 | if (messageType.equals(giftType)) { |
| 73 | - barrageLayout.addMessage(new BarrageBaseMessage(message.getUserInfo().getUserName(), "送了" + messagecontent, "")); | 64 | + if (onChatListener != null) { |
| 65 | + onChatListener.onbarrage(new BarrageBaseMessage(message.getUserInfo().getUserName(), "送了" + messagecontent, "")); | ||
| 66 | + } | ||
| 74 | messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), ": 送了" + messagecontent, message.getUserInfo().getHeadUrl(), true)); | 67 | messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), ": 送了" + messagecontent, message.getUserInfo().getHeadUrl(), true)); |
| 75 | } else if (messageType.equals(ChatRoom)) { | 68 | } else if (messageType.equals(ChatRoom)) { |
| 76 | if (message.getUserInfo().getUserId().equals(ChatUtil.getCurrentUserInfo().getUserId())) { | 69 | if (message.getUserInfo().getUserId().equals(ChatUtil.getCurrentUserInfo().getUserId())) { |
| @@ -78,8 +71,9 @@ public class MessageContentInfo { | @@ -78,8 +71,9 @@ public class MessageContentInfo { | ||
| 78 | } else { | 71 | } else { |
| 79 | messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), " :" + messagecontent, message.getUserInfo().getHeadUrl(), true)); | 72 | messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), " :" + messagecontent, message.getUserInfo().getHeadUrl(), true)); |
| 80 | } | 73 | } |
| 81 | - barrageLayout.addMessage(new BarrageBaseMessage(message.getUserInfo().getUserName(), messagecontent, "")); | ||
| 82 | - | 74 | + if (onChatListener != null) { |
| 75 | + onChatListener.onbarrage(new BarrageBaseMessage(message.getUserInfo().getUserName(), messagecontent, "")); | ||
| 76 | + } | ||
| 83 | } else if (messageType.equals(JoinType)) { | 77 | } else if (messageType.equals(JoinType)) { |
| 84 | String userName = message.getUserInfo().getUserName(); | 78 | String userName = message.getUserInfo().getUserName(); |
| 85 | if (TextUtils.isEmpty(userName)) { | 79 | if (TextUtils.isEmpty(userName)) { |
| @@ -88,15 +82,15 @@ public class MessageContentInfo { | @@ -88,15 +82,15 @@ public class MessageContentInfo { | ||
| 88 | if (userName.equals(UserService.getInstance(mContext).getActiveAccountInfo().getNickname())) { | 82 | if (userName.equals(UserService.getInstance(mContext).getActiveAccountInfo().getNickname())) { |
| 89 | return; | 83 | return; |
| 90 | } | 84 | } |
| 91 | - barrageLayout.addMessage(new BarrageBaseMessage(message.getUserInfo().getUserName(), "来了", "")); | ||
| 92 | - | 85 | + if (onChatListener != null) { |
| 86 | + onChatListener.onbarrage(new BarrageBaseMessage(message.getUserInfo().getUserName(), "来了", "")); | ||
| 87 | + } | ||
| 93 | messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), ": " + "来了", message.getUserInfo().getHeadUrl(), true)); | 88 | messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), ": " + "来了", message.getUserInfo().getHeadUrl(), true)); |
| 94 | - | ||
| 95 | } | 89 | } |
| 96 | - | ||
| 97 | - mSendAndRecevieSucessCall.receaviceSucess(messageContentArrayList); | ||
| 98 | - | ||
| 99 | - } catch (Exception e) { | 90 | + if (onChatListener != null) { |
| 91 | + onChatListener.onchat(messageContentArrayList); | ||
| 92 | + } | ||
| 93 | + } catch (Exception e) { | ||
| 100 | e.printStackTrace(); | 94 | e.printStackTrace(); |
| 101 | } | 95 | } |
| 102 | } | 96 | } |
| @@ -109,37 +103,24 @@ public class MessageContentInfo { | @@ -109,37 +103,24 @@ public class MessageContentInfo { | ||
| 109 | onSendMessageListener = new IChat.OnSendMessageListener() { | 103 | onSendMessageListener = new IChat.OnSendMessageListener() { |
| 110 | @Override | 104 | @Override |
| 111 | public void onAttached(CNMessage message) { | 105 | public void onAttached(CNMessage message) { |
| 112 | - | ||
| 113 | } | 106 | } |
| 114 | - | ||
| 115 | @Override | 107 | @Override |
| 116 | public void onSuccess(CNMessage message) { | 108 | public void onSuccess(CNMessage message) { |
| 117 | - | ||
| 118 | try { | 109 | try { |
| 119 | - | ||
| 120 | CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class); | 110 | CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class); |
| 121 | String messagecontent = cnMessageModle.getMessage().getContent(); | 111 | String messagecontent = cnMessageModle.getMessage().getContent(); |
| 122 | String messageType = cnMessageModle.getType(); | 112 | String messageType = cnMessageModle.getType(); |
| 123 | - | ||
| 124 | - | ||
| 125 | - if (messageType.equals(ChatRoom)) { | ||
| 126 | - barrageLayout.addMessage(new BarrageBaseMessage(message.getUserInfo().getUserName(), messagecontent, "")); | ||
| 127 | - | 113 | + if (messageType.equals(ChatRoom)) { |
| 114 | + onChatListener.onbarrage(new BarrageBaseMessage(message.getUserInfo().getUserName(), messagecontent, "")); | ||
| 128 | messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), messagecontent + " :", message.getUserInfo().getHeadUrl(), false)); | 115 | messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), messagecontent + " :", message.getUserInfo().getHeadUrl(), false)); |
| 129 | - | ||
| 130 | - mSendAndRecevieSucessCall.sentSucess(messageContentArrayList); | 116 | + onChatListener.onchat(messageContentArrayList); |
| 131 | } | 117 | } |
| 132 | - | ||
| 133 | } catch (Exception e) { | 118 | } catch (Exception e) { |
| 134 | e.printStackTrace(); | 119 | e.printStackTrace(); |
| 135 | } | 120 | } |
| 136 | - | ||
| 137 | - | ||
| 138 | } | 121 | } |
| 139 | - | ||
| 140 | @Override | 122 | @Override |
| 141 | public void onError(CNMessage message, int what, String extra) { | 123 | public void onError(CNMessage message, int what, String extra) { |
| 142 | - | ||
| 143 | } | 124 | } |
| 144 | }; | 125 | }; |
| 145 | 126 | ||
| @@ -148,14 +129,10 @@ public class MessageContentInfo { | @@ -148,14 +129,10 @@ public class MessageContentInfo { | ||
| 148 | @Override | 129 | @Override |
| 149 | public void onTokenIncorrect(String s) { | 130 | public void onTokenIncorrect(String s) { |
| 150 | } | 131 | } |
| 151 | - | ||
| 152 | @Override | 132 | @Override |
| 153 | public void onSuccess(String s) { | 133 | public void onSuccess(String s) { |
| 154 | joinChatRoom(); | 134 | joinChatRoom(); |
| 155 | - | ||
| 156 | } | 135 | } |
| 157 | - | ||
| 158 | - | ||
| 159 | @Override | 136 | @Override |
| 160 | public void onError(int i, String s) { | 137 | public void onError(int i, String s) { |
| 161 | 138 | ||
| @@ -165,7 +142,7 @@ public class MessageContentInfo { | @@ -165,7 +142,7 @@ public class MessageContentInfo { | ||
| 165 | } | 142 | } |
| 166 | 143 | ||
| 167 | 144 | ||
| 168 | - private void joinChatRoom() { | 145 | + public void joinChatRoom() { |
| 169 | ChatUtil.joinChatRoom(roomId, 0, new IChat.OnOperationListener() { | 146 | ChatUtil.joinChatRoom(roomId, 0, new IChat.OnOperationListener() { |
| 170 | @Override | 147 | @Override |
| 171 | public void onSuccess(int what, String extra) { | 148 | public void onSuccess(int what, String extra) { |
| @@ -181,10 +158,11 @@ public class MessageContentInfo { | @@ -181,10 +158,11 @@ public class MessageContentInfo { | ||
| 181 | }); | 158 | }); |
| 182 | } | 159 | } |
| 183 | 160 | ||
| 184 | - public interface SendAndRecevieSucessCall { | ||
| 185 | - void sentSucess(ArrayList<com.cnlive.gundam.video.model.MessageContent> messageContents); | 161 | + public interface OnChatListener { |
| 162 | + void onchat(ArrayList<com.cnlive.gundam.video.model.MessageContent> messageContents); | ||
| 163 | + | ||
| 164 | + void onbarrage(BarrageBaseMessage barrageBaseMessage); | ||
| 186 | 165 | ||
| 187 | - void receaviceSucess(ArrayList<com.cnlive.gundam.video.model.MessageContent> messageContents); | ||
| 188 | } | 166 | } |
| 189 | 167 | ||
| 190 | 168 |
app/src/main/java/com/cnlive/gundam/video/view/PlayerControllerView.java
| @@ -11,7 +11,6 @@ import android.databinding.ObservableLong; | @@ -11,7 +11,6 @@ import android.databinding.ObservableLong; | ||
| 11 | import android.databinding.ViewDataBinding; | 11 | import android.databinding.ViewDataBinding; |
| 12 | import android.os.Handler; | 12 | import android.os.Handler; |
| 13 | import android.os.Message; | 13 | import android.os.Message; |
| 14 | -import android.support.v7.widget.SwitchCompat; | ||
| 15 | import android.text.TextUtils; | 14 | import android.text.TextUtils; |
| 16 | import android.util.AttributeSet; | 15 | import android.util.AttributeSet; |
| 17 | import android.view.LayoutInflater; | 16 | import android.view.LayoutInflater; |
| @@ -21,7 +20,6 @@ import android.widget.SeekBar; | @@ -21,7 +20,6 @@ import android.widget.SeekBar; | ||
| 21 | 20 | ||
| 22 | import com.cnlive.gundam.BR; | 21 | import com.cnlive.gundam.BR; |
| 23 | import com.cnlive.gundam.R; | 22 | import com.cnlive.gundam.R; |
| 24 | -import com.cnlive.gundam.databinding.LayoutPlayerControllerLiveLBinding; | ||
| 25 | import com.cnlive.gundam.video.utils.PlayerUtils; | 23 | import com.cnlive.gundam.video.utils.PlayerUtils; |
| 26 | import com.cnlive.gundam.video.utils.VideoRateUtil; | 24 | import com.cnlive.gundam.video.utils.VideoRateUtil; |
| 27 | import com.cnlive.libs.util.Config; | 25 | import com.cnlive.libs.util.Config; |
| @@ -186,7 +184,6 @@ public class PlayerControllerView extends RelativeLayout implements SeekBar.OnSe | @@ -186,7 +184,6 @@ public class PlayerControllerView extends RelativeLayout implements SeekBar.OnSe | ||
| 186 | binding.setVariable(BR.title, observableTitle); | 184 | binding.setVariable(BR.title, observableTitle); |
| 187 | binding.setVariable(BR.showController, observableShow); | 185 | binding.setVariable(BR.showController, observableShow); |
| 188 | binding.setVariable(BR.isPlay, observableIsPlay); | 186 | binding.setVariable(BR.isPlay, observableIsPlay); |
| 189 | - if(switchCompatChangeListener!=null)switchCompatChangeListener.onSwitchCompatChange(((LayoutPlayerControllerLiveLBinding) this.binding).barrageTop); | ||
| 190 | isUgc = false; | 187 | isUgc = false; |
| 191 | break; | 188 | break; |
| 192 | case UGC_VOD_P: | 189 | case UGC_VOD_P: |
| @@ -406,14 +403,6 @@ public class PlayerControllerView extends RelativeLayout implements SeekBar.OnSe | @@ -406,14 +403,6 @@ public class PlayerControllerView extends RelativeLayout implements SeekBar.OnSe | ||
| 406 | void onSwitchRate(String rate); | 403 | void onSwitchRate(String rate); |
| 407 | } | 404 | } |
| 408 | 405 | ||
| 409 | - public interface SwitchCompatChangeListener{ | ||
| 410 | - void onSwitchCompatChange(SwitchCompat barrageTop); | ||
| 411 | - } | ||
| 412 | - private SwitchCompatChangeListener switchCompatChangeListener; | ||
| 413 | - public void setonswitchCompatChangeListene(SwitchCompatChangeListener switchCompatChangeListener){ | ||
| 414 | - this.switchCompatChangeListener=switchCompatChangeListener; | ||
| 415 | - } | ||
| 416 | - | ||
| 417 | 406 | ||
| 418 | 407 | ||
| 419 | } | 408 | } |
app/src/main/res/layout/layout_player_controller_live_l.xml
| @@ -175,18 +175,6 @@ | @@ -175,18 +175,6 @@ | ||
| 175 | android:textColor="@android:color/white" | 175 | android:textColor="@android:color/white" |
| 176 | android:visibility="@{hasRate.get() ? View.VISIBLE : View.GONE}" /> | 176 | android:visibility="@{hasRate.get() ? View.VISIBLE : View.GONE}" /> |
| 177 | 177 | ||
| 178 | - <android.support.v7.widget.SwitchCompat | ||
| 179 | - android:id="@+id/barrage_top" | ||
| 180 | - android:layout_width="wrap_content" | ||
| 181 | - android:layout_height="wrap_content" | ||
| 182 | - android:layout_centerVertical="true" | ||
| 183 | - android:background="@null" | ||
| 184 | - android:textIsSelectable="false" | ||
| 185 | - android:layout_marginRight="10dp" | ||
| 186 | - android:layout_toLeftOf="@+id/rate" | ||
| 187 | - android:thumb="@drawable/switch_thumb" | ||
| 188 | - app:switchMinWidth="15dp" | ||
| 189 | - app:track="@drawable/switch_track" /> | ||
| 190 | 178 | ||
| 191 | </RelativeLayout> | 179 | </RelativeLayout> |
| 192 | 180 |