package com.bc_chat.contacts.ui.friend

import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bc_chat.bc_base.config.RouteConfig
import com.bc_chat.bc_base.http.Api
import com.bc_chat.bc_base.utils.AppConfig
import com.bc_chat.bc_base.utils.Const
import com.bc_chat.contacts.R
import com.bc_chat.contacts.databinding.ActivityPhoneInvitationBinding
import com.umeng.commonsdk.proguard.e.A
import com.zhaohaoting.framework.abs.BaseActivity
import com.zhaohaoting.framework.abs.contract.BaseContract
import com.zhaohaoting.framework.utils.Utils


/**
 * author：Created by zhaohaoting on 2019/3/7
 * email：526309416@qq.com
 * desc：电话号码邀请
 */
@Route(path = RouteConfig.PHONE_INVITATION_FRIEND_ACTIVITY)
class PhoneInvitationFriendActivity : BaseActivity<BaseContract.BasePresenter>() {

    @JvmField
    @Autowired
    var remark: String? = null

    @JvmField
    @Autowired
    var phone: String? = null

    private val binding by lazy {
        rootDataBinding as ActivityPhoneInvitationBinding
    }

    override fun initPresenter(): BaseContract.BasePresenter? = null

    override fun getLayoutResId(): Int = R.layout.activity_phone_invitation

    override fun initialize() {
        ARouter.getInstance().inject(this)
        binding.tvHead.text = remark?.substring(0, 1)
        binding.tvName.text = remark
        binding.tvPhone.text = phone
        binding.tvInvitation.setOnClickListener {
            judgePermission(Const.Permission.Key.READ_CONTACT, *Const.Permission.Value.READ_CONTACT)
        }
    }

    override fun requestPermissionSuccess(requestCode: Int) {
        Utils.insertContact(phone, remark, this)
        Utils.doSendSMSTo(phone, "好友${AppConfig.instance.getUser().nickname}邀请你加入飞信：${Api.SHARE_PATH}", this)
    }
}
