Commit 747e659192492ad89c6159f18f9b247192db8e54
1 parent
964c0b2b
直播页面 调整布局
Showing
13 changed files
with
406 additions
and
39 deletions
app/src/main/java/com/cnlive/gundam/main/model/MsgEvent.java
0 → 100644
app/src/main/java/com/cnlive/gundam/main/ui/widget/RecyclerSpace.java
0 → 100644
| 1 | +package com.cnlive.gundam.main.ui.widget; | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | +import android.graphics.Canvas; | |
| 6 | +import android.graphics.Paint; | |
| 7 | +import android.graphics.Rect; | |
| 8 | +import android.graphics.drawable.Drawable; | |
| 9 | +import android.support.annotation.ColorRes; | |
| 10 | +import android.support.v7.widget.GridLayoutManager; | |
| 11 | +import android.support.v7.widget.LinearLayoutManager; | |
| 12 | +import android.support.v7.widget.RecyclerView; | |
| 13 | +import android.view.View; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * 创建:wukuiqing | |
| 17 | + * <p> | |
| 18 | + * 时间:2017/7/12 | |
| 19 | + * <p> | |
| 20 | + * 描述:分割线 | |
| 21 | + */ | |
| 22 | +public class RecyclerSpace extends RecyclerView.ItemDecoration { | |
| 23 | + private int space; | |
| 24 | + private int color = -1; | |
| 25 | + private Drawable mDivider; | |
| 26 | + private Paint mPaint; | |
| 27 | + private int type; | |
| 28 | + | |
| 29 | + public int getColor() { | |
| 30 | + return color; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public void setColor(@ColorRes int color) { | |
| 34 | + this.color = color; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public RecyclerSpace(int space) { | |
| 38 | + this.space = space; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public RecyclerSpace(int space, int color) { | |
| 42 | + this.space = space; | |
| 43 | + this.color = color; | |
| 44 | + mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
| 45 | + mPaint.setColor(color); | |
| 46 | + mPaint.setStyle(Paint.Style.FILL); | |
| 47 | + mPaint.setStrokeWidth(space * 2); | |
| 48 | + } | |
| 49 | + public RecyclerSpace(int space, int color,int type) { | |
| 50 | + this.space = space; | |
| 51 | + this.color = color; | |
| 52 | + mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
| 53 | + mPaint.setColor(color); | |
| 54 | + mPaint.setStyle(Paint.Style.FILL); | |
| 55 | + mPaint.setStrokeWidth(space * 2); | |
| 56 | + this.type=type; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public RecyclerSpace(int space, Drawable mDivider) { | |
| 60 | + this.space = space; | |
| 61 | + this.mDivider = mDivider; | |
| 62 | + } | |
| 63 | + | |
| 64 | + @Override | |
| 65 | + public void getItemOffsets(Rect outRect, View view, | |
| 66 | + RecyclerView parent, RecyclerView.State state) { | |
| 67 | + if (parent.getLayoutManager() != null) { | |
| 68 | + if (parent.getLayoutManager() instanceof LinearLayoutManager && !(parent.getLayoutManager() instanceof GridLayoutManager)) { | |
| 69 | + if (((LinearLayoutManager) parent.getLayoutManager()).getOrientation() == LinearLayoutManager.HORIZONTAL) { | |
| 70 | + outRect.set(space, 0, space, 0); | |
| 71 | + } else { | |
| 72 | + outRect.set(0, space, 0, space); | |
| 73 | + } | |
| 74 | + } else { | |
| 75 | + outRect.set(space, space, space, space); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { | |
| 83 | + super.onDraw(c, parent, state); | |
| 84 | + if (parent.getLayoutManager() != null) { | |
| 85 | + if (parent.getLayoutManager() instanceof LinearLayoutManager && !(parent.getLayoutManager() instanceof GridLayoutManager)) { | |
| 86 | + if (((LinearLayoutManager) parent.getLayoutManager()).getOrientation() == LinearLayoutManager.HORIZONTAL) { | |
| 87 | + drawHorizontal(c, parent); | |
| 88 | + } else { | |
| 89 | + drawVertical(c, parent); | |
| 90 | + } | |
| 91 | + } else { | |
| 92 | + if(type==0){ | |
| 93 | + drawGrideview(c, parent); | |
| 94 | + }else{ | |
| 95 | + drawGrideview1(c, parent); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + } | |
| 99 | + } | |
| 100 | + | |
| 101 | + //绘制纵向 item 分割线 | |
| 102 | + | |
| 103 | + private void drawVertical(Canvas canvas, RecyclerView parent) { | |
| 104 | + final int top = parent.getPaddingTop(); | |
| 105 | + final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom(); | |
| 106 | + final int childSize = parent.getChildCount(); | |
| 107 | + for (int i = 0; i < childSize; i++) { | |
| 108 | + final View child = parent.getChildAt(i); | |
| 109 | + RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); | |
| 110 | + final int left = child.getRight() + layoutParams.rightMargin; | |
| 111 | + final int right = left + space; | |
| 112 | + if (mDivider != null) { | |
| 113 | + mDivider.setBounds(left, top, right, bottom); | |
| 114 | + mDivider.draw(canvas); | |
| 115 | + } | |
| 116 | + if (mPaint != null) { | |
| 117 | + canvas.drawRect(left, top, right, bottom, mPaint); | |
| 118 | + } | |
| 119 | + } | |
| 120 | + } | |
| 121 | + | |
| 122 | + //绘制横向 item 分割线 | |
| 123 | + private void drawHorizontal(Canvas canvas, RecyclerView parent) { | |
| 124 | + int left = parent.getPaddingLeft(); | |
| 125 | + int right = parent.getMeasuredWidth() - parent.getPaddingRight(); | |
| 126 | + final int childSize = parent.getChildCount(); | |
| 127 | + for (int i = 0; i < childSize; i++) { | |
| 128 | + final View child = parent.getChildAt(i); | |
| 129 | + RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); | |
| 130 | + int top = child.getBottom() + layoutParams.bottomMargin; | |
| 131 | + int bottom = top + space; | |
| 132 | + if (mDivider != null) { | |
| 133 | + mDivider.setBounds(left, top, right, bottom); | |
| 134 | + mDivider.draw(canvas); | |
| 135 | + } | |
| 136 | + if (mPaint != null) { | |
| 137 | + canvas.drawRect(left, top, right, bottom, mPaint); | |
| 138 | + } | |
| 139 | + | |
| 140 | + } | |
| 141 | + } | |
| 142 | + | |
| 143 | + //绘制grideview item 分割线 不是填充满的 | |
| 144 | + private void drawGrideview(Canvas canvas, RecyclerView parent) { | |
| 145 | + GridLayoutManager linearLayoutManager = (GridLayoutManager) parent.getLayoutManager(); | |
| 146 | + int childSize = parent.getChildCount(); | |
| 147 | + int other = parent.getChildCount() / linearLayoutManager.getSpanCount() - 1; | |
| 148 | + if (other < 1) { | |
| 149 | + other = 1; | |
| 150 | + } | |
| 151 | + other = other * linearLayoutManager.getSpanCount(); | |
| 152 | + if (parent.getChildCount() < linearLayoutManager.getSpanCount()) { | |
| 153 | + other = parent.getChildCount(); | |
| 154 | + } | |
| 155 | + int top, bottom, left, right, spancount; | |
| 156 | + spancount = linearLayoutManager.getSpanCount() - 1; | |
| 157 | + for (int i = 0; i < childSize; i++) { | |
| 158 | + final View child = parent.getChildAt(i); | |
| 159 | + RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); | |
| 160 | + if (i < other) { | |
| 161 | + top = child.getBottom() + layoutParams.bottomMargin; | |
| 162 | + bottom = top + space; | |
| 163 | + left = (layoutParams.leftMargin + space) * (i + 1); | |
| 164 | + right = child.getMeasuredWidth() * (i + 1) + left + space * i; | |
| 165 | + if (mDivider != null) { | |
| 166 | + mDivider.setBounds(left, top, right, bottom); | |
| 167 | + mDivider.draw(canvas); | |
| 168 | + } | |
| 169 | + if (mPaint != null) { | |
| 170 | + canvas.drawRect(left, top, right, bottom, mPaint); | |
| 171 | + } | |
| 172 | + } | |
| 173 | + if (i != spancount) { | |
| 174 | + top = (layoutParams.topMargin + space) * (i / linearLayoutManager.getSpanCount() + 1); | |
| 175 | + bottom = (child.getMeasuredHeight() + space) * (i / linearLayoutManager.getSpanCount() + 1) + space; | |
| 176 | + left = child.getRight() + layoutParams.rightMargin; | |
| 177 | + right = left + space; | |
| 178 | + if (mDivider != null) { | |
| 179 | + mDivider.setBounds(left, top, right, bottom); | |
| 180 | + mDivider.draw(canvas); | |
| 181 | + } | |
| 182 | + if (mPaint != null) { | |
| 183 | + canvas.drawRect(left, top, right, bottom, mPaint); | |
| 184 | + } | |
| 185 | + } else { | |
| 186 | + spancount += 4; | |
| 187 | + } | |
| 188 | + } | |
| 189 | + } | |
| 190 | + | |
| 191 | + /***/ | |
| 192 | + private void drawGrideview1(Canvas canvas, RecyclerView parent) { | |
| 193 | + GridLayoutManager linearLayoutManager = (GridLayoutManager) parent.getLayoutManager(); | |
| 194 | + int childSize = parent.getChildCount(); | |
| 195 | + int top, bottom, left, right,spancount; | |
| 196 | + spancount=linearLayoutManager.getSpanCount(); | |
| 197 | + for (int i = 0; i < childSize; i++) { | |
| 198 | + final View child = parent.getChildAt(i); | |
| 199 | + //画横线 | |
| 200 | + RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); | |
| 201 | + top = child.getBottom() + layoutParams.bottomMargin; | |
| 202 | + bottom = top + space; | |
| 203 | + left = layoutParams.leftMargin+child.getPaddingLeft()+space; | |
| 204 | + right = child.getMeasuredWidth() * (i + 1) + left + space * i; | |
| 205 | + if (mDivider != null) { | |
| 206 | + mDivider.setBounds(left, top, right, bottom); | |
| 207 | + mDivider.draw(canvas); | |
| 208 | + } | |
| 209 | + if (mPaint != null) { | |
| 210 | + canvas.drawRect(left, top, right, bottom, mPaint); | |
| 211 | + } | |
| 212 | + //画竖线 | |
| 213 | + top = (layoutParams.topMargin + space) * (i / linearLayoutManager.getSpanCount() + 1); | |
| 214 | + bottom = (child.getMeasuredHeight() + space) * (i / linearLayoutManager.getSpanCount() + 1) + space; | |
| 215 | + left = child.getRight() + layoutParams.rightMargin; | |
| 216 | + right = left + space; | |
| 217 | + if (mDivider != null) { | |
| 218 | + mDivider.setBounds(left, top, right, bottom); | |
| 219 | + mDivider.draw(canvas); | |
| 220 | + } | |
| 221 | + if (mPaint != null) { | |
| 222 | + canvas.drawRect(left, top, right, bottom, mPaint); | |
| 223 | + } | |
| 224 | + | |
| 225 | + //画上缺失的线框 | |
| 226 | + if(i<spancount){ | |
| 227 | + top = child.getTop() + layoutParams.topMargin; | |
| 228 | + bottom = top + space; | |
| 229 | + left = (layoutParams.leftMargin + space) * (i + 1); | |
| 230 | + right = child.getMeasuredWidth() * (i + 1) + left + space * i; | |
| 231 | + if (mDivider != null) { | |
| 232 | + mDivider.setBounds(left, top, right, bottom); | |
| 233 | + mDivider.draw(canvas); | |
| 234 | + } | |
| 235 | + if (mPaint != null) { | |
| 236 | + canvas.drawRect(left, top, right, bottom, mPaint); | |
| 237 | + } | |
| 238 | + } | |
| 239 | + if(i%spancount==0){ | |
| 240 | + top = (layoutParams.topMargin + space) * (i / linearLayoutManager.getSpanCount() + 1); | |
| 241 | + bottom = (child.getMeasuredHeight() + space) * (i / linearLayoutManager.getSpanCount() + 1) + space; | |
| 242 | + left = child.getLeft() + layoutParams.leftMargin; | |
| 243 | + right = left + space; | |
| 244 | + if (mDivider != null) { | |
| 245 | + mDivider.setBounds(left, top, right, bottom); | |
| 246 | + mDivider.draw(canvas); | |
| 247 | + } | |
| 248 | + if (mPaint != null) { | |
| 249 | + canvas.drawRect(left, top, right, bottom, mPaint); | |
| 250 | + } | |
| 251 | + } | |
| 252 | + } | |
| 253 | + } | |
| 254 | +} | |
| 0 | 255 | \ No newline at end of file | ... | ... |
app/src/main/java/com/cnlive/gundam/video/activity/PlayerActivity.java
| ... | ... | @@ -9,13 +9,20 @@ import android.support.v7.app.AppCompatActivity; |
| 9 | 9 | import android.widget.Toast; |
| 10 | 10 | |
| 11 | 11 | import com.cnlive.gundam.R; |
| 12 | +import com.cnlive.gundam.main.model.MsgEvent; | |
| 12 | 13 | import com.cnlive.gundam.main.model.VideoListProgram; |
| 14 | +import com.cnlive.gundam.main.utils.SharedPreferencesHelper; | |
| 15 | +import com.cnlive.gundam.user.util.ToastUtil; | |
| 13 | 16 | import com.cnlive.gundam.video.fragment.PlayerLiveFragment; |
| 14 | 17 | import com.cnlive.gundam.video.fragment.PlayerUgcLiveFragment; |
| 15 | 18 | import com.cnlive.gundam.video.fragment.PlayerUgcVodFragment; |
| 16 | 19 | import com.cnlive.gundam.video.fragment.PlayerVodFragment; |
| 17 | 20 | import com.cnlive.gundam.video.utils.PlayerUtils; |
| 18 | 21 | |
| 22 | +import org.greenrobot.eventbus.EventBus; | |
| 23 | +import org.greenrobot.eventbus.Subscribe; | |
| 24 | +import org.greenrobot.eventbus.ThreadMode; | |
| 25 | + | |
| 19 | 26 | /** |
| 20 | 27 | * Created by gujun on 2017/4/5. |
| 21 | 28 | * screenDirect //0:竖向 1;横向 ugcLive ugcVod 播放页面用到了 |
| ... | ... | @@ -28,11 +35,14 @@ public class PlayerActivity extends AppCompatActivity { |
| 28 | 35 | //默认横屏 |
| 29 | 36 | private int screenDirect = 1; |
| 30 | 37 | |
| 38 | + | |
| 31 | 39 | @Override |
| 32 | 40 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 33 | 41 | super.onCreate(savedInstanceState); |
| 34 | 42 | setContentView(R.layout.activity_player); |
| 35 | 43 | addData(getIntent()); |
| 44 | + | |
| 45 | + | |
| 36 | 46 | } |
| 37 | 47 | |
| 38 | 48 | @Override |
| ... | ... | @@ -80,11 +90,20 @@ public class PlayerActivity extends AppCompatActivity { |
| 80 | 90 | |
| 81 | 91 | @Override |
| 82 | 92 | public void onBackPressed() { |
| 93 | + | |
| 83 | 94 | if (!(PlayerUtils.isPortrait(this)) && (fragment instanceof PlayerLiveFragment || fragment instanceof PlayerVodFragment)) { |
| 84 | 95 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 96 | + } else if (SharedPreferencesHelper.getInstance(this).getIntValue("ishow") == 0) { | |
| 97 | + EventBus.getDefault().post(new MsgEvent()); | |
| 85 | 98 | } else { |
| 86 | 99 | super.onBackPressed(); |
| 87 | 100 | } |
| 88 | 101 | } |
| 89 | 102 | |
| 103 | + | |
| 104 | + @Override | |
| 105 | + protected void onDestroy() { | |
| 106 | + super.onDestroy(); | |
| 107 | + EventBus.getDefault().unregister(this); | |
| 108 | + } | |
| 90 | 109 | } | ... | ... |
app/src/main/java/com/cnlive/gundam/video/adpter/CommonAdapter.java
| ... | ... | @@ -8,6 +8,7 @@ import android.view.View; |
| 8 | 8 | import android.view.ViewGroup; |
| 9 | 9 | import android.widget.BaseAdapter; |
| 10 | 10 | import android.widget.LinearLayout; |
| 11 | +import android.widget.RelativeLayout; | |
| 11 | 12 | |
| 12 | 13 | import com.cnlive.gundam.databinding.ItemListRightBinding; |
| 13 | 14 | import com.cnlive.gundam.video.model.MessageContent; |
| ... | ... | @@ -67,12 +68,12 @@ public class CommonAdapter<T> extends BaseAdapter { |
| 67 | 68 | if(((MessageContent) mDataList.get(position)).isSendInfo()){ |
| 68 | 69 | ItemListRightBinding binding1 = (ItemListRightBinding) binding; |
| 69 | 70 | LinearLayout rightLin = binding1.rightLin; |
| 70 | - LinearLayout leftLin = binding1.leftLin; | |
| 71 | + RelativeLayout leftLin = binding1.leftLin; | |
| 71 | 72 | leftLin.setVisibility(View.VISIBLE); |
| 72 | 73 | rightLin.setVisibility(View.INVISIBLE); |
| 73 | 74 | }else { |
| 74 | 75 | ItemListRightBinding binding1 = (ItemListRightBinding) binding; |
| 75 | - LinearLayout leftLin = binding1.leftLin; | |
| 76 | + RelativeLayout leftLin = binding1.leftLin; | |
| 76 | 77 | LinearLayout rightLin = binding1.rightLin; |
| 77 | 78 | rightLin.setVisibility(View.VISIBLE); |
| 78 | 79 | ... | ... |
app/src/main/java/com/cnlive/gundam/video/fragment/chat/ChatRoomFragment.java
| ... | ... | @@ -11,6 +11,7 @@ import android.support.v4.app.Fragment; |
| 11 | 11 | import android.support.v4.content.ContextCompat; |
| 12 | 12 | import android.support.v7.widget.GridLayoutManager; |
| 13 | 13 | import android.support.v7.widget.SwitchCompat; |
| 14 | +import android.util.Log; | |
| 14 | 15 | import android.view.LayoutInflater; |
| 15 | 16 | import android.view.View; |
| 16 | 17 | import android.view.ViewGroup; |
| ... | ... | @@ -21,6 +22,9 @@ import com.bumptech.glide.Glide; |
| 21 | 22 | import com.cnlive.gundam.BR; |
| 22 | 23 | import com.cnlive.gundam.R; |
| 23 | 24 | import com.cnlive.gundam.databinding.FragmentChatBinding; |
| 25 | +import com.cnlive.gundam.main.model.MsgEvent; | |
| 26 | +import com.cnlive.gundam.main.ui.widget.RecyclerSpace; | |
| 27 | +import com.cnlive.gundam.main.utils.SharedPreferencesHelper; | |
| 24 | 28 | import com.cnlive.gundam.user.auth.UserService; |
| 25 | 29 | import com.cnlive.gundam.user.model.User; |
| 26 | 30 | import com.cnlive.gundam.user.util.InputUtil; |
| ... | ... | @@ -34,10 +38,14 @@ import com.cnlive.gundam.video.model.MessageContent; |
| 34 | 38 | import com.cnlive.libs.util.chat.ChatUtil; |
| 35 | 39 | import com.cnlive.libs.util.chat.base.IChat; |
| 36 | 40 | import com.cnlive.libs.util.chat.model.CNUserInfo; |
| 41 | +import com.cnlive.libs.util.data.okhttpUtil.utils.L; | |
| 37 | 42 | import com.cnlive.libs.video.barrage.BarrageLayout; |
| 38 | 43 | |
| 39 | -import java.util.ArrayList; | |
| 44 | +import org.greenrobot.eventbus.EventBus; | |
| 45 | +import org.greenrobot.eventbus.Subscribe; | |
| 46 | +import org.greenrobot.eventbus.ThreadMode; | |
| 40 | 47 | |
| 48 | +import java.util.ArrayList; | |
| 41 | 49 | |
| 42 | 50 | |
| 43 | 51 | /** |
| ... | ... | @@ -82,23 +90,25 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback |
| 82 | 90 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 83 | 91 | super.onViewCreated(view, savedInstanceState); |
| 84 | 92 | initListener(); |
| 93 | + EventBus.getDefault().register(this); | |
| 85 | 94 | initDate(); |
| 86 | 95 | initGift(); |
| 87 | 96 | int checkCallPhonePermission = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_PHONE_STATE); |
| 88 | 97 | if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) { |
| 89 | 98 | requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, PERMISSION_REQUEST_CODE); |
| 90 | - }else{ | |
| 99 | + } else { | |
| 91 | 100 | initChat(); |
| 92 | 101 | } |
| 93 | 102 | } |
| 103 | + | |
| 94 | 104 | @Override |
| 95 | 105 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| 96 | 106 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 97 | - if(requestCode == PERMISSION_REQUEST_CODE){ | |
| 107 | + if (requestCode == PERMISSION_REQUEST_CODE) { | |
| 98 | 108 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
| 99 | 109 | initChat(); |
| 100 | 110 | } else { |
| 101 | - ToastUtil.show(getActivity(),"使用聊天功能,请通过权限审核"); | |
| 111 | + ToastUtil.show(getActivity(), "使用聊天功能,请通过权限审核"); | |
| 102 | 112 | } |
| 103 | 113 | } |
| 104 | 114 | } |
| ... | ... | @@ -121,6 +131,8 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback |
| 121 | 131 | } |
| 122 | 132 | } |
| 123 | 133 | }); |
| 134 | + | |
| 135 | + | |
| 124 | 136 | } |
| 125 | 137 | |
| 126 | 138 | @BindingAdapter("android:src") |
| ... | ... | @@ -131,7 +143,9 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback |
| 131 | 143 | @BindingAdapter({"imageUrl"}) |
| 132 | 144 | public static void loadImage(ImageView imageView, String url) { |
| 133 | 145 | if (url == null) { |
| 134 | - imageView.setImageResource(R.mipmap.ic_launcher); | |
| 146 | +// imageView.setImageResource(R.mipmap.ic_launcher); | |
| 147 | + | |
| 148 | + Glide.with(imageView.getContext()).load("https://yweb0.cnliveimg.com/main/cnlive/150819151803915_969.jpg").error(R.mipmap.ic_launcher).into(imageView); | |
| 135 | 149 | } else { |
| 136 | 150 | Glide.with(imageView.getContext()).load(url).error(R.mipmap.ic_launcher).into(imageView); |
| 137 | 151 | } |
| ... | ... | @@ -143,11 +157,11 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback |
| 143 | 157 | } |
| 144 | 158 | |
| 145 | 159 | |
| 146 | - | |
| 147 | 160 | @Override |
| 148 | 161 | public void onDestroy() { |
| 149 | 162 | super.onDestroy(); |
| 150 | 163 | ChatUtil.disconnect(false); |
| 164 | + EventBus.getDefault().unregister(this); | |
| 151 | 165 | } |
| 152 | 166 | |
| 153 | 167 | private void initChat() { |
| ... | ... | @@ -178,11 +192,14 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback |
| 178 | 192 | @Override |
| 179 | 193 | public void onClick(View view) { |
| 180 | 194 | int i = View.INVISIBLE == fragmentChatBinding.rlGift.getVisibility() ? View.VISIBLE : View.INVISIBLE; |
| 195 | + SharedPreferencesHelper.getInstance(getActivity()).setValue("ishow",i); | |
| 181 | 196 | fragmentChatBinding.rlGift.setVisibility(i); |
| 182 | 197 | } |
| 183 | 198 | }); |
| 184 | 199 | GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 6); |
| 185 | 200 | fragmentChatBinding.recyclerGift.setLayoutManager(gridLayoutManager); |
| 201 | + fragmentChatBinding.recyclerGift.addItemDecoration(new RecyclerSpace(10)); | |
| 202 | + | |
| 186 | 203 | fragmentChatBinding.setGiftAdapter(new GiftAdapter(roomId, getActivity(), giftArray, R.layout.fragment_gift_receycel, BR.dataBean)); |
| 187 | 204 | } |
| 188 | 205 | |
| ... | ... | @@ -222,20 +239,22 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback |
| 222 | 239 | barrageBottom(); |
| 223 | 240 | initMessageAdapter(); |
| 224 | 241 | messageContentInfo = new MessageContentInfo(); |
| 225 | - messageContentInfo.setOnReceiveAndSendListener( roomId, getActivity(), ChatRoomFragment.this); | |
| 242 | + messageContentInfo.setOnReceiveAndSendListener(roomId, getActivity(), ChatRoomFragment.this); | |
| 226 | 243 | } |
| 227 | 244 | |
| 228 | 245 | |
| 229 | 246 | public void giftItem(int postion) { |
| 230 | 247 | fragmentChatBinding.rlGift.setVisibility(View.INVISIBLE); |
| 231 | - messageContents.add(new MessageContent(messageContents.get(0).getName(),"送了" + gitName[postion]+":",messageContents.get(0).getIcon(),false)); | |
| 248 | + | |
| 249 | + messageContents.add(new MessageContent(messageContents.get(0).getName(), "送了" + gitName[postion] + ":", messageContents.get(0).getIcon(), false)); | |
| 232 | 250 | messageContentCommonAdapter.addItems((messageContents)); |
| 233 | 251 | } |
| 234 | 252 | |
| 235 | 253 | ArrayList<MessageContent> messageContents; |
| 254 | + | |
| 236 | 255 | @Override |
| 237 | 256 | public void onchat(ArrayList<MessageContent> messageContents) { |
| 238 | - this.messageContents=messageContents; | |
| 257 | + this.messageContents = messageContents; | |
| 239 | 258 | messageContentCommonAdapter.addItems((messageContents)); |
| 240 | 259 | |
| 241 | 260 | } |
| ... | ... | @@ -244,4 +263,13 @@ public class ChatRoomFragment extends Fragment implements InputUtil.SendCallback |
| 244 | 263 | public void onbarrage(BarrageBaseMessage barrageBaseMessage) { |
| 245 | 264 | barrageLayout.addMessage(barrageBaseMessage); |
| 246 | 265 | } |
| 266 | + | |
| 267 | + //在注册了的Activity中,声明处理事件的方法 | |
| 268 | + @Subscribe(threadMode = ThreadMode.MAIN) //第2步:注册一个在后台线程执行的方法,用于接收事件 | |
| 269 | + public void onUserEvent(MsgEvent event) { | |
| 270 | + | |
| 271 | + fragmentChatBinding.rlGift.setVisibility(View.INVISIBLE); | |
| 272 | + SharedPreferencesHelper.getInstance(getActivity()).setValue("ishow",4); | |
| 273 | + } | |
| 274 | + | |
| 247 | 275 | } | ... | ... |
app/src/main/java/com/cnlive/gundam/video/fragment/chat/MessageContentInfo.java
| ... | ... | @@ -67,9 +67,9 @@ public class MessageContentInfo { |
| 67 | 67 | messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), ": 送了" + messagecontent, message.getUserInfo().getHeadUrl(), true)); |
| 68 | 68 | } else if (messageType.equals(ChatRoom)) { |
| 69 | 69 | if (message.getUserInfo().getUserId().equals(ChatUtil.getCurrentUserInfo().getUserId())) { |
| 70 | - messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), messagecontent + " :", message.getUserInfo().getHeadUrl(), false)); | |
| 70 | + messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), messagecontent + " : ", message.getUserInfo().getHeadUrl(), false)); | |
| 71 | 71 | } else { |
| 72 | - 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)); | |
| 73 | 73 | } |
| 74 | 74 | if (onChatListener != null) { |
| 75 | 75 | onChatListener.onbarrage(new BarrageBaseMessage(message.getUserInfo().getUserName(), messagecontent, "")); |
| ... | ... | @@ -85,7 +85,7 @@ public class MessageContentInfo { |
| 85 | 85 | if (onChatListener != null) { |
| 86 | 86 | onChatListener.onbarrage(new BarrageBaseMessage(message.getUserInfo().getUserName(), "来了", "")); |
| 87 | 87 | } |
| 88 | - messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), ": " + "来了", message.getUserInfo().getHeadUrl(), true)); | |
| 88 | + messageContentArrayList.add(new MessageContent(message.getUserInfo().getUserName(), " : " + "来了", message.getUserInfo().getHeadUrl(), true)); | |
| 89 | 89 | } |
| 90 | 90 | if (onChatListener != null) { |
| 91 | 91 | onChatListener.onchat(messageContentArrayList); |
| ... | ... | @@ -112,7 +112,7 @@ public class MessageContentInfo { |
| 112 | 112 | String messageType = cnMessageModle.getType(); |
| 113 | 113 | if (messageType.equals(ChatRoom)) { |
| 114 | 114 | onChatListener.onbarrage(new BarrageBaseMessage(message.getUserInfo().getUserName(), messagecontent, "")); |
| 115 | - 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)); | |
| 116 | 116 | onChatListener.onchat(messageContentArrayList); |
| 117 | 117 | } |
| 118 | 118 | } catch (Exception e) { | ... | ... |
app/src/main/res/drawable/chat_gift_bg.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + android:shape="rectangle" | |
| 4 | + android:useLevel="false"> | |
| 5 | + <solid android:color="#454543" /> | |
| 6 | + <size android:height="24dp" /> | |
| 7 | + <corners | |
| 8 | + android:bottomLeftRadius="8dp" | |
| 9 | + android:bottomRightRadius="8dp" | |
| 10 | + android:topLeftRadius="8dp" | |
| 11 | + android:topRightRadius="8dp" /> <!-- 设置四个角的半径 --> | |
| 12 | + | |
| 13 | +</shape> | |
| 0 | 14 | \ No newline at end of file | ... | ... |
app/src/main/res/drawable/switch_track_dan_off.xml
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | 2 | |
| 3 | 3 | <shape xmlns:android="http://schemas.android.com/apk/res/android"> |
| 4 | - <solid android:color="#CC000000" /> | |
| 5 | - <corners android:radius="9dp" /> | |
| 4 | + <solid android:color="#555756" /> | |
| 5 | + | |
| 6 | + | |
| 7 | + <corners android:radius="30dp" /> | |
| 6 | 8 | <size |
| 7 | 9 | android:height="18dp" /> |
| 8 | 10 | <stroke | ... | ... |
app/src/main/res/drawable/switch_track_dan_on.xml
app/src/main/res/layout/fragment_chat.xml
| ... | ... | @@ -38,9 +38,11 @@ |
| 38 | 38 | android:id="@+id/edit_layout" |
| 39 | 39 | android:layout_width="match_parent" |
| 40 | 40 | android:layout_height="50dp" |
| 41 | + android:background="#555756" | |
| 42 | + android:orientation="horizontal" | |
| 41 | 43 | android:layout_alignParentBottom="true" |
| 42 | - android:background="#e0000000" | |
| 43 | - android:orientation="horizontal"> | |
| 44 | + android:layout_alignParentLeft="true" | |
| 45 | + android:layout_alignParentStart="true"> | |
| 44 | 46 | |
| 45 | 47 | <ImageView |
| 46 | 48 | android:id="@+id/sendMessage" |
| ... | ... | @@ -83,6 +85,7 @@ |
| 83 | 85 | android:visibility="invisible"> |
| 84 | 86 | |
| 85 | 87 | <android.support.v7.widget.RecyclerView |
| 88 | + android:padding="5dp" | |
| 86 | 89 | android:id="@+id/recycler_gift" |
| 87 | 90 | android:layout_width="match_parent" |
| 88 | 91 | android:layout_height="wrap_content" | ... | ... |
app/src/main/res/layout/fragment_gift_receycel.xml
app/src/main/res/layout/fragment_player_live.xml
| ... | ... | @@ -21,7 +21,7 @@ |
| 21 | 21 | |
| 22 | 22 | <RelativeLayout |
| 23 | 23 | android:id="@+id/contentLayout" |
| 24 | - android:background="@android:color/black" | |
| 24 | + android:background="#282828" | |
| 25 | 25 | android:layout_width="match_parent" |
| 26 | 26 | android:layout_height="match_parent" |
| 27 | 27 | android:layout_below="@+id/videoView"> | ... | ... |
app/src/main/res/layout/item_list_right.xml
| ... | ... | @@ -11,64 +11,98 @@ |
| 11 | 11 | </data> |
| 12 | 12 | |
| 13 | 13 | <RelativeLayout |
| 14 | + | |
| 14 | 15 | android:layout_width="match_parent" |
| 15 | - android:layout_height="match_parent"> | |
| 16 | + android:layout_height="wrap_content" | |
| 17 | + android:padding="10dp"> | |
| 16 | 18 | |
| 17 | - <LinearLayout | |
| 19 | + <RelativeLayout | |
| 18 | 20 | android:id="@+id/left_lin" |
| 19 | - | |
| 20 | 21 | android:layout_width="wrap_content" |
| 21 | 22 | android:layout_height="50dp" |
| 22 | - android:orientation="horizontal"> | |
| 23 | + android:layout_alignParentLeft="true" | |
| 24 | + android:background="@drawable/chat_gift_bg" | |
| 23 | 25 | |
| 24 | - <com.cnlive.gundam.user.view.CircleImageView | |
| 25 | - android:layout_width="20dp" | |
| 26 | - android:layout_height="20dp" | |
| 27 | - app:imageUrl="@{user.icon}"/> | |
| 26 | + android:paddingBottom="5dp" | |
| 27 | + android:paddingLeft="10dp" | |
| 28 | + android:paddingRight="10dp" | |
| 29 | + android:paddingTop="5dp"> | |
| 28 | 30 | |
| 29 | - <TextView | |
| 31 | + <ImageView | |
| 32 | + android:id="@+id/iv_left_user_icon" | |
| 30 | 33 | android:layout_width="wrap_content" |
| 31 | 34 | android:layout_height="wrap_content" |
| 32 | - android:textColor="@android:color/white" | |
| 33 | - android:text="@{user.name}" /> | |
| 35 | + android:layout_centerVertical="true" | |
| 36 | + app:imageUrl="@{user.icon}" /> | |
| 34 | 37 | |
| 35 | - <TextView | |
| 38 | + <LinearLayout | |
| 36 | 39 | android:layout_width="wrap_content" |
| 37 | 40 | android:layout_height="wrap_content" |
| 38 | - android:textColor="@android:color/white" | |
| 39 | - android:text="@{user.messaage}" /> | |
| 40 | - </LinearLayout> | |
| 41 | + android:layout_marginLeft="10dp" | |
| 42 | + android:layout_toRightOf="@+id/iv_left_user_icon" | |
| 43 | + android:orientation="vertical"> | |
| 44 | + | |
| 45 | + <TextView | |
| 46 | + android:id="@+id/tv_left_user_name" | |
| 47 | + android:layout_width="wrap_content" | |
| 48 | + android:layout_height="wrap_content" | |
| 49 | + android:text="@{user.name}" | |
| 50 | + android:textColor="@android:color/white" /> | |
| 51 | + | |
| 52 | + <TextView | |
| 53 | + android:id="@+id/tv_left_user_mewssage" | |
| 54 | + android:layout_width="wrap_content" | |
| 55 | + android:layout_height="wrap_content" | |
| 56 | + android:layout_marginTop="5dp" | |
| 57 | + android:text="@{user.messaage}" | |
| 58 | + android:textColor="@android:color/white" /> | |
| 59 | + </LinearLayout> | |
| 60 | + | |
| 61 | + | |
| 62 | + </RelativeLayout> | |
| 41 | 63 | |
| 42 | 64 | |
| 43 | 65 | |
| 44 | 66 | <LinearLayout |
| 45 | 67 | android:id="@+id/right_lin" |
| 68 | + android:background="@drawable/chat_gift_bg" | |
| 46 | 69 | |
| 70 | + android:paddingBottom="5dp" | |
| 71 | + android:paddingLeft="10dp" | |
| 72 | + android:paddingRight="10dp" | |
| 73 | + android:paddingTop="5dp" | |
| 47 | 74 | android:layout_alignParentRight="true" |
| 48 | 75 | android:layout_width="wrap_content" |
| 49 | 76 | android:layout_height="50dp" |
| 50 | 77 | android:orientation="horizontal"> |
| 51 | 78 | |
| 52 | 79 | <TextView |
| 80 | + android:layout_gravity="center_vertical" | |
| 81 | + android:layout_marginRight="10dp" | |
| 53 | 82 | android:layout_width="wrap_content" |
| 54 | 83 | android:layout_height="wrap_content" |
| 55 | 84 | android:textColor="@android:color/white" |
| 56 | 85 | android:text="@{user.messaage}" /> |
| 57 | 86 | <TextView |
| 87 | + android:layout_gravity="center_vertical" | |
| 88 | + android:visibility="gone" | |
| 58 | 89 | android:layout_width="wrap_content" |
| 59 | 90 | android:layout_height="wrap_content" |
| 60 | 91 | android:textColor="@android:color/white" |
| 61 | 92 | android:text="@{user.name}" /> |
| 62 | 93 | |
| 63 | - <com.cnlive.gundam.user.view.CircleImageView | |
| 64 | - android:layout_width="20dp" | |
| 65 | - android:layout_height="20dp" | |
| 94 | + <ImageView | |
| 95 | + android:layout_gravity="center_vertical" | |
| 96 | + android:layout_width="wrap_content" | |
| 97 | + android:layout_height="wrap_content" | |
| 66 | 98 | app:imageUrl="@{user.icon}" |
| 67 | 99 | /> |
| 68 | 100 | |
| 69 | 101 | </LinearLayout> |
| 70 | 102 | |
| 71 | 103 | |
| 104 | + | |
| 105 | + | |
| 72 | 106 | </RelativeLayout> |
| 73 | 107 | |
| 74 | 108 | </layout> |
| 75 | 109 | \ No newline at end of file | ... | ... |