package com.dollearn.student.dialog
|
|
import android.view.Gravity
|
import android.view.View
|
import android.webkit.WebSettings
|
import android.webkit.WebView
|
import androidx.core.os.bundleOf
|
import androidx.fragment.app.FragmentManager
|
import cn.sinata.xldutils.utils.showAllowingStateLoss
|
import com.dollearn.student.R
|
import kotlinx.android.synthetic.main.dialog_bottom_rule.*
|
|
class LoginRuleDialog:BaseDialogFragment() {
|
override fun setContentView() = R.layout.dialog_bottom_rule
|
|
private val type by lazy { arguments?.getInt("type") }
|
private val content by lazy { arguments?.getString("content")?:"" }
|
|
override fun setGravity() = Gravity.BOTTOM
|
|
override fun initView() {
|
iv_close.setOnClickListener { dismissAllowingStateLoss() }
|
tv_title.text = when(type){
|
TYPE_USER -> "用户协议"
|
TYPE_PRIVACY -> "隐私协议"
|
TYPE_COUPON_USAGE -> "可用门店"
|
TYPE_COUPON_CITY -> "可用城市"
|
else -> "运动安全告知书"
|
}
|
initWebView(webView,content)
|
}
|
|
private fun initWebView(webView: WebView, url: String) {
|
val settings = webView.settings
|
settings.defaultTextEncodingName = "utf-8" //设置编码格式
|
settings.loadWithOverviewMode = true // 页面支持缩放:
|
settings.builtInZoomControls = true
|
settings.useWideViewPort = false //将图片调整到适合webview的大小
|
settings.setSupportZoom(false) //支持缩放
|
settings.supportMultipleWindows() //多窗口
|
settings.cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK //关闭webview中缓存
|
settings.allowFileAccess = true //设置可以访问文件
|
settings.setNeedInitialFocus(true) //当webview调用requestFocus时为webview设置节点
|
settings.javaScriptCanOpenWindowsAutomatically = true //支持通过JS打开新窗口
|
settings.loadsImagesAutomatically = true //支持自动加载图片
|
settings.javaScriptEnabled = true
|
settings.domStorageEnabled = true
|
webView.isScrollContainer = false
|
webView.isScrollbarFadingEnabled = false
|
webView.scrollBarStyle = View.SCROLLBARS_OUTSIDE_OVERLAY
|
if (url.startsWith("http")) {
|
webView.loadUrl(url)
|
} else {
|
val sHead =
|
"<html><head><meta name=\"viewport\" content=\"width=device-width, " + "initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes\" />" + "<style>img{max-width:100% !important;height:auto !important;}</style>" + "<style>body{max-width:100% !important;}</style>" + "</head><body>"
|
webView.loadDataWithBaseURL(null, sHead + url, "text/html", "utf-8", null)
|
}
|
}
|
|
companion object{
|
const val TYPE_USER = 1
|
const val TYPE_PRIVACY = 2
|
const val TYPE_UNREGISTER = 3
|
const val TYPE_COUPON_USAGE = 4//优惠券可用门店
|
const val TYPE_COUPON_CITY = 5//优惠券可用城市
|
fun show(fm:FragmentManager,content:String,type:Int){
|
val loginRuleDialog = LoginRuleDialog()
|
loginRuleDialog.arguments = bundleOf("content" to content,"type" to type)
|
loginRuleDialog.showAllowingStateLoss(fm,"rule")
|
}
|
}
|
}
|