public void setupToC(final Page page, Site site, boolean firstPage) {
    tocProgress.setVisibility(View.GONE);
    tocList.setVisibility(View.VISIBLE);

    headerView.setText(Html.fromHtml(page.getDisplayTitle()));
    headerView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            scrollToSection(page.getSections().get(0));
            wasClicked = true;
            funnel.logClick(0, page.getTitle().getDisplayText());
            hide();
          }
        });

    tocList.setAdapter(new ToCAdapter(page), site.getLanguageCode());
    tocList.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Section section = (Section) parent.getAdapter().getItem(position);
            scrollToSection(section);
            wasClicked = true;
            funnel.logClick(position, section.getHeading());
            hide();
          }
        });

    funnel =
        new ToCInteractionFunnel(
            WikipediaApp.getInstance(),
            site,
            page.getPageProperties().getPageId(),
            tocList.getAdapter().getCount());

    if (!page.isMainPage() && !firstPage) {
      if (WikipediaApp.getInstance().getOnboardingStateMachine().isTocTutorialEnabled()) {
        showTocOnboarding();
      }
    }
  }
  public ToCHandler(
      final AppCompatActivity activity,
      final WikiDrawerLayout slidingPane,
      final CommunicationBridge bridge) {
    this.parentActivity = activity;
    this.bridge = bridge;
    this.slidingPane = slidingPane;

    this.tocList = (ConfigurableListView) slidingPane.findViewById(R.id.page_toc_list);
    ((FrameLayout.LayoutParams) tocList.getLayoutParams())
        .setMargins(0, getContentTopOffsetPx(activity), 0, 0);
    this.tocProgress = (ProgressBar) slidingPane.findViewById(R.id.page_toc_in_progress);

    bridge.addListener(
        "currentSectionResponse",
        new CommunicationBridge.JSEventListener() {
          @Override
          public void onMessage(String messageType, JSONObject messagePayload) {
            int sectionID = messagePayload.optInt("sectionID");
            Log.d("Wikipedia", "current section is " + sectionID);
            if (tocList.getAdapter() == null) {
              return;
            }
            int itemToSelect = 0;
            // Find the list item that corresponds to the returned sectionID.
            // Start with index 1 of the list adapter, since index 0 is the header view,
            // and won't have a Section object associated with it.
            // And end with the second-to-last section, since the last section is the
            // artificial Read More section, and unknown to the WebView.
            // The lead section (id 0) will automatically fall through the loop.
            for (int i = 1; i < tocList.getAdapter().getCount() - 1; i++) {
              if (((Section) tocList.getAdapter().getItem(i)).getId() <= sectionID) {
                itemToSelect = i;
              } else {
                break;
              }
            }
            tocList.setItemChecked(itemToSelect, true);
            tocList.smoothScrollToPosition(itemToSelect);
          }
        });

    headerView =
        (TextView)
            LayoutInflater.from(tocList.getContext())
                .inflate(R.layout.header_toc_list, null, false);
    tocList.addHeaderView(headerView);

    // create a dummy funnel, in case the drawer is pulled out before a page is loaded.
    funnel =
        new ToCInteractionFunnel(
            WikipediaApp.getInstance(), WikipediaApp.getInstance().getSite(), 0, 0);

    slidingPane.setDrawerListener(
        new DrawerLayout.SimpleDrawerListener() {
          private boolean sectionRequested = false;

          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            parentActivity.supportInvalidateOptionsMenu();
            funnel.logOpen();
            wasClicked = false;
          }

          @Override
          public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            parentActivity.supportInvalidateOptionsMenu();
            if (!wasClicked) {
              funnel.logClose();
            }
            sectionRequested = false;
          }

          @Override
          public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
            // make sure the ActionBar is showing
            ((PageActivity) parentActivity).showToolbar();
            ((PageActivity) parentActivity)
                .getSearchBarHideHandler()
                .setForceNoFade(slideOffset != 0);
            // request the current section to highlight, if we haven't yet
            if (!sectionRequested) {
              bridge.sendMessage("requestCurrentSection", new JSONObject());
              sectionRequested = true;
            }
          }
        });
  }