Search in sources :

Example 1 with SmoothLinearLayoutManager

use of com.moez.QKSMS.ui.view.SmoothLinearLayoutManager in project qksms by moezbhatti.

the class MessageListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_conversation, container, false);
    mRecyclerView = (MessageListRecyclerView) view.findViewById(R.id.conversation);
    mAdapter = new MessageListAdapter(mContext);
    mAdapter.setItemClickListener(this);
    mAdapter.setMultiSelectListener(this);
    mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        private long mLastMessageId = -1;

        @Override
        public void onChanged() {
            LinearLayoutManager manager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
            int position;
            if (mRowId != -1 && mCursor != null) {
                // Scroll to the position in the conversation for that message.
                position = SmsHelper.getPositionForMessageId(mCursor, "sms", mRowId, mAdapter.getColumnsMap());
                // Be sure to reset the row ID here---we only want to scroll to the message
                // the first time the cursor is loaded after the row ID is set.
                mRowId = -1;
            } else {
                position = mAdapter.getItemCount() - 1;
            }
            if (mAdapter.getCount() > 0) {
                MessageItem lastMessage = mAdapter.getItem(mAdapter.getCount() - 1);
                if (mLastMessageId >= 0 && mLastMessageId != lastMessage.getMessageId()) {
                    // Scroll to bottom only if a new message was inserted in this conversation
                    if (position != -1) {
                        manager.smoothScrollToPosition(mRecyclerView, null, position);
                    }
                }
                mLastMessageId = lastMessage.getMessageId();
            }
        }
    });
    mRecyclerView.setAdapter(mAdapter);
    mLayoutManager = new SmoothLinearLayoutManager(mContext);
    mLayoutManager.setStackFromEnd(true);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mComposeView = (ComposeView) view.findViewById(R.id.compose_view);
    mComposeView.setActivityLauncher(this);
    mComposeView.setLabel("MessageList");
    mRecyclerView.setComposeView(mComposeView);
    return view;
}
Also used : SmoothLinearLayoutManager(com.moez.QKSMS.ui.view.SmoothLinearLayoutManager) MessageListRecyclerView(com.moez.QKSMS.ui.view.MessageListRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) SmoothLinearLayoutManager(com.moez.QKSMS.ui.view.SmoothLinearLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MessageListRecyclerView(com.moez.QKSMS.ui.view.MessageListRecyclerView) ComposeView(com.moez.QKSMS.ui.view.ComposeView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ComposeView (com.moez.QKSMS.ui.view.ComposeView)1 MessageListRecyclerView (com.moez.QKSMS.ui.view.MessageListRecyclerView)1 SmoothLinearLayoutManager (com.moez.QKSMS.ui.view.SmoothLinearLayoutManager)1