From a4de46387bc489523f300ae4c9a08fe50b2a91ae Mon Sep 17 00:00:00 2001 From: Dylan McCall Date: Tue, 21 Mar 2023 11:55:06 -0700 Subject: [PATCH] Wait for redirects before showing main webview The onPageFinished callback fires when a page is redirected to another one. We can detect if a new page load is started before the previous page is finished, and wait for that new page load to finish. https://phabricator.endlessm.com/T34576 --- .../java/org/kivy/android/PythonActivity.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java b/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java index ff448652ed..2c5f73a5bc 100644 --- a/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java +++ b/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java @@ -221,22 +221,27 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true); mWebView.getSettings().setMediaPlaybackRequiresUserGesture(false); mWebView.setWebViewClient(new WebViewClient() { + boolean isRedirected = false; + + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + isRedirected = false; + } + @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { + isRedirected = true; return tryOpenExternalLink(url); } @Override public void onPageFinished(WebView view, String url) { - Log.i(TAG, "MainPythonWebViewClient onPageFinished"); + if (isRedirected) { + return; + } + + Log.v(TAG, "MainPythonWebViewClient loading finished"); displayMainWebView(); - // FIXME: We should use postVisualStateCallback here... - // mWebView.postVisualStateCallback(123, new WebView.VisualStateCallback() { - // @Override - // public void onComplete(long requestId) { - // displayMainWebView(); - // } - // }); } }); mWebViewSwitcher.addView(mWebView, 1);