/** * Load chapter for external url (not hosted in Baka-Tsuki). Used local cache if available * (wac/mht). * * @param pageModel * @param refresh */ public void loadExternalUrl(PageModel pageModel, boolean refresh) { try { // check if .wac available String url = pageModel.getPage(); String wacName = Util.getSavedWacName(url); final NonLeakingWebView wv = (NonLeakingWebView) findViewById(R.id.webViewContent); if (!Util.isStringNullOrEmpty(wacName) && !refresh) { client.setExternalNeedSave(false); String[] urlParts = url.split("#", 2); if (urlParts.length == 2) { executeLoadWacTask(wacName, urlParts[1], url); } else executeLoadWacTask(wacName, "", url); } else { if (refresh) { Toast.makeText(this, "Refreshing WAC: " + wacName, Toast.LENGTH_SHORT).show(); Log.i(TAG, "Refreshing WAC: " + wacName); } else { Log.w(TAG, "WAC not available: " + wacName); } client.setExternalNeedSave(true); setWebViewSettings(); wv.loadUrl(url); Intent currIntent = this.getIntent(); currIntent.putExtra(Constants.EXTRA_PAGE, url); currIntent.putExtra(Constants.EXTRA_PAGE_IS_EXTERNAL, true); } setChapterTitle(pageModel); buildTOCMenu(pageModel); content = null; } catch (Exception ex) { Log.e(TAG, "Cannot load external content: " + pageModel.getPage(), ex); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_settings: Intent launchNewIntent = new Intent(this, DisplaySettingsActivity.class); startActivity(launchNewIntent); return true; case R.id.menu_refresh_chapter_content: /* * Implement code to refresh chapter content */ PageModel page = null; if (content != null) { try { page = content.getPageModel(); } catch (Exception e) { Log.e(TAG, "Cannot get current chapter.", e); } } else { String pageStr = getIntent().getStringExtra(Constants.EXTRA_PAGE); try { page = NovelsDao.getInstance().getExistingPageModel(new PageModel(pageStr), null); if (page == null) { // no page model, just url page = new PageModel(pageStr); page.setExternal(true); } } catch (Exception e) { Log.e(TAG, "Cannot get current chapter.", e); } } if (page != null) { executeTask(page, true); } return true; case R.id.invert_colors: /* * Implement code to invert colors */ UIHelper.ToggleColorPref(this); UIHelper.Recreate(this); return true; case R.id.menu_chapter_previous: /* * Implement code to move to previous chapter */ String currentPage = getIntent().getStringExtra(Constants.EXTRA_PAGE); try { if (novelDetails == null) novelDetails = NovelsDao.getInstance().getNovelDetails(content.getPageModel(), null, false); PageModel prev = novelDetails.getPrev( currentPage, UIHelper.getShowMissing(this), UIHelper.getShowRedlink(this)); if (prev != null) { jumpTo(prev); } else { Toast.makeText( this, getResources().getString(R.string.first_available_chapter), Toast.LENGTH_SHORT) .show(); } } catch (Exception e) { Log.e(TAG, "Cannot get previous chapter.", e); } return true; case R.id.menu_chapter_next: /* * Implement code to move to next chapter */ String currentPage2 = getIntent().getStringExtra(Constants.EXTRA_PAGE); try { if (novelDetails == null) novelDetails = NovelsDao.getInstance().getNovelDetails(content.getPageModel(), null, false); PageModel next = novelDetails.getNext( currentPage2, UIHelper.getShowMissing(this), UIHelper.getShowRedlink(this)); if (next != null) { jumpTo(next); } else { Toast.makeText( this, getResources().getString(R.string.last_available_chapter), Toast.LENGTH_SHORT) .show(); } } catch (Exception e) { Log.e(TAG, "Cannot get next chapter.", e); } return true; case R.id.menu_chapter_toc: if (tocMenu != null) tocMenu.show(); return true; case R.id.menu_search: showSearchBox(); return true; case R.id.menu_bookmarks_here: if (bookmarkMenu != null) bookmarkMenu.show(); return true; case R.id.menu_bookmarks: Intent bookmarkIntent = new Intent(this, DisplayBookmarkActivity.class); startActivity(bookmarkIntent); return true; case R.id.menu_downloads_list: Intent downloadsItent = new Intent(this, DownloadListActivity.class); startActivity(downloadsItent); return true; case R.id.menu_speak: tts.start(webView, content.getLastYScroll()); return true; case R.id.menu_pause_tts: tts.pause(); return true; case R.id.menu_save_external: // save based on current intent page name. String url = getIntent().getStringExtra(Constants.EXTRA_PAGE); NonLeakingWebView wv = (NonLeakingWebView) findViewById(R.id.webViewContent); if (!url.startsWith("http")) { url = getTitle().toString(); Log.w( TAG, "Current page is not started with http, resolve from current webView url: " + url); } if (wv != null && !Util.isStringNullOrEmpty(url)) wv.saveMyWebArchive(url); return true; case R.id.menu_browser_back: if (webView != null && webView.canGoBack()) { // only good for android 4.4++ webView.goBack(); } return true; case android.R.id.home: finish(); return true; default: return super.onOptionsItemSelected(item); } }