Search in sources :

Example 1 with RecyclerViewScrolledToBottomListener

use of chat.rocket.android.helper.RecyclerViewScrolledToBottomListener in project Rocket.Chat.Android by RocketChat.

the class RoomFragment method onSetupView.

@Override
protected void onSetupView() {
    RecyclerView listView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
    adapter = new MessageListAdapter(getContext());
    listView.setAdapter(adapter);
    adapter.setOnItemClickListener(this);
    adapter.setOnItemLongClickListener(this);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, true);
    listView.setLayoutManager(layoutManager);
    autoScrollManager = new RecyclerViewAutoScrollManager(layoutManager) {

        @Override
        protected void onAutoScrollMissed() {
            if (newMessageIndicatorManager != null) {
                presenter.onUnreadCount();
            }
        }
    };
    adapter.registerAdapterDataObserver(autoScrollManager);
    scrollListener = new LoadMoreScrollListener(layoutManager, 40) {

        @Override
        public void requestMoreItem() {
            presenter.loadMoreMessages();
        }
    };
    listView.addOnScrollListener(scrollListener);
    listView.addOnScrollListener(new RecyclerViewScrolledToBottomListener(layoutManager, 1, this::markAsReadIfNeeded));
    newMessageIndicatorManager = new AbstractNewMessageIndicatorManager() {

        @Override
        protected void onShowIndicator(int count, boolean onlyAlreadyShown) {
            if ((onlyAlreadyShown && unreadIndicator != null && unreadIndicator.isShown()) || !onlyAlreadyShown) {
                unreadIndicator = getUnreadCountIndicatorView(count);
                unreadIndicator.show();
            }
        }

        @Override
        protected void onHideIndicator() {
            if (unreadIndicator != null && unreadIndicator.isShown()) {
                unreadIndicator.dismiss();
            }
        }
    };
    setupSideMenu();
    setupMessageComposer();
    setupMessageActions();
}
Also used : LoadMoreScrollListener(chat.rocket.android.helper.LoadMoreScrollListener) RecyclerViewScrolledToBottomListener(chat.rocket.android.helper.RecyclerViewScrolledToBottomListener) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerViewAutoScrollManager(chat.rocket.android.helper.RecyclerViewAutoScrollManager) AbstractNewMessageIndicatorManager(chat.rocket.android.layouthelper.chatroom.AbstractNewMessageIndicatorManager) MessageListAdapter(chat.rocket.android.layouthelper.chatroom.MessageListAdapter)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LoadMoreScrollListener (chat.rocket.android.helper.LoadMoreScrollListener)1 RecyclerViewAutoScrollManager (chat.rocket.android.helper.RecyclerViewAutoScrollManager)1 RecyclerViewScrolledToBottomListener (chat.rocket.android.helper.RecyclerViewScrolledToBottomListener)1 AbstractNewMessageIndicatorManager (chat.rocket.android.layouthelper.chatroom.AbstractNewMessageIndicatorManager)1 MessageListAdapter (chat.rocket.android.layouthelper.chatroom.MessageListAdapter)1