PrivacyActivity.kt 7.3 KB
Newer Older
1
package com.yidianling.user.safePrivate
konghaorui committed
2 3 4 5 6 7

import android.content.Intent
import android.view.View
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
konghaorui committed
8
import com.alibaba.android.arouter.facade.annotation.Route
9 10 11 12 13 14 15 16
import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.bean.StatusBarOptions
import com.ydl.ydlcommon.view.MyToggleButton
import com.ydl.ydlcommon.view.dialog.CommonDialog
import com.yidianling.user.R
import com.yidianling.user.UserConstants
import com.yidianling.user.UserHelper
import com.yidianling.user.ui.InputPhoneActivity
konghaorui committed
17 18 19 20 21

/**
 * 安全隐私--手势解锁--指纹解锁
 * Created by harvie on 2017/6/10 0010.
 */
konghaorui committed
22
@Route(path = "/user/privacy")
konghaorui committed
23 24
class PrivacyActivity : BaseActivity() {
    override fun layoutResId(): Int {
25
        return R.layout.user_activity_me_privacy
konghaorui committed
26 27 28 29 30 31
    }

    override fun initDataAndEvent() {
        init()
    }

32 33 34 35
    override fun getStatusViewOptions(): StatusBarOptions {
        return StatusBarOptions(true,true)
    }

konghaorui committed
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    var rela_finger: android.widget.RelativeLayout? = null

    var fingerToggle: MyToggleButton? = null
    var handToggle: MyToggleButton? = null

    var finger_tip: TextView? = null
    var lin_update: LinearLayout? = null

    override fun onResume() {
        super.onResume()
        //设置开关状态
        setStatus()
    }

    fun setStatus() {
        //设置开关状态
        if (FingerPrintUtil.Companion.instance().fingerPrintIsOpen()) {
            fingerToggle?.setToggleOn()
        } else {
            fingerToggle?.setToggleOff()
        }

        if (!FingerPrintUtil.Companion.instance().getHandPass().equals("")) {
            handToggle?.setToggleOn()
        } else {
            handToggle?.setToggleOff()
        }

        if (!FingerPrintUtil.instance().getHandPass().equals("")) {
            lin_update?.visibility = View.VISIBLE
        } else {
            lin_update?.visibility = View.GONE
        }
    }

    fun init() {
        finger_tip = findViewById<TextView>(R.id.finger_tip) as TextView
        rela_finger = findViewById<RelativeLayout>(R.id.rela_finger) as RelativeLayout
        fingerToggle = findViewById<MyToggleButton>(R.id.zhiwen) as MyToggleButton
        handToggle = findViewById<MyToggleButton>(R.id.shoushi) as MyToggleButton
        lin_update = findViewById<LinearLayout>(R.id.lin_update) as LinearLayout

        //修改手势密码
        lin_update?.setOnClickListener({
            startActivity(Intent(mContext, CheckPasswordActivity::class.java))
        })

        var bo: Boolean? = FingerPrintUtil.Companion.instance().isFingerPrintAvaliable()
        if (bo != null && bo) {
            //支持指纹的设备显示指纹解锁栏目
            rela_finger?.visibility = android.view.View.VISIBLE
            finger_tip?.visibility = android.view.View.VISIBLE

            fingerToggle?.setOnToggleChanged(object : MyToggleButton.OnToggleChanged {
                override fun onToggle(on: Boolean) {
                    if (on) {
                        //开启指纹识别--验证指纹
                        //如果用户没有可用指纹--提示录入指纹
                        if (FingerPrintUtil.Companion.instance().isHaveFingerPrint() ?: false == false) {

                            CommonDialog(mContext)
                                    .setMessage("\n你尚未设置指纹或指纹功能\n未启用,请在手机系统中添加指纹\n")
                                    .setRightClick("确定", {
                                        fingerToggle?.setToggleOff()
                                    })
                                    .setCancelAble(false)
                                    .show()
                            return
                        }

                        //判断是否绑定手机号
                        if (!UserHelper.isBindPhone()) {
                            CommonDialog(mContext)
                                    .setMessage("\n为了您的账号安全,请绑定手机号\n")
                                    .setLeftOnclick("取消", {
                                        fingerToggle?.setToggleOff()
                                    })
                                    .setRightClick("确定", {
                                        fingerToggle?.setToggleOff()
                                        //跳转绑定手机号页面
                                        InputPhoneActivity.start(mContext, UserConstants.BIND_PHONE_ACTION, null, false)
                                    })
                                    .setCancelAble(false)
                                    .show()
                            return
                        }
                        //跳转指纹设置页
                        startActivity(Intent(mContext, SetFingerPrintActivity::class.java))
                    } else {
                        //提示
                        CommonDialog(mContext)
                                .setMessage("\n确认关闭指纹解锁?\n")
                                .setLeftOnclick("取消", {
                                    fingerToggle?.setToggleOn()
                                })
                                .setRightClick("确定", {
                                    //关闭指纹识别
                                    FingerPrintUtil.Companion.instance().setFingerStatus(on)
                                })
                                .setCancelAble(false)
                                .show()
                    }
                }

            })
        }


        handToggle?.setOnToggleChanged(object : MyToggleButton.OnToggleChanged {
            override fun onToggle(on: Boolean) {
                if (on) {
                    //判断是否绑定手机号
                    if (!UserHelper.isBindPhone()) {
                        CommonDialog(mContext)
                                .setMessage("\n为了您的账号安全,请绑定手机号\n")
                                .setLeftOnclick("取消", {
                                    handToggle?.setToggleOff()
                                })
                                .setRightClick("确定", {
                                    handToggle?.setToggleOff()
                                    //跳转绑定手机号页面
                                    InputPhoneActivity.start(mContext, UserConstants.BIND_PHONE_ACTION, null, false);
                                })
                                .setCancelAble(false)
                                .show()
                        return
                    }

                    //验证登录密码
                    CheckPasswordActivity.startActivity(mContext)
                } else {
                    //提示
                    CommonDialog(mContext)
                            .setMessage("\n确认关闭手势密码?\n")
                            .setLeftOnclick("取消", {
                                handToggle?.setToggleOn()
                            })
                            .setRightClick("确定", {
                                lin_update?.visibility = View.GONE
                                FingerPrintUtil.Companion.instance().setHandPassword("")
                            })
                            .show()
                }
            }
        })

    }
}