From f917d260d21b4c20acd5a4e11faf660d27fba56d Mon Sep 17 00:00:00 2001 From: Alexander Danmayer Date: Wed, 18 May 2022 09:46:04 +0200 Subject: [PATCH] small refactoring --- .../faria/turbolinks/TurbolinksSession.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/turbolinks/src/main/java/co/faria/turbolinks/TurbolinksSession.java b/turbolinks/src/main/java/co/faria/turbolinks/TurbolinksSession.java index 29facf3..c19815c 100644 --- a/turbolinks/src/main/java/co/faria/turbolinks/TurbolinksSession.java +++ b/turbolinks/src/main/java/co/faria/turbolinks/TurbolinksSession.java @@ -160,33 +160,33 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) { @Override public void onPageFinished(WebView view, final String location) { - Log.d("TurbolinksSession", "onPageFinished (WebClient): " + location); - - if (!location.equals("about:blank") && !initPageLoading) { - String jsCall = "window.webView == null"; - webView.evaluateJavascript(jsCall, new ValueCallback() { - @Override - public void onReceiveValue(String s) { - if (Boolean.parseBoolean(s) && !bridgeInjectionInProgress) { - bridgeInjectionInProgress = true; - TurbolinksHelper.injectTurbolinksBridge(TurbolinksSession.this, applicationContext, webView); - TurbolinksLog.d("Bridge injected"); - - TurbolinksHelper.runOnMainThread(activity, new Runnable() { - @Override - public void run() { - if (webView != null) { // make sure webView is available - turbolinksAdapter.onPageFinished(); + if (!location.equals("about:blank")) { + Log.d("TurbolinksSession", "onPageFinished (WebClient): " + location); + + if (initPageLoading) { + // don't inject JS on initPageLoading + turbolinksAdapter.onPageFinished(); + } else { + String jsCall = "window.webView == null"; + webView.evaluateJavascript(jsCall, new ValueCallback() { + @Override + public void onReceiveValue(String s) { + if (Boolean.parseBoolean(s) && !bridgeInjectionInProgress) { + bridgeInjectionInProgress = true; + TurbolinksHelper.injectTurbolinksBridge(TurbolinksSession.this, applicationContext, webView); + TurbolinksLog.d("Bridge injected"); + + TurbolinksHelper.runOnMainThread(activity, new Runnable() { + @Override + public void run() { + if (webView != null) { // make sure webView is available + turbolinksAdapter.onPageFinished(); + } } - } - }); + }); + } } - } - }); - } else { - // notifiy page finished for initPageLoading - if (!location.equals("about:blank")) { - turbolinksAdapter.onPageFinished(); + }); } } }