Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inner class WebAppInterface {
- @JavascriptInterface
- fun resize(height: Float) {
- val webViewHeight = (height * resources.displayMetrics.density)
- activity?.runOnUiThread {
- val viewGroup = webViewNotification.layoutParams
- viewGroup.height = webViewHeight.toInt()
- webViewNotification.layoutParams = viewGroup
- }
- }
- }
- class WebClient : WebViewClient() {
- private val URL = "javascript:AndroidFunction.resize(document.body.scrollHeight)"
- override fun onPageFinished(view: WebView?, url: String?) {
- view?.loadUrl(URL)
- }
- }
- override fun onActivityCreated(savedInstanceState: Bundle?) {
- super.onActivityCreated(savedInstanceState)
- webViewNotification.settings.javaScriptEnabled = true
- webViewNotification.addJavascriptInterface(WebAppInterface(), "AndroidFunction")
- webViewNotification.webViewClient = WebClient()
- refreshLayout.setOnRefreshListener {
- mViewModel.loadInbox()
- }
- mViewModel.loaded.observe(viewLifecycleOwner, Observer {
- webViewNotification.loadDataWithBaseURL(
- it.basePath,
- it.code,
- "text/html", "UTF-8", null
- )
- (activity as MainActivity).removeBadge()
- })
- mViewModel.progress.observe(viewLifecycleOwner, Observer { progress ->
- refreshLayout.isRefreshing = progress
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement