Commit 94d8abb36b534d52fd8e184538de314294e44f2e

Authored by 陈硕
1 parent 07978eba

油壶聊天室的布局

app/src/main/java/com/cnlive/gundam/main/ui/fragment/ConfigFragment.java
@@ -8,7 +8,6 @@ import android.support.v4.app.Fragment; @@ -8,7 +8,6 @@ import android.support.v4.app.Fragment;
8 import android.view.LayoutInflater; 8 import android.view.LayoutInflater;
9 import android.view.View; 9 import android.view.View;
10 import android.view.ViewGroup; 10 import android.view.ViewGroup;
11 -import android.widget.TextView;  
12 11
13 import com.bumptech.glide.Glide; 12 import com.bumptech.glide.Glide;
14 import com.cnlive.gundam.R; 13 import com.cnlive.gundam.R;
@@ -49,8 +48,7 @@ public class ConfigFragment extends Fragment implements View.OnClickListener { @@ -49,8 +48,7 @@ public class ConfigFragment extends Fragment implements View.OnClickListener {
49 } 48 }
50 49
51 private void initUI() { 50 private void initUI() {
52 - TextView titleText = binding.getRoot().findViewById(R.id.toobar_tv);  
53 - if (titleText != null) titleText.setText("我 的"); 51 + binding.toobar.toobarTv.setText("我 的");
54 binding.configHeader.setOnClickListener(this); 52 binding.configHeader.setOnClickListener(this);
55 binding.message.setOnClickListener(this); 53 binding.message.setOnClickListener(this);
56 } 54 }
app/src/main/java/com/cnlive/gundam/stream/ui/activity/StreamActivity.java
@@ -100,11 +100,18 @@ public class StreamActivity extends BaseStreamActivity implements ChatConnect.Ch @@ -100,11 +100,18 @@ public class StreamActivity extends BaseStreamActivity implements ChatConnect.Ch
100 showView.setChatView(false); 100 showView.setChatView(false);
101 showView.setViewers(false); 101 showView.setViewers(false);
102 binding.setIsShow(showView); 102 binding.setIsShow(showView);
103 - binding.chatRecyclerView.setLayoutManager(new LinearLayoutManager(this));  
104 chatItemList = new ArrayList<>(); 103 chatItemList = new ArrayList<>();
  104 + initChatRoomRecycel();
105 timerUtil = new TimerUtil(this); 105 timerUtil = new TimerUtil(this);
106 } 106 }
107 107
  108 + private void initChatRoomRecycel() {
  109 + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
  110 + linearLayoutManager.setStackFromEnd(true);
  111 + binding.chatRecyclerView.setLayoutManager(linearLayoutManager);
  112 + chatAdapter = new SimpleAdapter(this, R.layout.item_chat, com.cnlive.gundam.BR.chat);
  113 + }
  114 +
108 private void initData() { 115 private void initData() {
109 activityId = getIntent().getStringExtra("activityId"); 116 activityId = getIntent().getStringExtra("activityId");
110 channelId = getIntent().getStringExtra("channelId"); 117 channelId = getIntent().getStringExtra("channelId");
@@ -408,8 +415,10 @@ public class StreamActivity extends BaseStreamActivity implements ChatConnect.Ch @@ -408,8 +415,10 @@ public class StreamActivity extends BaseStreamActivity implements ChatConnect.Ch
408 } catch (Exception e) { 415 } catch (Exception e) {
409 e.printStackTrace(); 416 e.printStackTrace();
410 } 417 }
411 - chatAdapter = new SimpleAdapter(this, chatItemList, R.layout.item_chat, com.cnlive.gundam.BR.chat); 418 +
  419 + chatAdapter.addItems(chatItemList);
412 binding.setChatAdapter(chatAdapter); 420 binding.setChatAdapter(chatAdapter);
  421 +
413 } 422 }
414 423
415 private void getOnlinePerson() { 424 private void getOnlinePerson() {
app/src/main/java/com/cnlive/gundam/stream/ui/adapter/SimpleAdapter.java
@@ -8,6 +8,7 @@ import android.view.LayoutInflater; @@ -8,6 +8,7 @@ import android.view.LayoutInflater;
8 import android.view.View; 8 import android.view.View;
9 import android.view.ViewGroup; 9 import android.view.ViewGroup;
10 10
  11 +import java.util.ArrayList;
11 import java.util.List; 12 import java.util.List;
12 13
13 /** 14 /**
@@ -21,13 +22,18 @@ public class SimpleAdapter&lt;T&gt; extends RecyclerView.Adapter&lt;SimpleAdapter.ViewHol @@ -21,13 +22,18 @@ public class SimpleAdapter&lt;T&gt; extends RecyclerView.Adapter&lt;SimpleAdapter.ViewHol
21 private int variableId; 22 private int variableId;
22 23
23 24
24 - public SimpleAdapter(Context mContext, List<T> activeInfoList, int layoutId, int variableId) { 25 + public SimpleAdapter(Context mContext, int layoutId, int variableId) {
25 this.mContext = mContext; 26 this.mContext = mContext;
26 - this.activeInfoList = activeInfoList; 27 + if(activeInfoList==null){this.activeInfoList = new ArrayList<>();}
27 this.layoutId = layoutId; 28 this.layoutId = layoutId;
28 this.variableId = variableId; 29 this.variableId = variableId;
29 } 30 }
30 31
  32 + public void addItems(List<T> items){
  33 + if(items == null) return ;
  34 + this.activeInfoList=items;
  35 + }
  36 +
31 @Override 37 @Override
32 public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 38 public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
33 LayoutInflater inflater = LayoutInflater.from(parent.getContext()); 39 LayoutInflater inflater = LayoutInflater.from(parent.getContext());
app/src/main/java/com/cnlive/gundam/user/activity/LoginActivity.java
1 package com.cnlive.gundam.user.activity; 1 package com.cnlive.gundam.user.activity;
2 2
3 -import android.content.Context;  
4 import android.databinding.DataBindingUtil; 3 import android.databinding.DataBindingUtil;
5 import android.os.Bundle; 4 import android.os.Bundle;
6 -import android.view.MotionEvent;  
7 -import android.view.View;  
8 -import android.view.inputmethod.InputMethodManager;  
9 5
10 import com.cnlive.gundam.R; 6 import com.cnlive.gundam.R;
11 import com.cnlive.gundam.user.auth.AccountAuthenticatorActivity; 7 import com.cnlive.gundam.user.auth.AccountAuthenticatorActivity;
12 import com.cnlive.gundam.user.fragment.LoginFragment; 8 import com.cnlive.gundam.user.fragment.LoginFragment;
13 -import com.cnlive.gundam.user.util.DevilUtil;  
14 9
15 10
16 /** 11 /**
@@ -26,20 +21,4 @@ public class LoginActivity extends AccountAuthenticatorActivity { @@ -26,20 +21,4 @@ public class LoginActivity extends AccountAuthenticatorActivity {
26 getSupportFragmentManager().beginTransaction().replace(R.id.login_fragment, LoginFragment.newInstance()).commit(); 21 getSupportFragmentManager().beginTransaction().replace(R.id.login_fragment, LoginFragment.newInstance()).commit();
27 } 22 }
28 23
29 - /**  
30 - * 隐藏软键盘  
31 - */  
32 - @Override  
33 - public boolean dispatchTouchEvent(MotionEvent ev){  
34 - // TODO Auto-generated method stub  
35 - if(ev.getAction()== MotionEvent.ACTION_DOWN){  
36 -  
37 - View v=getCurrentFocus();  
38 - if(DevilUtil.isShouldHideInput(v,ev)){  
39 - InputMethodManager im=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  
40 - DevilUtil.hideSoftInput(v.getWindowToken(),im);  
41 - }  
42 - }  
43 - return super.dispatchTouchEvent(ev);  
44 - }  
45 } 24 }
app/src/main/java/com/cnlive/gundam/video/adpter/CommonAdapter.java
@@ -12,6 +12,7 @@ import android.widget.LinearLayout; @@ -12,6 +12,7 @@ import android.widget.LinearLayout;
12 import com.cnlive.gundam.databinding.ItemListRightBinding; 12 import com.cnlive.gundam.databinding.ItemListRightBinding;
13 import com.cnlive.gundam.video.model.MessageContent; 13 import com.cnlive.gundam.video.model.MessageContent;
14 14
  15 +import java.util.ArrayList;
15 import java.util.List; 16 import java.util.List;
16 17
17 /** 18 /**
@@ -29,12 +30,17 @@ public class CommonAdapter&lt;T&gt; extends BaseAdapter { @@ -29,12 +30,17 @@ public class CommonAdapter&lt;T&gt; extends BaseAdapter {
29 this.mContext = context; 30 this.mContext = context;
30 this.layoutId = layoutId; 31 this.layoutId = layoutId;
31 this.variableId = variableId; 32 this.variableId = variableId;
  33 + this.mDataList= new ArrayList<>();
32 } 34 }
33 35
34 - public void setDataList(List<T> dataList){  
35 - this.mDataList= dataList; 36 + public void addItems(List<T> items){
  37 + if(items == null) return ;
  38 + this.mDataList=items;
  39 + notifyDataSetChanged();
36 } 40 }
37 41
  42 +
  43 +
38 @Override 44 @Override
39 public int getCount() { return mDataList.size(); } 45 public int getCount() { return mDataList.size(); }
40 46
app/src/main/java/com/cnlive/gundam/video/fragment/chat/ChatRoomFragment.java
@@ -43,7 +43,7 @@ import java.util.ArrayList; @@ -43,7 +43,7 @@ import java.util.ArrayList;
43 */ 43 */
44 public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback, MessageContentInfo.SendAndRecevieSucessCall { 44 public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback, MessageContentInfo.SendAndRecevieSucessCall {
45 45
46 - 46 + PlayerControllerView.SwitchCompatChangeListener switchCompatChangeListener;
47 private FragmentChatBinding fragmentChatBinding; 47 private FragmentChatBinding fragmentChatBinding;
48 private ArrayList<GiftModle> giftArray; 48 private ArrayList<GiftModle> giftArray;
49 private CommonAdapter<MessageContent> messageContentCommonAdapter; 49 private CommonAdapter<MessageContent> messageContentCommonAdapter;
@@ -71,7 +71,6 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback @@ -71,7 +71,6 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback
71 71
72 } 72 }
73 73
74 - PlayerControllerView.SwitchCompatChangeListener switchCompatChangeListener;  
75 @Override 74 @Override
76 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 75 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
77 super.onViewCreated(view, savedInstanceState); 76 super.onViewCreated(view, savedInstanceState);
@@ -126,15 +125,12 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback @@ -126,15 +125,12 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback
126 125
127 @Override 126 @Override
128 public void sentSucess(ArrayList<MessageContent> messageContents) { 127 public void sentSucess(ArrayList<MessageContent> messageContents) {
129 -  
130 - messageContentCommonAdapter.setDataList((messageContents));  
131 - ChatRoomFragment.this.fragmentChatBinding.setMessageAdapter(messageContentCommonAdapter); 128 + messageContentCommonAdapter.addItems((messageContents));
132 } 129 }
133 130
134 @Override 131 @Override
135 public void receaviceSucess(ArrayList<MessageContent> messageContents) { 132 public void receaviceSucess(ArrayList<MessageContent> messageContents) {
136 - messageContentCommonAdapter.setDataList((messageContents));  
137 - ChatRoomFragment.this.fragmentChatBinding.setMessageAdapter(messageContentCommonAdapter); 133 + messageContentCommonAdapter.addItems((messageContents));
138 } 134 }
139 135
140 136
@@ -144,10 +140,6 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback @@ -144,10 +140,6 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback
144 ChatUtil.disconnect(false); 140 ChatUtil.disconnect(false);
145 } 141 }
146 142
147 -  
148 -  
149 -  
150 -  
151 private void initChat() { 143 private void initChat() {
152 User activeAccountInfo = UserService.getInstance(getActivity()).getActiveAccountInfo(); 144 User activeAccountInfo = UserService.getInstance(getActivity()).getActiveAccountInfo();
153 String faceurl = activeAccountInfo.getFaceurl(); 145 String faceurl = activeAccountInfo.getFaceurl();
@@ -165,6 +157,7 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback @@ -165,6 +157,7 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback
165 private void initMessageAdapter() { 157 private void initMessageAdapter() {
166 if (messageContentCommonAdapter == null) 158 if (messageContentCommonAdapter == null)
167 messageContentCommonAdapter = new CommonAdapter<>(getActivity(), R.layout.item_list_right, BR.user); 159 messageContentCommonAdapter = new CommonAdapter<>(getActivity(), R.layout.item_list_right, BR.user);
  160 + ChatRoomFragment.this.fragmentChatBinding.setMessageAdapter(messageContentCommonAdapter);
168 161
169 } 162 }
170 163
app/src/main/java/com/cnlive/gundam/video/fragment/chat/MessageContentInfo.java
@@ -37,11 +37,13 @@ public class MessageContentInfo { @@ -37,11 +37,13 @@ public class MessageContentInfo {
37 private String JoinType = "joinType"; 37 private String JoinType = "joinType";
38 private String ChatRoom = "chatRoom"; 38 private String ChatRoom = "chatRoom";
39 private String giftType = "giftType"; 39 private String giftType = "giftType";
  40 + private Gson gson;
40 41
41 42
42 public void setOnReceiveAndSendListener(BarrageLayout barrageLayout, String roomID, Context context, SendAndRecevieSucessCall sendAndRecevieSucessCall) { 43 public void setOnReceiveAndSendListener(BarrageLayout barrageLayout, String roomID, Context context, SendAndRecevieSucessCall sendAndRecevieSucessCall) {
43 this.roomId = roomID; 44 this.roomId = roomID;
44 this.mContext = context; 45 this.mContext = context;
  46 + gson = new Gson();
45 this.mSendAndRecevieSucessCall = sendAndRecevieSucessCall; 47 this.mSendAndRecevieSucessCall = sendAndRecevieSucessCall;
46 mHandler = new Handler(); 48 mHandler = new Handler();
47 messageContentArrayList = new ArrayList<>(); 49 messageContentArrayList = new ArrayList<>();
@@ -63,7 +65,7 @@ public class MessageContentInfo { @@ -63,7 +65,7 @@ public class MessageContentInfo {
63 public void run() { 65 public void run() {
64 try { 66 try {
65 67
66 - Gson gson = new Gson(); 68 +
67 CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class); 69 CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class);
68 String messagecontent = cnMessageModle.getMessage().getContent(); 70 String messagecontent = cnMessageModle.getMessage().getContent();
69 String messageType = cnMessageModle.getType(); 71 String messageType = cnMessageModle.getType();
@@ -115,7 +117,6 @@ public class MessageContentInfo { @@ -115,7 +117,6 @@ public class MessageContentInfo {
115 117
116 try { 118 try {
117 119
118 - Gson gson = new Gson();  
119 CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class); 120 CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class);
120 String messagecontent = cnMessageModle.getMessage().getContent(); 121 String messagecontent = cnMessageModle.getMessage().getContent();
121 String messageType = cnMessageModle.getType(); 122 String messageType = cnMessageModle.getType();
@@ -169,8 +170,7 @@ public class MessageContentInfo { @@ -169,8 +170,7 @@ public class MessageContentInfo {
169 @Override 170 @Override
170 public void onSuccess(int what, String extra) { 171 public void onSuccess(int what, String extra) {
171 CNMessageModle cnMessageModle = new CNMessageModle(JoinType, new MessageInfo("", "", "", "", "")); 172 CNMessageModle cnMessageModle = new CNMessageModle(JoinType, new MessageInfo("", "", "", "", ""));
172 - Gson gson2 = new Gson();  
173 - String obj2 = gson2.toJson(cnMessageModle); 173 + String obj2 = gson.toJson(cnMessageModle);
174 ChatUtil.sendMessage(IChat.CHATROOM, roomId, obj2, onSendMessageListener); 174 ChatUtil.sendMessage(IChat.CHATROOM, roomId, obj2, onSendMessageListener);
175 } 175 }
176 176
app/src/main/res/layout/item_toolbar.xml
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 android:layout_height="wrap_content" 13 android:layout_height="wrap_content"
14 android:layout_centerInParent="true" 14 android:layout_centerInParent="true"
15 android:singleLine="true" 15 android:singleLine="true"
16 - android:text="我的" 16 + android:text=""
17 android:textColor="@color/config_black_color" 17 android:textColor="@color/config_black_color"
18 android:textSize="22sp" /> 18 android:textSize="22sp" />
19 19