]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.kt
Remove AsyncTask from SSLCertificateErrorDialog. https://redmine.stoutner.com/issues/987
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / WebViewTabFragment.kt
index 5d37613c3427040d48c4a9cf61347ef26a9756ff..6f48043870f19683e8c3af2e29c7497e3142ad8f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019-2020,2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2019-2020,2022-2023 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
  *
@@ -43,7 +43,6 @@ private const val SAVED_NESTED_SCROLL_WEBVIEW_STATE = "saved_nested_scroll_webvi
 
 class WebViewTabFragment : Fragment() {
     // Define the public variables.
-    @JvmField  // TODO.  `@JvmField` can be removed once the entire project has been converted to Kotlin.
     var fragmentId = Calendar.getInstance().timeInMillis
 
     // The public interface is used to send information back to the parent activity.
@@ -59,7 +58,6 @@ class WebViewTabFragment : Fragment() {
     private lateinit var nestedScrollWebView: NestedScrollWebView
 
     companion object {
-        @JvmStatic  // TODO.  `@JvmStatic` can be removed once the entire project has been converted to Kotlin.
         fun createPage(pageNumber: Int, url: String?): WebViewTabFragment {
             // Create an arguments bundle.
             val argumentsBundle = Bundle()
@@ -79,8 +77,7 @@ class WebViewTabFragment : Fragment() {
             return webViewTabFragment
         }
 
-        @JvmStatic  // TODO.  `@JvmStatic` can be removed once the entire project has been converted to Kotlin.
-        fun restorePage(savedState: Bundle?, savedNestedScrollWebViewState: Bundle?): WebViewTabFragment {
+        fun restorePage(savedState: Bundle, savedNestedScrollWebViewState: Bundle): WebViewTabFragment {
             // Create an arguments bundle
             val argumentsBundle = Bundle()
 
@@ -108,8 +105,8 @@ class WebViewTabFragment : Fragment() {
     }
 
     override fun onCreateView(layoutInflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
-        // Check to see if the fragment is being restarted.
-        return if (savedInstanceState == null) {  // The fragment is not being restarted.  Load and configure a new fragment.
+        // Check to see if the fragment is being restarted without the app being killed.
+        return if (savedInstanceState == null) {  // The fragment is not being restarted.  It is either new or is being restored after the app was killed.
             // Check to see if a new page is being created.
             if (requireArguments().getBoolean(CREATE_NEW_PAGE)) {  // A new page is being created.
                 // Get the variables from the arguments
@@ -132,9 +129,9 @@ class WebViewTabFragment : Fragment() {
 
                 // Return the new page view.
                 newPageView
-            } else {  // A page is being restored.
+            } else {  // A page is being restored after the app was killed.
                 // Get the saved states from the arguments.
-                val savedState = requireArguments().getBundle(SAVED_STATE)
+                val savedState = requireArguments().getBundle(SAVED_STATE)!!
                 val savedNestedScrollWebViewState = requireArguments().getBundle(SAVED_NESTED_SCROLL_WEBVIEW_STATE)!!
 
                 // Inflate the tab's WebView.  Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.
@@ -152,7 +149,7 @@ class WebViewTabFragment : Fragment() {
                 nestedScrollWebView.restoreNestedScrollWebViewState(savedNestedScrollWebViewState)
 
                 // Restore the WebView state.
-                nestedScrollWebView.restoreState(savedState!!)
+                nestedScrollWebView.restoreState(savedState)
 
                 // Initialize the WebView.
                 newTabListener.initializeWebView(nestedScrollWebView, 0, progressBar, "", true)
@@ -165,4 +162,4 @@ class WebViewTabFragment : Fragment() {
             null
         }
     }
-}
\ No newline at end of file
+}