public void setAdapter(final RealmBasedRecyclerViewAdapter adapter) {
    this.adapter = adapter;
    recyclerView.setAdapter(adapter);
    if (swipeToDelete) {
      realmSimpleItemTouchHelperCallback.setAdapter(adapter);
    }

    if (adapter != null) {
      adapter.registerAdapterDataObserver(
          new RecyclerView.AdapterDataObserver() {
            @Override
            public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
              super.onItemRangeMoved(fromPosition, toPosition, itemCount);
              update();
            }

            @Override
            public void onItemRangeRemoved(int positionStart, int itemCount) {
              super.onItemRangeRemoved(positionStart, itemCount);
              update();
            }

            @Override
            public void onItemRangeInserted(int positionStart, int itemCount) {
              super.onItemRangeInserted(positionStart, itemCount);
              update();
            }

            @Override
            public void onItemRangeChanged(int positionStart, int itemCount) {
              super.onItemRangeChanged(positionStart, itemCount);
              update();
            }

            @Override
            public void onChanged() {
              super.onChanged();
              update();
            }

            private void update() {
              updateEmptyContentContainerVisibility(adapter);
            }
          });
      updateEmptyContentContainerVisibility(adapter);
    }
  }
  private void maybeFireLoadMore() {
    if (hasLoadMoreFired) {
      return;
    }
    if (!showShowLoadMore) {
      return;
    }

    final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int visibleItemCount = layoutManager.getChildCount();
    int totalItemCount = layoutManager.getItemCount();
    int firstVisibleItemPosition = findFirstVisibleItemPosition();

    if (totalItemCount == 0) {
      return;
    }

    if (firstVisibleItemPosition + visibleItemCount + bufferItems > totalItemCount) {
      if (onLoadMoreListener != null) {
        hasLoadMoreFired = true;
        onLoadMoreListener.onLoadMore(adapter.getLastItem());
      }
    }
  }