罗明文
22 小时以前 442124baa483f8d1c4aaca7ff81e15dd3f122363
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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")
        }
    }
}