From c8ba78f39b98a448b8d6b890d2a887ab68f8203d Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Tue, 27 Dec 2022 10:17:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=92=AD=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E5=AE=A4=E8=BF=98=E6=98=AF=E4=BC=9A=E5=8D=A1=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E8=87=AA=E5=8A=A8=E6=BB=9A=E5=8A=A8=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 | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 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 27341f9d0..73127c6e0 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -47,7 +47,6 @@ 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. @@ -68,6 +67,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { private int mRecyclerViewScrolledDy; private int mPosition; + private boolean isBottom = false; public LiveChatAdapter(Context context) { mContext = context; @@ -128,8 +128,23 @@ 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) || dy == 0) return; + if (isBottom && dy >= 0) return; + // Log.i(TAG, "onScrolled: " + dy); mRecyclerViewScrolledDy = dy; + isBottom = false; + } + + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + if (newState == 0 && isSlideToBottom(recyclerView)) { + // Log.i(TAG, "onScrollStateChanged: 到底部了"); + mRecyclerViewScrolledDy = 0; + isBottom = true; + } else if (newState == 0) { + // Log.i(TAG, "onScrollStateChanged: 不是底部"); + isBottom = false; + } } }); } @@ -383,7 +398,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { if (bean == null) { return; } - // Log.i(TAG, "insertItem: " + bean.getContent()); + // Log.i(TAG, "insertItem: " + bean.getContent()); int size = mList.size(); //设置最大展示99条消息 if (size == 100) { @@ -397,7 +412,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { notifyItemInserted(getItemCount()); } size = mList.size(); - if (isSlideToBottom(mRecyclerView) || mRecyclerViewScrolledDy == 0) { + if (isBottom || mRecyclerViewScrolledDy == 0) { scrollToBottom(); } else { Bus.get().post(new LiveAudienceEvent() @@ -451,10 +466,10 @@ public class LiveChatAdapter extends RecyclerView.Adapter { } public void scrollToBottom() { - mRecyclerViewScrolledDy = 0; if (mList.size() > 0) { mRecyclerView.smoothScrollToPosition(getItemCount() - 1); } + mRecyclerViewScrolledDy = 0; } public void scrollToAt() {