package com.zxbw.modulemain.activity

import android.text.TextUtils
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.zxbw.modulemain.R
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.Constant
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.utils.JumpUtils
import kotlinx.android.synthetic.main.activity_layout_setting.*

class SettingActivity : BaseActivity() {
    override fun onClick(v: View?) {

    }

    override fun before() {
        super.before()
        setStatusBarBackground(AppContext.get().resources.getColor(R.color.transparent))
    }

    override fun layoutID(): Int {
        return R.layout.activity_layout_setting
    }

    var adSwitch: Boolean? = false
    override fun init() {
        id_img_back?.setOnClickListener {
            finish()
        }
        val user = SettingPreference.getUserInfoData()
        if (user == null) {
            return
        }
        if (SettingPreference.getAdSwitch().equals("0")) {
            id_img_ad?.setImageResource(R.drawable.icon_guan)
        }else{
            id_img_ad?.setImageResource(R.drawable.icon_kai)
        }
        id_img_ad?.setOnClickListener {
            if (SettingPreference.getAdSwitch().equals("0")) {
                SettingPreference.setAdSwitch("1")
                id_img_ad?.setImageResource(R.drawable.icon_kai)
            } else {
                SettingPreference.setAdSwitch("0")
                id_img_ad?.setImageResource(R.drawable.icon_guan)
            }
        }
        id_tv_user_number?.text = user.nickname
        id_tv_number?.text = user.phone
        id_tv_id?.text = user.uid
        id_tv_version_code?.text = "V${Constant.Param.vn}"
        if (!TextUtils.isEmpty(user.headImage)) {
            Glide.with(this).load(user.headImage)
                .apply(RequestOptions.bitmapTransform(CircleCrop()))
                .error(R.drawable.icon_default_user_img)
                .into(id_img_user_head)
        } else {
            id_img_user_head.setImageResource(R.drawable.icon_head_defalt)
        }
        id_ll_tuichui_denglu?.setOnClickListener {
            SettingPreference.saveToken("")
            SettingPreference.saveUserInfo(null)
            finish()
            JumpUtils.loginJump()

        }
    }
}