Question: Please provide me with the full working code using Kotlin. I've added the provided code included in the assignment. Instructions: Enhance the application from your

Please provide me with the full working code using Kotlin. I've added the provided code included in the assignment.
Instructions:
Enhance the application from your previous assignment to support multiple pages. We are going to treat each instance of PageViewerFragment like a Tab in a standard browser implementation, but since we are not actually using tabs we'll say page instead.
1. Redesign your BrowserActivitys default layout to add a new container: browser_control (illustrated below), and replace the FragmentContainerView called page_display with a ViewPager2
2. Create a new fragment class, BrowserControlFragment, with the following features:
This fragment should display 1 ImageButton:
The button should create a new browser page (a new instance of PageViewerFragment),and display it in the ViewPager2(described below).
3. Your ViewPager2 will use a FragmentStateAdapter that will allow the user to use a swipe
gesture to move between instances of PageViewerFragments.
When the user creates a new page from the BrowserControlFragment, it should be added to the end of the ViewPager2 and automatically displayed (i.e. the user should see the blank new page and would swipe right to see the previous page).
4. BrowserActivity should behave as follows:
1. Attach the necessary fragments
1. On Startup, whether in Portrait or Landscape mode, the activity should display a
single instance of BrowserControlFragment in the browser_control
2. By default, the activity should start with one (empty) instance of PageViewerFragment
3. When the user clicks on the NewPage ImageButton in BrowserControlFragment, a new instance of PageViewerFragment should be created and displayed in the ViewPager2 and that page should by active automatically (that is, the ViewPager2 should select the new page immediately).
4. The activity should display as its title the page title of the currently displayed page.
Here is the provided code:
----------------------------------------
`import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class BrowserActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Ensure browser page isn't added twice
if (supportFragmentManager.findFragmentById(R.id.page_viewer)!is PageViewerFragment)
supportFragmentManager
.beginTransaction()
.add(R.id.page_viewer, PageViewerFragment())
.commit()
}
}`
-------------------------------------
`package edu.temple.superbrowser
import android.annotation.SuppressLint
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.EditText
import android.widget.ImageButton
class PageViewerFragment : Fragment(){
private lateinit var webView: WebView
private lateinit var goButton: ImageButton
private lateinit var bkButton: ImageButton
private lateinit var fwdButton: ImageButton
private lateinit var urlEditText: EditText
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_page_viewer, container, false).apply {
webView = findViewById(R.id.webView)
goButton = findViewById(R.id.goButton)
bkButton = findViewById(R.id.bkButton)
fwdButton = findViewById(R.id.fwdButton)
urlEditText = findViewById(R.id.urlEditText)
}
}
@SuppressLint("SetJavaScriptEnabled")
override fun onViewCreated(view: View, savedInstanceState: Bundle?){
super.onViewCreated(view, savedInstanceState)
// Enable Javascript for proper functioning websites
webView.settings.javaScriptEnabled = true;
// Provision WebViewClient implementation that retrieves current page URL
webView.webViewClient = object: WebViewClient (){
override fun onPageFinished(view: WebView?, url: String?){
super.onPageFinished(view, url)
url?.run {
urlEditText.setText(this)
}
}
}
// Restore previous web state if present
savedInstanceState?.run {
webView.restoreState(this)
}
goButton.setOnClickListener {
urlEditText.setText(cleanUrl(urlEditText.text.toString()))
webView.loadUrl(urlEditText.text.toString())
}
bkButton.setOnClickListener {
webView.goBack()
}
fwdButton.setOnClickListener {
webView.goForward()
}
}
// Helper function to format malformed URLs
private fun cleanUrl(url: String) : String {
return if (url.startsWith("http"))
url
else
"https://$url"
}
override fun onSaveInstanceState(outState: Bundle){
super.onSaveInstanceState(outState)
//Store current web state
webView.saveState(outState)`
----------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!