]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/adapters/WebViewPagerAdapter.java
Update the URL in the copyright header. https://redmine.stoutner.com/issues/796
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / adapters / WebViewPagerAdapter.java
index 510ac7396a1a63a6d813061652274ca696eb706a..a3095617cde308fbb1e0d0b67cfb2cf3257f11f3 100644 (file)
@@ -1,25 +1,26 @@
 /*
- * Copyright © 2019-2020 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2019-2022 Soren Stoutner <soren@stoutner.com>.
  *
- * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
+ * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
  *
- * Privacy Browser is free software: you can redistribute it and/or modify
+ * Privacy Browser Android is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
- * Privacy Browser is distributed in the hope that it will be useful,
+ * Privacy Browser Android is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
+ * along with Privacy Browser Android.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 package com.stoutner.privacybrowser.adapters;
 
 import android.os.Bundle;
+import android.widget.FrameLayout;
 
 import androidx.annotation.NonNull;
 import androidx.fragment.app.Fragment;
@@ -27,13 +28,15 @@ import androidx.fragment.app.FragmentManager;
 import androidx.fragment.app.FragmentPagerAdapter;
 import androidx.viewpager.widget.ViewPager;
 
+import com.stoutner.privacybrowser.R;
 import com.stoutner.privacybrowser.fragments.WebViewTabFragment;
+import com.stoutner.privacybrowser.views.NestedScrollWebView;
 
 import java.util.LinkedList;
 
 public class WebViewPagerAdapter extends FragmentPagerAdapter {
     // The WebView fragments list contains all the WebViews.
-    private LinkedList<WebViewTabFragment> webViewFragmentsList = new LinkedList<>();
+    private final LinkedList<WebViewTabFragment> webViewFragmentsList = new LinkedList<>();
 
     // Define the constructor.
     public WebViewPagerAdapter(FragmentManager fragmentManager) {
@@ -125,17 +128,40 @@ public class WebViewPagerAdapter extends FragmentPagerAdapter {
     }
 
     public boolean deletePage(int pageNumber, ViewPager webViewPager) {
+        // Get the WebView tab fragment.
+        WebViewTabFragment webViewTabFragment = webViewFragmentsList.get(pageNumber);
+
+        // Get the WebView frame layout.
+        FrameLayout webViewFrameLayout = (FrameLayout) webViewTabFragment.getView();
+
+        // Remove the warning below that the WebView frame layout might be null.
+        assert webViewFrameLayout != null;
+
+        // Get a handle for the nested scroll WebView.
+        NestedScrollWebView nestedScrollWebView = webViewFrameLayout.findViewById(R.id.nestedscroll_webview);
+
+        // Pause the current WebView.
+        nestedScrollWebView.onPause();
+
+        // Remove all the views from the frame layout.
+        webViewFrameLayout.removeAllViews();
+
+        // Destroy the current WebView.
+        nestedScrollWebView.destroy();
+
         // Delete the page.
         webViewFragmentsList.remove(pageNumber);
 
         // Update the view pager.
         notifyDataSetChanged();
 
-        // Return true if the selected page number did not change after the delete.  This will cause the calling method to reset the current WebView to the new contents of this page number.
+        // Return true if the selected page number did not change after the delete (because the newly selected tab has has same number as the previously deleted tab).
+        // This will cause the calling method to reset the current WebView to the new contents of this page number.
         return (webViewPager.getCurrentItem() == pageNumber);
     }
 
     public WebViewTabFragment getPageFragment(int pageNumber) {
+        // Return the page fragment.
         return webViewFragmentsList.get(pageNumber);
     }
 }
\ No newline at end of file