From 99938f6ed6b33bc1aae7bff8c3eb0ff9ac69f0d3 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 23 Dec 2022 14:57:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=81=8A=E5=A4=A9=E5=AE=A4?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=A4=A7=E4=BA=8E99=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E4=BC=9A=E6=B7=B7=E4=B9=B1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/live/adapter/LiveChatAdapter.java | 20 ++++++----- .../yunbao/live/views/LiveRoomViewHolder.java | 35 ++++++++++++++++++- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java index d0020fde6..f8f993610 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -47,6 +47,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Set; /** * Created by cxf on 2018/10/10. @@ -127,7 +128,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); - if (isSlideToBottom(recyclerView)) return; + if (isSlideToBottom(recyclerView) || dy == 0) return; mRecyclerViewScrolledDy = dy; } }); @@ -379,16 +380,22 @@ public class LiveChatAdapter extends RecyclerView.Adapter { @SuppressLint("NotifyDataSetChanged") public void insertItem(LiveChatBean bean) { - if (bean == null) { return; } int size = mList.size(); //设置最大展示99条消息 if (size == 100) { - mList.remove(0); + mList.subList(0, 50).clear(); + notifyItemRangeRemoved(0, 50); } mList.add(bean); + if (getItemCount() == 1 ) { + notifyDataSetChanged(); + } else { + notifyItemInserted(getItemCount()); + } + size = mList.size(); if (isSlideToBottom(mRecyclerView) || mRecyclerViewScrolledDy == 0) { scrollToBottom(); } else { @@ -401,11 +408,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { mPosition = size; } } - if (getItemCount() == 1) { - notifyDataSetChanged(); - } else { - notifyItemInserted(getItemCount()); - } + } @@ -447,6 +450,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { } public void scrollToBottom() { + mRecyclerViewScrolledDy = 0; if (mList.size() > 0) { mRecyclerView.smoothScrollToPosition(getItemCount() - 1); } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index e67759a00..8dee9b116 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -16,6 +16,7 @@ import android.text.TextUtils; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ViewOutlineProvider; @@ -157,6 +158,8 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.Timer; +import java.util.TimerTask; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; @@ -743,7 +746,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis msgNumber = (TextView) findViewById(R.id.room_msg_num); msgUserIcon = (RoundedImageView) findViewById(R.id.room_msg_user_icon); msgLayout = (ConstraintLayout) findViewById(R.id.room_msg_layout); - ViewClicksAntiShake.clicksAntiShake(msg, this::openChatWindow); + // ViewClicksAntiShake.clicksAntiShake(msg, this::openChatWindow); ViewClicksAntiShake.clicksAntiShake(msg2, this::openChatWindow); lt_trickery = (LinearLayout) findViewById(R.id.lt_trickery); @@ -925,6 +928,35 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis mViewMedal.setOnClickListener(this); findViewById(R.id.btn_close).setOnClickListener(this); mAvatar.setOnClickListener(this); + //点击侧边消息按钮,自动发消息,测试用的 + /*msg.setOnClickListener(new View.OnClickListener() { + long index=0; + public TimerTask createTask() { + return new TimerTask() { + @Override + public void run() { + LiveChatBean bean = new LiveChatBean(); + bean.setContent("test msg = "+index++); + bean.setUserNiceName("auto"); + handler.post(()->mLiveChatAdapter.insertItem(bean)); + } + }; + } + + Handler handler = new Handler(Looper.getMainLooper()); + private TimerTask task; + @Override + public void onClick(View v) { + if(task==null){ + task=createTask(); + new Timer().schedule(task, 0, 300); + }else{ + task.cancel(); + task=null; + } + } + }); +*/ findViewById(R.id.btn_votes).setOnClickListener(this); findViewById(R.id.btn_medal_rank).setOnClickListener(this); findViewById(R.id.btn_noble).setOnClickListener(this); @@ -3718,6 +3750,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis * 展示新消息提示 */ public void showNewMessage() { + if (newMessage.getVisibility() == View.VISIBLE) return; Locale locale = mContext.getResources().getConfiguration().locale; String language = locale.getLanguage(); ImgLoader.display(mContext, TextUtils.equals(language, "zh") ? R.mipmap.new_message_cn : R.mipmap.new_message_en, newMessage);