|  | @@ -5,6 +5,7 @@ import android.os.Bundle;
 | 
	
		
			
				|  |  |  import android.os.Handler;
 | 
	
		
			
				|  |  |  import android.os.Looper;
 | 
	
		
			
				|  |  |  import android.text.TextUtils;
 | 
	
		
			
				|  |  | +import android.util.Log;
 | 
	
		
			
				|  |  |  import android.view.LayoutInflater;
 | 
	
		
			
				|  |  |  import android.view.View;
 | 
	
		
			
				|  |  |  import android.view.ViewGroup;
 | 
	
	
		
			
				|  | @@ -17,6 +18,7 @@ import com.cooleshow.base.constanst.LoginStatusConstants;
 | 
	
		
			
				|  |  |  import com.cooleshow.base.event.LoginStatusEvent;
 | 
	
		
			
				|  |  |  import com.cooleshow.base.router.RouterPath;
 | 
	
		
			
				|  |  |  import com.cooleshow.base.utils.LogUtils;
 | 
	
		
			
				|  |  | +import com.cooleshow.base.widgets.TopSmoothScroller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import org.greenrobot.eventbus.EventBus;
 | 
	
		
			
				|  |  |  import org.greenrobot.eventbus.Subscribe;
 | 
	
	
		
			
				|  | @@ -76,11 +78,14 @@ public class ConversationListFragment extends Fragment implements BaseAdapter.On
 | 
	
		
			
				|  |  |      private ConversationListViewModel mConversationListViewModel;
 | 
	
		
			
				|  |  |      protected SmartRefreshLayout mRefreshLayout;
 | 
	
		
			
				|  |  |      protected Handler mHandler = new Handler(Looper.getMainLooper());
 | 
	
		
			
				|  |  | +    private LinearLayoutManager mLayoutManager;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |          mAdapter = onResolveAdapter();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private int targetUnReadPos = -1;//未读会话位置标记
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
	
		
			
				|  |  |          super.onCreate(savedInstanceState);
 | 
	
	
		
			
				|  | @@ -101,8 +106,8 @@ public class ConversationListFragment extends Fragment implements BaseAdapter.On
 | 
	
		
			
				|  |  |          mRefreshLayout = view.findViewById(R.id.rc_refresh);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          mAdapter.setItemClickListener(this);
 | 
	
		
			
				|  |  | -        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
 | 
	
		
			
				|  |  | -        mList.setLayoutManager(layoutManager);
 | 
	
		
			
				|  |  | +        mLayoutManager = new LinearLayoutManager(getActivity());
 | 
	
		
			
				|  |  | +        mList.setLayoutManager(mLayoutManager);
 | 
	
		
			
				|  |  |          mList.setAdapter(mAdapter);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          mNoticeContainerView = view.findViewById(R.id.rc_conversationlist_notice_container);
 | 
	
	
		
			
				|  | @@ -142,12 +147,12 @@ public class ConversationListFragment extends Fragment implements BaseAdapter.On
 | 
	
		
			
				|  |  |                  onConversationListRefresh(refreshLayout);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  | -        mRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
 | 
	
		
			
				|  |  | -            @Override
 | 
	
		
			
				|  |  | -            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
 | 
	
		
			
				|  |  | -                onConversationListLoadMore();
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        });
 | 
	
		
			
				|  |  | +//        mRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
 | 
	
		
			
				|  |  | +//            @Override
 | 
	
		
			
				|  |  | +//            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
 | 
	
		
			
				|  |  | +//                onConversationListLoadMore();
 | 
	
		
			
				|  |  | +//            }
 | 
	
		
			
				|  |  | +//        });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -188,6 +193,7 @@ public class ConversationListFragment extends Fragment implements BaseAdapter.On
 | 
	
		
			
				|  |  |              @Override
 | 
	
		
			
				|  |  |              public void onChanged(List<BaseUiConversation> uiConversations) {
 | 
	
		
			
				|  |  |                  RLog.d(TAG, "conversation list onChanged.");
 | 
	
		
			
				|  |  | +                targetUnReadPos = -1;
 | 
	
		
			
				|  |  |                  mAdapter.setDataCollection(uiConversations);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          });
 | 
	
	
		
			
				|  | @@ -229,6 +235,49 @@ public class ConversationListFragment extends Fragment implements BaseAdapter.On
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    public void findUnReadConversation() {
 | 
	
		
			
				|  |  | +        List<BaseUiConversation> data = mAdapter.getData();
 | 
	
		
			
				|  |  | +        if (data != null && data.size() > 0) {
 | 
	
		
			
				|  |  | +            int firstUnreadPos = -1;
 | 
	
		
			
				|  |  | +            for (int i = 0; i < data.size(); i++) {
 | 
	
		
			
				|  |  | +                BaseUiConversation baseUiConversation = data.get(i);
 | 
	
		
			
				|  |  | +                if (baseUiConversation.mCore != null) {
 | 
	
		
			
				|  |  | +                    int unreadMessageCount = baseUiConversation.mCore.getUnreadMessageCount();
 | 
	
		
			
				|  |  | +                    if (unreadMessageCount != 0) {
 | 
	
		
			
				|  |  | +                        if (firstUnreadPos == -1) {
 | 
	
		
			
				|  |  | +                            firstUnreadPos = i;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        if (i != targetUnReadPos && i > targetUnReadPos) {
 | 
	
		
			
				|  |  | +                            targetUnReadPos = i;
 | 
	
		
			
				|  |  | +                            break;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        if (i == data.size() - 1) {
 | 
	
		
			
				|  |  | +                            //如果遍历到最后一条,就返回第一条未读会话的位置
 | 
	
		
			
				|  |  | +                            targetUnReadPos = firstUnreadPos;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        scrollToPosition(targetUnReadPos);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void scrollToPosition(int pos) {
 | 
	
		
			
				|  |  | +        if (mLayoutManager != null) {
 | 
	
		
			
				|  |  | +            List<BaseUiConversation> data = mAdapter.getData();
 | 
	
		
			
				|  |  | +            if (data != null && data.size() > 0) {
 | 
	
		
			
				|  |  | +                if (pos < 0 || pos >= data.size()) {
 | 
	
		
			
				|  |  | +                    pos = 0;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                Log.i("pq", "result pos:" + pos);
 | 
	
		
			
				|  |  | +                final TopSmoothScroller mScroller = new TopSmoothScroller(getActivity());
 | 
	
		
			
				|  |  | +                mScroller.setTargetPosition(pos);
 | 
	
		
			
				|  |  | +                mLayoutManager.startSmoothScroll(mScroller);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 会话列表点击事件回调
 | 
	
		
			
				|  |  |       *
 |