package com.sinata.xqmuse.dialog
|
|
import android.view.Gravity
|
import android.view.View
|
import android.webkit.WebSettings
|
import androidx.core.os.bundleOf
|
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentPagerAdapter
|
import cn.sinata.xldutils.utils.showAllowingStateLoss
|
import com.flyco.tablayout.listener.OnTabSelectListener
|
import com.sinata.xqmuse.R
|
import com.sinata.xqmuse.ui.FakeFragment
|
import com.sinata.xqmuse.utils.interfaces.StringCallback
|
import kotlinx.android.synthetic.main.dialog_login_rule.*
|
|
class LoginRulesDialog:BaseDialogFragment() {
|
override fun setContentView() = R.layout.dialog_login_rule
|
|
private val index by lazy { arguments?.getInt("index") }
|
private val privacy by lazy { arguments?.getString("privacy")?:"" }
|
private val user by lazy { arguments?.getString("user")?:"" }
|
private var callback:StringCallback? = null
|
|
override fun setGravity() = Gravity.CENTER
|
|
|
override fun initView() {
|
tv_cancel.setOnClickListener {
|
callback?.onResult("")
|
dismissAllowingStateLoss()
|
}
|
tv_ok.setOnClickListener {
|
callback?.onResult("1")
|
dismissAllowingStateLoss()
|
}
|
val frags = arrayListOf<Fragment>()
|
frags.add(FakeFragment())
|
frags.add(FakeFragment())
|
vp_fake.adapter = object :FragmentPagerAdapter(childFragmentManager,0){
|
override fun getCount() = 2
|
|
override fun getItem(position: Int) = frags[position]
|
}
|
tab_top.setViewPager(vp_fake, arrayOf("用户协议","隐私协议"))
|
initWebView()
|
val value = object : OnTabSelectListener {
|
override fun onTabSelect(position: Int) {
|
load(position)
|
}
|
|
override fun onTabReselect(position: Int) {
|
}
|
}
|
tab_top.setOnTabSelectListener(value)
|
tab_top.currentTab = index?:0
|
load(index?:0)
|
}
|
|
private fun initWebView() {
|
val settings = sc_content.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
|
sc_content.isScrollContainer = false
|
sc_content.isScrollbarFadingEnabled = false
|
sc_content.scrollBarStyle = View.SCROLLBARS_OUTSIDE_OVERLAY
|
}
|
|
private fun load(position:Int){
|
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>"
|
if (position == 0) {
|
sc_content.loadDataWithBaseURL(null, sHead + user, "text/html", "utf-8", null)
|
} else {
|
sc_content.loadDataWithBaseURL(
|
null,
|
sHead + privacy,
|
"text/html",
|
"utf-8",
|
null
|
)
|
}
|
}
|
|
companion object{
|
fun show(fm:FragmentManager,privacy:String,user:String,index:Int,callback:StringCallback){
|
val loginRuleDialog = LoginRulesDialog()
|
loginRuleDialog.arguments = bundleOf("privacy" to privacy,"index" to index,"user" to user)
|
loginRuleDialog.callback = callback
|
loginRuleDialog.showAllowingStateLoss(fm,"rule")
|
}
|
}
|
}
|