|
|
|
@ -13,7 +13,7 @@ import androidx.fragment.app.activityViewModels |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.BaseFragment |
|
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
|
import io.legado.app.data.entities.BaseSource |
|
|
|
|
import io.legado.app.databinding.FragmentWebViewLoginBinding |
|
|
|
|
import io.legado.app.help.http.CookieStore |
|
|
|
|
import io.legado.app.utils.snackbar |
|
|
|
@ -28,7 +28,7 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) { |
|
|
|
|
|
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
viewModel.source?.let { |
|
|
|
|
binding.titleBar.title = getString(R.string.login_source, it.bookSourceName) |
|
|
|
|
binding.titleBar.title = getString(R.string.login_source, it.getName()) |
|
|
|
|
initWebView(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -52,32 +52,32 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressLint("SetJavaScriptEnabled") |
|
|
|
|
private fun initWebView(bookSource: BookSource) { |
|
|
|
|
private fun initWebView(source: BaseSource) { |
|
|
|
|
val settings = binding.webView.settings |
|
|
|
|
settings.setSupportZoom(true) |
|
|
|
|
settings.builtInZoomControls = true |
|
|
|
|
settings.javaScriptEnabled = true |
|
|
|
|
bookSource.getHeaderMap()[AppConst.UA_NAME]?.let { |
|
|
|
|
source.getHeaderMap()[AppConst.UA_NAME]?.let { |
|
|
|
|
settings.userAgentString = it |
|
|
|
|
} |
|
|
|
|
val cookieManager = CookieManager.getInstance() |
|
|
|
|
binding.webView.webViewClient = object : WebViewClient() { |
|
|
|
|
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { |
|
|
|
|
val cookie = cookieManager.getCookie(url) |
|
|
|
|
CookieStore.setCookie(bookSource.bookSourceUrl, cookie) |
|
|
|
|
CookieStore.setCookie(source.getStoreUrl(), cookie) |
|
|
|
|
super.onPageStarted(view, url, favicon) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onPageFinished(view: WebView?, url: String?) { |
|
|
|
|
val cookie = cookieManager.getCookie(url) |
|
|
|
|
CookieStore.setCookie(bookSource.bookSourceUrl, cookie) |
|
|
|
|
CookieStore.setCookie(source.getStoreUrl(), cookie) |
|
|
|
|
if (checking) { |
|
|
|
|
activity?.finish() |
|
|
|
|
} |
|
|
|
|
super.onPageFinished(view, url) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
bookSource.loginUrl?.let { |
|
|
|
|
source.loginUrl?.let { |
|
|
|
|
binding.webView.loadUrl(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|