Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
adanmayer committed May 18, 2022
1 parent eaa5e59 commit f917d26
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions turbolinks/src/main/java/co/faria/turbolinks/TurbolinksSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>() {
@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<String>() {
@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();
});
}
}
}
Expand Down

0 comments on commit f917d26

Please sign in to comment.