修复直播聊天室还是会卡不会自动滚动问题
This commit is contained in:
parent
d31af73479
commit
c8ba78f39b
@ -47,7 +47,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by cxf on 2018/10/10.
|
* Created by cxf on 2018/10/10.
|
||||||
@ -68,6 +67,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
|
|||||||
private int mRecyclerViewScrolledDy;
|
private int mRecyclerViewScrolledDy;
|
||||||
|
|
||||||
private int mPosition;
|
private int mPosition;
|
||||||
|
private boolean isBottom = false;
|
||||||
|
|
||||||
public LiveChatAdapter(Context context) {
|
public LiveChatAdapter(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@ -128,8 +128,23 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
super.onScrolled(recyclerView, dx, dy);
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
if (isSlideToBottom(recyclerView) || dy == 0) return;
|
if (isBottom && dy >= 0) return;
|
||||||
|
// Log.i(TAG, "onScrolled: " + dy);
|
||||||
mRecyclerViewScrolledDy = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -397,7 +412,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
|
|||||||
notifyItemInserted(getItemCount());
|
notifyItemInserted(getItemCount());
|
||||||
}
|
}
|
||||||
size = mList.size();
|
size = mList.size();
|
||||||
if (isSlideToBottom(mRecyclerView) || mRecyclerViewScrolledDy == 0) {
|
if (isBottom || mRecyclerViewScrolledDy == 0) {
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
} else {
|
} else {
|
||||||
Bus.get().post(new LiveAudienceEvent()
|
Bus.get().post(new LiveAudienceEvent()
|
||||||
@ -451,10 +466,10 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void scrollToBottom() {
|
public void scrollToBottom() {
|
||||||
mRecyclerViewScrolledDy = 0;
|
|
||||||
if (mList.size() > 0) {
|
if (mList.size() > 0) {
|
||||||
mRecyclerView.smoothScrollToPosition(getItemCount() - 1);
|
mRecyclerView.smoothScrollToPosition(getItemCount() - 1);
|
||||||
}
|
}
|
||||||
|
mRecyclerViewScrolledDy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scrollToAt() {
|
public void scrollToAt() {
|
||||||
|
Loading…
Reference in New Issue
Block a user