SecretDescriptionDialog.kt 3.79 KB
Newer Older
yjiucheng committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package com.yidianling.user.widget

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.text.Html
import android.text.SpannableString
import android.text.Spanned
import android.text.TextPaint
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import com.ydl.ydlcommon.utils.SharedPreferencesEditor
import com.ydl.ydlcommon.utils.Utils
18
import com.ydl.ydlcommon.utils.actionutil.ActionCountUtils
yjiucheng committed
19
import com.yidianling.user.R
20
import com.yidianling.user.constants.UserBIConstants
yjiucheng committed
21
import com.yidianling.user.ui.login.H5Activity
严久程 committed
22
import kotlinx.android.synthetic.main.user_dialog_secret.*
yjiucheng committed
23 24 25 26 27 28 29 30 31 32 33


class SecretDescriptionDialog(
    var mContext: Context,
    var mSecretProtocolString: String,
    private val listener: OnSecretDescriptionDialogListener?
) : Dialog(mContext, R.style.platform_dialog_default_style) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

严久程 committed
34
        setContentView(R.layout.user_dialog_secret)
yjiucheng committed
35 36 37 38 39 40 41 42 43 44

        val params = window.attributes
        params.width = WindowManager.LayoutParams.MATCH_PARENT
        params.height = WindowManager.LayoutParams.WRAP_CONTENT
        window.setGravity(Gravity.CENTER)
        window.attributes = params

        user_secret_desc.text = Html.fromHtml(mSecretProtocolString)

        user_secret_no_agree.setOnClickListener {
45 46 47 48
            ActionCountUtils.count(
                UserBIConstants.PRIVACY_AUTHORIZATION_TWO_CLICK,
                "拒绝"
            )
yjiucheng committed
49 50 51 52
            listener?.onCancel()
        }

        user_secret_agree.setOnClickListener {
53
            ActionCountUtils.count(UserBIConstants.PRIVACY_AUTHORIZATION_CLICK, "同意")
yjiucheng committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
            agreeAction()
        }

        val str = "阅读完整版《用户使用协议》、《隐私保护政策》"
        val spannableString = SpannableString(str)
//        spannableString.setSpan(
//            ForegroundColorSpan(Color.parseColor("#159CEF")),
//            5,
//            13,
//            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
//        )
//        spannableString.setSpan(
//            ForegroundColorSpan(Color.parseColor("#159CEF")),
//            str.length - 8,
//            str.length,
//            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
//        )
        spannableString.setSpan(
            object : ClickableSpan() {
                override fun onClick(widget: View?) {
严久程 committed
74
                    if (Utils.isFastClick()) {
yjiucheng committed
75 76 77 78 79 80
                        return
                    }
                    H5Activity.start(mContext, false)
                }

                override fun updateDrawState(ds: TextPaint?) {
严久程 committed
81
                    ds?.color = Color.parseColor("#159CEF")
yjiucheng committed
82 83 84 85 86 87 88
                }
            }, 5,
            13, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        spannableString.setSpan(
            object : ClickableSpan() {
                override fun onClick(widget: View?) {
严久程 committed
89
                    if (Utils.isFastClick()) {
yjiucheng committed
90 91 92 93 94 95
                        return
                    }
                    H5Activity.start(mContext, true)
                }

                override fun updateDrawState(ds: TextPaint?) {
严久程 committed
96
                    ds?.color = Color.parseColor("#159CEF")
yjiucheng committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
                }
            }, str.length - 8,
            str.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        tv_content.movementMethod = LinkMovementMethod.getInstance()
        tv_content.highlightColor = Color.TRANSPARENT
        tv_content.text = spannableString
    }

    private fun agreeAction() {
        SharedPreferencesEditor.putString("hasAgreeSecret", "true")
        listener?.onSure()
    }

    interface OnSecretDescriptionDialogListener {
        fun onCancel()
        fun onSure()
    }


}