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 e0a9e4b1f..3fc05e41a 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -12,6 +12,7 @@ import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.style.ForegroundColorSpan; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -63,6 +64,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { private LinearLayoutManager mLayoutManager; private IMLoginModel model; + private int mRecyclerViewScrolledDx, mRecyclerViewScrolledDy; private int mPosition; @@ -121,6 +123,15 @@ public class LiveChatAdapter extends RecyclerView.Adapter { public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { mRecyclerView = recyclerView; mLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); + mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + mRecyclerViewScrolledDx = dx; + mRecyclerViewScrolledDy = dy; + Log.i(TAG, "onScrolled: dx = " + dx + ", dy = " + dy); + } + }); } class RedPackVh extends RecyclerView.ViewHolder { @@ -379,8 +390,15 @@ public class LiveChatAdapter extends RecyclerView.Adapter { mList.remove(0); } mList.add(bean); - - if (isSlideToBottom(mRecyclerView)) { + int sum = (mRecyclerView.computeVerticalScrollExtent() + mRecyclerView.computeVerticalScrollOffset()); + Log.i(TAG, "Extent=" + mRecyclerView.computeVerticalScrollExtent() + + "|Offset=" + mRecyclerView.computeVerticalScrollOffset() + + "|sum=" + sum + + "|Range=" + mRecyclerView.computeVerticalScrollRange() + + "|content=" + bean.getContent() + + ((sum >= mRecyclerView.computeVerticalScrollRange()) ? "" : "|停止滑动") + ); + if (isSlideToBottom(mRecyclerView) || mRecyclerViewScrolledDy == 0) { scrollToBottom(mRecyclerView); } else { Bus.get().post(new LiveAudienceEvent() @@ -409,6 +427,8 @@ public class LiveChatAdapter extends RecyclerView.Adapter { }); } + String TAG = "聊天测试"; + /** * 判断是否滚到底部 *