]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java
Make pinned settings tab aware.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / WebViewTabFragment.java
index 8ad76d7cbed9eb854614efd7775df19c9adeda17..3ffa8aa4faaa81ab8e8c97c60e715fcdab82c163 100644 (file)
@@ -24,6 +24,7 @@ import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.ProgressBar;
 
 import androidx.annotation.NonNull;
 import androidx.fragment.app.Fragment;
@@ -31,10 +32,15 @@ import androidx.fragment.app.Fragment;
 import com.stoutner.privacybrowser.R;
 import com.stoutner.privacybrowser.views.NestedScrollWebView;
 
+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 fragmentId = Calendar.getInstance().getTimeInMillis();
+
     // The public interface is used to send information back to the parent activity.
     public interface NewTabListener {
-        void initializeWebView(NestedScrollWebView nestedScrollWebView, int tabNumber);
+        void initializeWebView(NestedScrollWebView nestedScrollWebView, int pageNumber, ProgressBar progressBar);
     }
 
     // The new tab listener is used in `onAttach()` and `onCreateView()`.
@@ -49,12 +55,12 @@ public class WebViewTabFragment extends Fragment {
         newTabListener = (NewTabListener) context;
     }
 
-    public static WebViewTabFragment createTab(int tabNumber) {
+    public static WebViewTabFragment createPage(int pageNumber) {
         // Create a bundle.
         Bundle bundle = new Bundle();
 
-        // Store the tab number in the bundle.
-        bundle.putInt("tab_number", tabNumber);
+        // Store the page number in the bundle.
+        bundle.putInt("page_number", pageNumber);
 
         // Create a new instance of the WebView tab fragment.
         WebViewTabFragment webViewTabFragment = new WebViewTabFragment();
@@ -75,18 +81,22 @@ public class WebViewTabFragment extends Fragment {
         assert arguments != null;
 
         // Get the variables from the arguments
-        int tabNumber = arguments.getInt("tab_number");
+        int pageNumber = arguments.getInt("page_number");
 
         // 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 tabView = layoutInflater.inflate(R.layout.nestedscroll_webview, container, false);
+        View newPageView = layoutInflater.inflate(R.layout.webview_framelayout, container, false);
+
+        // Get handles for the views.
+        NestedScrollWebView nestedScrollWebView = newPageView.findViewById(R.id.nestedscroll_webview);
+        ProgressBar progressBar = newPageView.findViewById(R.id.progress_bar);
 
-        // Get a handle for the nested scroll WebView.
-        NestedScrollWebView nestedScrollWebView = tabView.findViewById(R.id.nestedscroll_webview);
+        // Store the WebView fragment ID in the nested scroll WebView.
+        nestedScrollWebView.setWebViewFragmentId(fragmentId);
 
         // Request the main activity initialize the WebView.
-        newTabListener.initializeWebView(nestedScrollWebView, tabNumber);
+        newTabListener.initializeWebView(nestedScrollWebView, pageNumber, progressBar);
 
-        // Return the tab view.
-        return tabView;
+        // Return the new page view.
+        return newPageView;
     }
 }
\ No newline at end of file