diff --git a/uikit/src/main/java/cn/wildfire/chat/kit/conversationlist/ConversationListAdapter.java b/uikit/src/main/java/cn/wildfire/chat/kit/conversationlist/ConversationListAdapter.java index 1544f6e5..cf1c6cfd 100644 --- a/uikit/src/main/java/cn/wildfire/chat/kit/conversationlist/ConversationListAdapter.java +++ b/uikit/src/main/java/cn/wildfire/chat/kit/conversationlist/ConversationListAdapter.java @@ -55,7 +55,7 @@ public void updateStatusNotification(List statusNotification submit(statusNotifications, this.conversationInfos); } - private int headerCount() { + public int headerCount() { return isEmpty(this.statusNotifications) ? 0 : 1; } diff --git a/uikit/src/main/java/cn/wildfire/chat/kit/conversationlist/ConversationListFragment.java b/uikit/src/main/java/cn/wildfire/chat/kit/conversationlist/ConversationListFragment.java index 6475a4ed..48238c30 100644 --- a/uikit/src/main/java/cn/wildfire/chat/kit/conversationlist/ConversationListFragment.java +++ b/uikit/src/main/java/cn/wildfire/chat/kit/conversationlist/ConversationListFragment.java @@ -175,15 +175,15 @@ public void onChanged(Object o) { public void scrollToNextUnreadConversation() { int start = layoutManager.findFirstVisibleItemPosition(); - int end = layoutManager.findLastVisibleItemPosition(); int nextUnreadConversationPosition = adapter.getNextUnreadConversationPosition(start); - if (nextUnreadConversationPosition > 0) { - if (nextUnreadConversationPosition >= start && nextUnreadConversationPosition <= end) { - smoothScroller.setTargetPosition(nextUnreadConversationPosition); - layoutManager.startSmoothScroll(smoothScroller); - } else { - recyclerView.smoothScrollToPosition(nextUnreadConversationPosition); - } + // 支持循环滚动,后面没有未读会话时,从头开始找 + if (nextUnreadConversationPosition == -1 && start > adapter.headerCount()) { + nextUnreadConversationPosition = adapter.getNextUnreadConversationPosition(0); + } + + if (nextUnreadConversationPosition != -1) { + smoothScroller.setTargetPosition(nextUnreadConversationPosition); + layoutManager.startSmoothScroll(smoothScroller); } }