GoogleFragment: Show progress on page load

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-07-13 21:30:48 +05:30
parent 08f06beaa9
commit 4431054e9c
2 changed files with 38 additions and 2 deletions

View File

@@ -23,10 +23,12 @@ import android.os.Build
import android.os.Bundle
import android.view.View
import android.webkit.CookieManager
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Toast
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
@@ -72,6 +74,23 @@ class GoogleFragment : Fragment(R.layout.fragment_google) {
cookieManager.acceptThirdPartyCookies(this)
cookieManager.setAcceptThirdPartyCookies(this, true)
webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView?, newProgress: Int) {
super.onProgressChanged(view, newProgress)
if (newProgress != 0) {
binding.progressBar.also {
it.isVisible = newProgress < 100
it.isIndeterminate = false
it.max = 100
it.progress = newProgress
}
} else {
binding.progressBar.isIndeterminate = true
}
}
}
webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) {
val cookies = CookieManager.getInstance().getCookie(url)
@@ -119,6 +138,7 @@ class GoogleFragment : Fragment(R.layout.fragment_google) {
GoogleFragmentDirections.actionGoogleFragmentToSplashFragment()
)
}
R.id.accountFragment -> {
findNavController().navigate(
GoogleFragmentDirections.actionGoogleFragmentToAccountFragment()