修复直播聊天室还是会卡不会自动滚动问题

This commit is contained in:
zlzw 2022-12-27 10:17:47 +08:00
parent d31af73479
commit c8ba78f39b

View File

@ -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() {