/**
  * Initialization method that has 3 different behaviors based on whether bookmark model is loaded.
  * If the bookmark model is not loaded yet, it pushes a loading state to backstack which contains
  * the url from preference. If the model is loaded and the backstack is empty, it creates a state
  * by fetching the last visited bookmark url stored in preference. If the bookmark model is loaded
  * but backstack contains a pending loading state, it creates a new state by getting the url of
  * the loading state and replace the previous loading state with the new normal state.
  */
 private void initializeIfBookmarkModelLoaded() {
   if (mEnhancedBookmarksModel.isBookmarkModelLoaded()) {
     mSearchView.onEnhancedBookmarkDelegateInitialized(this);
     mDrawerListView.onEnhancedBookmarkDelegateInitialized(this);
     mContentView.onEnhancedBookmarkDelegateInitialized(this);
     if (mStateStack.isEmpty()) {
       setState(UIState.createStateFromUrl(getUrlFromPreference(), mEnhancedBookmarksModel));
     } else if (mStateStack.peek().mState == UIState.STATE_LOADING) {
       String url = mStateStack.pop().mUrl;
       setState(UIState.createStateFromUrl(url, mEnhancedBookmarksModel));
     }
   } else {
     mContentView.showLoadingUi();
     mDrawerListView.showLoadingUi();
     mContentView.showLoadingUi();
     if (mStateStack.isEmpty() || mStateStack.peek().mState != UIState.STATE_LOADING) {
       setState(UIState.createLoadingState(getUrlFromPreference()));
     } else if (!mStateStack.isEmpty()) {
       // Refresh the UI. This is needed because on tablet, updateForUrl might set up
       // loading state too early and at that time all UI components are not created yet.
       // Therefore we need to set the previous loading state once again to trigger all UI
       // updates.
       setState(mStateStack.pop());
     }
   }
 }
 @Override
 public void closeSearchUI() {
   if (mSearchView.getVisibility() != View.VISIBLE) return;
   mViewSwitcher.showPrevious();
 }