Skip to content

Commit

Permalink
Add clear history action
Browse files Browse the repository at this point in the history
And fix back<->forward mixup bug
  • Loading branch information
alandau committed Mar 12, 2018
1 parent ab8785f commit d76b371
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions app/src/main/java/landau/sweb/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ArrayAdapter;
Expand Down Expand Up @@ -195,9 +196,9 @@ public String toString() {
new MenuAction("Share URL", android.R.drawable.ic_menu_share, this::shareUrl),

new MenuAction("Back", R.drawable.back,
() -> {if (getCurrentWebView().canGoBack()) getCurrentWebView().goForward();}),
new MenuAction("Forward", R.drawable.forward,
() -> {if (getCurrentWebView().canGoBack()) getCurrentWebView().goBack();}),
new MenuAction("Forward", R.drawable.forward,
() -> {if (getCurrentWebView().canGoForward()) getCurrentWebView().goForward();}),
new MenuAction("Reload", R.drawable.reload, () -> getCurrentWebView().reload()),
new MenuAction("Stop", R.drawable.stop, () -> getCurrentWebView().stopLoading()),
new MenuAction("Scroll to top", R.drawable.top,
Expand All @@ -214,6 +215,8 @@ public String toString() {
new MenuAction("Import bookmarks", R.drawable.bookmarks_import, this::importBookmarks),
new MenuAction("Delete all bookmarks", 0, this::deleteAllBookmarks),

new MenuAction("Clear history and cache", 0, this::clearHistoryCache),

new MenuAction("Show tabs", R.drawable.tabs, this::showOpenTabs),
new MenuAction("New tab", R.drawable.tab_new, () -> {
newTab("");
Expand Down Expand Up @@ -1011,6 +1014,15 @@ private void deleteAllBookmarks() {
.show();
}

private void clearHistoryCache() {
WebView v = getCurrentWebView();
v.clearCache(true);
v.clearFormData();
v.clearHistory();
CookieManager.getInstance().removeAllCookies(null);
WebStorage.getInstance().deleteAllData();
}

private void closeCurrentTab() {
if (getCurrentWebView().getUrl() != null && !getCurrentWebView().getUrl().equals("about:blank")) {
TitleAndUrl titleAndUrl = new TitleAndUrl();
Expand Down

0 comments on commit d76b371

Please sign in to comment.