-private const val CREATE_NEW_PAGE = "create_new_page"
-private const val PAGE_NUMBER = "page_number"
-private const val URL = "url"
-private const val SAVED_STATE = "saved_state"
-private const val SAVED_NESTED_SCROLL_WEBVIEW_STATE = "saved_nested_scroll_webview_state"
+private const val CREATE_NEW_PAGE = "A"
+private const val PAGE_POSITION = "B"
+private const val URL = "C"
+private const val SAVED_STATE = "D"
+private const val SAVED_NESTED_SCROLL_WEBVIEW_STATE = "E"
var fragmentId = Calendar.getInstance().timeInMillis
// The public interface is used to send information back to the parent activity.
interface NewTabListener {
@SuppressLint("ClickableViewAccessibility")
var fragmentId = Calendar.getInstance().timeInMillis
// The public interface is used to send information back to the parent activity.
interface NewTabListener {
@SuppressLint("ClickableViewAccessibility")
- fun initializeWebView(nestedScrollWebView: NestedScrollWebView, pageNumber: Int, progressBar: ProgressBar, url: String, restoringState: Boolean)
+ fun initializeWebView(nestedScrollWebView: NestedScrollWebView, pagePosition: Int, progressBar: ProgressBar, urlString: String, restoringState: Boolean)
fun createPage(pageNumber: Int, url: String?): WebViewTabFragment {
// Create an arguments bundle.
val argumentsBundle = Bundle()
// Store the argument in the bundle.
argumentsBundle.putBoolean(CREATE_NEW_PAGE, true)
fun createPage(pageNumber: Int, url: String?): WebViewTabFragment {
// Create an arguments bundle.
val argumentsBundle = Bundle()
// Store the argument in the bundle.
argumentsBundle.putBoolean(CREATE_NEW_PAGE, true)
argumentsBundle.putString(URL, url)
// Create a new instance of the WebView tab fragment.
argumentsBundle.putString(URL, url)
// Create a new instance of the WebView tab fragment.
- @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 {
}
override fun onCreateView(layoutInflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
}
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
// 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
val url = requireArguments().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.
val url = requireArguments().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.
nestedScrollWebView.webViewFragmentId = fragmentId
// Request the main activity initialize the WebView.
nestedScrollWebView.webViewFragmentId = fragmentId
// Request the main activity initialize the WebView.
- newTabListener.initializeWebView(nestedScrollWebView, pageNumber, progressBar, url, false)
+ newTabListener.initializeWebView(nestedScrollWebView, pagePosition, progressBar, url, false)
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.
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.
nestedScrollWebView.restoreNestedScrollWebViewState(savedNestedScrollWebViewState)
// Restore the WebView state.
nestedScrollWebView.restoreNestedScrollWebViewState(savedNestedScrollWebViewState)
// Restore the WebView state.
// Initialize the WebView.
newTabListener.initializeWebView(nestedScrollWebView, 0, progressBar, "", true)
// Initialize the WebView.
newTabListener.initializeWebView(nestedScrollWebView, 0, progressBar, "", true)