/** Push the current page title onto the backstack. */ private void pushBackStack() { PageBackStackItem item = new PageBackStackItem(model.getTitleOriginal(), model.getCurEntry()); backStack.add(item); }
private void loadPageOnWebViewReady(boolean tryFromCache) { // stage any section-specific link target from the title, since the title may be // replaced (normalized) sectionTargetFromTitle = model.getTitle().getFragment(); Utils.setupDirectionality( model.getTitle().getSite().getLanguageCode(), Locale.getDefault().getLanguage(), bridge); // hide the native top and bottom components... leadImagesHandler.hide(); bottomContentHandler.hide(); bottomContentHandler.setTitle(model.getTitle()); if (model.getCurEntry().getSource() == HistoryEntry.SOURCE_SAVED_PAGE) { state = STATE_NO_FETCH; loadSavedPage(); } else if (tryFromCache) { // is this page in cache?? app.getPageCache() .get( model.getTitleOriginal(), pageSequenceNum, new PageCache.CacheGetListener() { @Override public void onGetComplete(Page page, int sequence) { if (sequence != pageSequenceNum) { return; } if (page != null) { Log.d( TAG, "Using page from cache: " + model.getTitleOriginal().getDisplayText()); model.setPage(page); model.setTitle(page.getTitle()); // load the current title's thumbnail from sqlite updateThumbnail( PageImage.PERSISTENCE_HELPER.getImageUrlForTitle(app, model.getTitle())); // Save history entry... new SaveHistoryTask(model.getCurEntry(), app).execute(); // don't re-cache the page after loading. cacheOnComplete = false; state = STATE_COMPLETE_FETCH; setState(state); performActionForState(state); } else { // page isn't in cache, so fetch it from the network... loadPageFromNetwork(); } } @Override public void onGetError(Throwable e, int sequence) { Log.e(TAG, "Failed to get page from cache.", e); if (sequence != pageSequenceNum) { return; } // something failed when loading it from cache, so fetch it from network... loadPageFromNetwork(); } }); } else { loadPageFromNetwork(); } }