/** display a new Document and return the new Page */
  public CurrentPage setCurrentDocument(Book nextDocument) {
    CurrentPage nextPage = null;
    if (nextDocument != null) {
      PassageChangeMediator.getInstance().onBeforeCurrentPageChanged();

      nextPage = getBookPage(nextDocument);

      // is the next doc the same as the prev doc
      boolean sameDoc = nextDocument.equals(nextPage.getCurrentDocument());

      // must be in this order because History needs to grab the current doc before change
      nextPage.setCurrentDocument(nextDocument);
      currentDisplayedPage = nextPage;

      // page will change due to above
      // if there is a valid share key or the doc (hence the key) in the next page is the same then
      // show the page straight away
      if ((nextPage.isShareKeyBetweenDocs() || sameDoc) && nextPage.getKey() != null) {
        PassageChangeMediator.getInstance().onCurrentPageChanged();
      } else {
        Context context = CurrentActivityHolder.getInstance().getCurrentActivity();
        // pop up a key selection screen
        Intent intent = new Intent(context, nextPage.getKeyChooserActivity());
        context.startActivity(intent);
      }
    } else {
      // should never get here because a doc should always be passed in but I have seen errors lie
      // this once or twice
      nextPage = currentDisplayedPage;
    }

    return nextPage;
  }
 public void onScroll(int newYPos) {
   // do not try to change verse while the page is changing - can cause all sorts of errors e.g.
   // selected verse may not be valid in new chapter and cause chapter jumps
   if (!PassageChangeMediator.getInstance().isPageChanging()) {
     verseCalculator.newPosition(newYPos);
   }
 }
  /**
   * called during app start-up to restore previous state
   *
   * @param inState
   */
  public void restoreState(SharedPreferences inState) {
    Log.i(TAG, "restore state");
    currentBiblePage.restoreState(inState);
    currentCommentaryPage.restoreState(inState);
    currentDictionaryPage.restoreState(inState);
    currentGeneralBookPage.restoreState(inState);

    String restoredPageCategoryName = inState.getString("currentPageCategory", null);
    if (StringUtils.isNotEmpty(restoredPageCategoryName)) {
      BookCategory restoredBookCategory = BookCategory.fromString(restoredPageCategoryName);
      currentDisplayedPage = getBookPage(restoredBookCategory);
    }

    // force an update here from default chapter/verse
    PassageChangeMediator.getInstance().onCurrentPageChanged();
    PassageChangeMediator.getInstance().onCurrentPageDetailChanged();
  }
  public CurrentPage setCurrentDocumentAndKeyAndOffset(
      Book currentBook, Key key, float yOffsetRatio) {
    PassageChangeMediator.getInstance().onBeforeCurrentPageChanged();

    CurrentPage nextPage = getBookPage(currentBook);
    if (nextPage != null) {
      try {
        nextPage.setInhibitChangeNotifications(true);
        nextPage.setCurrentDocument(currentBook);
        nextPage.setKey(key);
        nextPage.setCurrentYOffsetRatio(yOffsetRatio);
        currentDisplayedPage = nextPage;
      } finally {
        nextPage.setInhibitChangeNotifications(false);
      }
    }
    // valid key has been set so do not need to show a key chooser therefore just update main view
    PassageChangeMediator.getInstance().onCurrentPageChanged();

    return nextPage;
  }
 public void showBible() {
   PassageChangeMediator.getInstance().onBeforeCurrentPageChanged();
   currentDisplayedPage = currentBiblePage;
   PassageChangeMediator.getInstance().onCurrentPageChanged();
 }