package com.zxhl.main.page.activity

import android.text.TextUtils
import android.util.Log
import android.view.View
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.model.uc.UserInfo
import com.zxhl.cms.utils.AdCallback
import com.zxhl.cms.utils.NoDoubleClickListener
import com.zxhl.cms.utils.UserDataUtils
import com.zxhl.cms.widget.LoadingDialog
import com.zxhl.main.R
import com.zxhl.main.page.contract.EditUserInfoContract
import com.zxhl.main.page.presenter.EditUserInfoPresenter
import kotlinx.android.synthetic.main.activity_layout_update_nick_name.*

class UpdateNickNameActivity : BaseActivity(), EditUserInfoContract.View, AdCallback<String> {
    private var mPresenter: EditUserInfoPresenter? = null
    private var mLoading: LoadingDialog? = null
    override fun init() {
        mPresenter = EditUserInfoPresenter(this)
        mLoading = LoadingDialog.getLoadingDialog(
            this,
            getString(com.zxhl.cms.R.string.wait_ing),
            false,
            false
        )
        id_img_back?.setOnClickListener {
            finish()
        }
        id_tv_sava_nick_name?.setOnClickListener(object : NoDoubleClickListener() {
            override fun onNoDoubleClick(v: View?) {

                saveName()
            }

        })
        id_img_clear?.setOnClickListener {
            id_edit_nickname?.setText("")
        }
    }

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

    override fun onClick(v: View?) {

    }

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

    fun saveName() {
        if (!TextUtils.isEmpty(id_edit_nickname.text.toString())) {
            mLoading?.setLoading("loading")
            mLoading?.show()
            mPresenter?.updateUserNickName(id_edit_nickname.text.toString())
        } else {
            showToast("please input")
        }
    }

    override fun setData(result: UserInfo?) {

    }

    override fun updateSuc() {
        mLoading?.setResult(true, "success", 1000)
        UserDataUtils.updateUserInfo(this)
    }

    override fun updateFail() {
        mLoading?.setResult(false, "fail", 1000)
    }

    override fun uploadSuc(result: String) {

    }

    override fun uploadFail() {

    }

    override fun updatePicSuc() {

    }

    override fun updatePicFail() {

    }

    override fun onResult(code: Int, result: String?) {
        finish()
    }
}