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 8 import android.view.LayoutInflater;
9 9 import android.view.View;
10 10 import android.view.ViewGroup;
11   -import android.widget.TextView;
12 11  
13 12 import com.bumptech.glide.Glide;
14 13 import com.cnlive.gundam.R;
... ... @@ -49,8 +48,7 @@ public class ConfigFragment extends Fragment implements View.OnClickListener {
49 48 }
50 49  
51 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 52 binding.configHeader.setOnClickListener(this);
55 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 100 showView.setChatView(false);
101 101 showView.setViewers(false);
102 102 binding.setIsShow(showView);
103   - binding.chatRecyclerView.setLayoutManager(new LinearLayoutManager(this));
104 103 chatItemList = new ArrayList<>();
  104 + initChatRoomRecycel();
105 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 115 private void initData() {
109 116 activityId = getIntent().getStringExtra("activityId");
110 117 channelId = getIntent().getStringExtra("channelId");
... ... @@ -408,8 +415,10 @@ public class StreamActivity extends BaseStreamActivity implements ChatConnect.Ch
408 415 } catch (Exception e) {
409 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 420 binding.setChatAdapter(chatAdapter);
  421 +
413 422 }
414 423  
415 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 8 import android.view.View;
9 9 import android.view.ViewGroup;
10 10  
  11 +import java.util.ArrayList;
11 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 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 26 this.mContext = mContext;
26   - this.activeInfoList = activeInfoList;
  27 + if(activeInfoList==null){this.activeInfoList = new ArrayList<>();}
27 28 this.layoutId = layoutId;
28 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 37 @Override
32 38 public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
33 39 LayoutInflater inflater = LayoutInflater.from(parent.getContext());
... ...
app/src/main/java/com/cnlive/gundam/user/activity/LoginActivity.java
1 1 package com.cnlive.gundam.user.activity;
2 2  
3   -import android.content.Context;
4 3 import android.databinding.DataBindingUtil;
5 4 import android.os.Bundle;
6   -import android.view.MotionEvent;
7   -import android.view.View;
8   -import android.view.inputmethod.InputMethodManager;
9 5  
10 6 import com.cnlive.gundam.R;
11 7 import com.cnlive.gundam.user.auth.AccountAuthenticatorActivity;
12 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 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 12 import com.cnlive.gundam.databinding.ItemListRightBinding;
13 13 import com.cnlive.gundam.video.model.MessageContent;
14 14  
  15 +import java.util.ArrayList;
15 16 import java.util.List;
16 17  
17 18 /**
... ... @@ -29,12 +30,17 @@ public class CommonAdapter&lt;T&gt; extends BaseAdapter {
29 30 this.mContext = context;
30 31 this.layoutId = layoutId;
31 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 44 @Override
39 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 43 */
44 44 public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback, MessageContentInfo.SendAndRecevieSucessCall {
45 45  
46   -
  46 + PlayerControllerView.SwitchCompatChangeListener switchCompatChangeListener;
47 47 private FragmentChatBinding fragmentChatBinding;
48 48 private ArrayList<GiftModle> giftArray;
49 49 private CommonAdapter<MessageContent> messageContentCommonAdapter;
... ... @@ -71,7 +71,6 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback
71 71  
72 72 }
73 73  
74   - PlayerControllerView.SwitchCompatChangeListener switchCompatChangeListener;
75 74 @Override
76 75 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
77 76 super.onViewCreated(view, savedInstanceState);
... ... @@ -126,15 +125,12 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback
126 125  
127 126 @Override
128 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 131 @Override
135 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 140 ChatUtil.disconnect(false);
145 141 }
146 142  
147   -
148   -
149   -
150   -
151 143 private void initChat() {
152 144 User activeAccountInfo = UserService.getInstance(getActivity()).getActiveAccountInfo();
153 145 String faceurl = activeAccountInfo.getFaceurl();
... ... @@ -165,6 +157,7 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback
165 157 private void initMessageAdapter() {
166 158 if (messageContentCommonAdapter == null)
167 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 37 private String JoinType = "joinType";
38 38 private String ChatRoom = "chatRoom";
39 39 private String giftType = "giftType";
  40 + private Gson gson;
40 41  
41 42  
42 43 public void setOnReceiveAndSendListener(BarrageLayout barrageLayout, String roomID, Context context, SendAndRecevieSucessCall sendAndRecevieSucessCall) {
43 44 this.roomId = roomID;
44 45 this.mContext = context;
  46 + gson = new Gson();
45 47 this.mSendAndRecevieSucessCall = sendAndRecevieSucessCall;
46 48 mHandler = new Handler();
47 49 messageContentArrayList = new ArrayList<>();
... ... @@ -63,7 +65,7 @@ public class MessageContentInfo {
63 65 public void run() {
64 66 try {
65 67  
66   - Gson gson = new Gson();
  68 +
67 69 CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class);
68 70 String messagecontent = cnMessageModle.getMessage().getContent();
69 71 String messageType = cnMessageModle.getType();
... ... @@ -115,7 +117,6 @@ public class MessageContentInfo {
115 117  
116 118 try {
117 119  
118   - Gson gson = new Gson();
119 120 CNMessageModle cnMessageModle = gson.fromJson(message.getContent(), CNMessageModle.class);
120 121 String messagecontent = cnMessageModle.getMessage().getContent();
121 122 String messageType = cnMessageModle.getType();
... ... @@ -169,8 +170,7 @@ public class MessageContentInfo {
169 170 @Override
170 171 public void onSuccess(int what, String extra) {
171 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 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 13 android:layout_height="wrap_content"
14 14 android:layout_centerInParent="true"
15 15 android:singleLine="true"
16   - android:text="我的"
  16 + android:text=""
17 17 android:textColor="@color/config_black_color"
18 18 android:textSize="22sp" />
19 19  
... ...