]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java
Allow specifying any font size. https://redmine.stoutner.com/issues/504
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / WebViewTabFragment.java
index bbda97990df89de636066b6cdccd8d7378a972af..91866a3e397e72dacc945d318806ce98fc5c5744 100644 (file)
@@ -36,18 +36,18 @@ import java.util.Calendar;
 
 public class WebViewTabFragment extends Fragment {
     // Set a unique ID for this tab based on the time it was created.
-    public long tabId = Calendar.getInstance().getTimeInMillis();
+    public long fragmentId = Calendar.getInstance().getTimeInMillis();
 
     // The public interface is used to send information back to the parent activity.
     public interface NewTabListener {
-        void initializeWebView(long pageId, int pageNumber, ProgressBar progressBar, NestedScrollWebView nestedScrollWebView);
+        void initializeWebView(NestedScrollWebView nestedScrollWebView, int pageNumber, ProgressBar progressBar, String url);
     }
 
     // The new tab listener is used in `onAttach()` and `onCreateView()`.
     private NewTabListener newTabListener;
 
     @Override
-    public void onAttach(Context context) {
+    public void onAttach(@NonNull Context context) {
         // Run the default commands.
         super.onAttach(context);
 
@@ -55,12 +55,13 @@ public class WebViewTabFragment extends Fragment {
         newTabListener = (NewTabListener) context;
     }
 
-    public static WebViewTabFragment createPage(int pageNumber) {
+    public static WebViewTabFragment createPage(int pageNumber, String url) {
         // Create a bundle.
         Bundle bundle = new Bundle();
 
-        // Store the page number in the bundle.
+        // Store the page number and URL in the bundle.
         bundle.putInt("page_number", pageNumber);
+        bundle.putString("url", url);
 
         // Create a new instance of the WebView tab fragment.
         WebViewTabFragment webViewTabFragment = new WebViewTabFragment();
@@ -82,6 +83,7 @@ public class WebViewTabFragment extends Fragment {
 
         // Get the variables from the arguments
         int pageNumber = arguments.getInt("page_number");
+        String url = arguments.getString("url");
 
         // Inflate the tab's WebView.  Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.  The fragment will take care of attaching the root automatically.
         View newPageView = layoutInflater.inflate(R.layout.webview_framelayout, container, false);
@@ -90,8 +92,11 @@ public class WebViewTabFragment extends Fragment {
         NestedScrollWebView nestedScrollWebView = newPageView.findViewById(R.id.nestedscroll_webview);
         ProgressBar progressBar = newPageView.findViewById(R.id.progress_bar);
 
+        // Store the WebView fragment ID in the nested scroll WebView.
+        nestedScrollWebView.setWebViewFragmentId(fragmentId);
+
         // Request the main activity initialize the WebView.
-        newTabListener.initializeWebView(tabId, pageNumber, progressBar, nestedScrollWebView);
+        newTabListener.initializeWebView(nestedScrollWebView, pageNumber, progressBar, url);
 
         // Return the new page view.
         return newPageView;