X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.java;h=39b95dca65d30d4ab5f35a3b31b1d47fd6969873;hb=514e93baaa8389dc9c5abdb79e68c890c260b8d3;hp=162a1c8fcee84c3dd5519f10f3c4f9c58519ef8c;hpb=ca0573b78247e8beee6fb75de26220bea532f166;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index 162a1c8f..39b95dca 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 Soren Stoutner . + * Copyright 2015-2023 Soren Stoutner . * * Download cookie code contributed 2017 Hendrik Knackstedt. Copyright assigned to Soren Stoutner . * @@ -751,6 +751,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } } } else { // The app has been restarted. + // Set the saved tab position to be the size of the saved state array list. The tab position is 0 based, meaning the at the new tab will be the tab position that is restored. + savedTabPosition = savedStateArrayList.size(); + // Replace the intent that started the app with this one. This will load the tab after the others have been restored. setIntent(intent); } @@ -4356,7 +4359,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Add the first tab. addNewTab("", true); } else { // The activity has been restarted. - // Restore each tab. Once the minimum API >= 24, a `forEach()` command can be used. + // Restore each tab. for (int i = 0; i < savedStateArrayList.size(); i++) { // Add a new tab. tabLayout.addTab(tabLayout.newTab()); @@ -4382,7 +4385,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook if (savedTabPosition == 0) { // The first tab is selected. // Set the first page as the current WebView. setCurrentWebView(0); - } else { // the first tab is not selected. + } else { // The first tab is not selected. // Move to the selected tab. webViewPager.setCurrentItem(savedTabPosition); } @@ -4841,7 +4844,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Remove any background on the URL relative layout. urlRelativeLayout.setBackground(ResourcesCompat.getDrawable(getResources(), R.color.transparent, null)); } - } else { // The fragment has not been populated. Try again in 100 milliseconds. + } else if (pageNumber == savedTabPosition){ // The app is being restored but the saved tab position fragment has not been populated yet. Try again in 100 milliseconds. // Create a handler to set the current WebView. Handler setCurrentWebViewHandler = new Handler(); @@ -5330,9 +5333,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook nestedScrollWebView.setWebViewClient(new WebViewClient() { // `shouldOverrideUrlLoading` makes this WebView the default handler for URLs inside the app, so that links are not kicked out to other apps. - // The deprecated `shouldOverrideUrlLoading` must be used until API >= 24. @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { + public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest webResourceRequest) { + // Get the URL from the web resource request. + String url = webResourceRequest.getUrl().toString(); + // Sanitize the url. url = sanitizeUrl(url);