package com.zswc.creativity.adapter

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.text.TextUtils
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.qmuiteam.qmui.kotlin.onClick
import com.zswc.creativity.R
import com.zswc.creativity.databinding.ItemEnterinfoBinding
import com.zswc.creativity.model.DataInfoBean
import com.yanzhenjie.permission.Action
import com.yanzhenjie.permission.AndPermission
import com.ysnows.base.base.BAdapter

class OrderInfoInadapter() : BAdapter<DataInfoBean.OrderBean.ReceiveBean, BaseDataBindingHolder<ItemEnterinfoBinding>>(R.layout.item_enterinfo) {

    @SuppressLint("WrongConstant")
    override fun convert(holder: BaseDataBindingHolder<ItemEnterinfoBinding>, item: DataInfoBean.OrderBean.ReceiveBean) {
        holder.dataBinding?.position=holder.adapterPosition
        holder.dataBinding?.item = item


        holder.dataBinding?.tvPhone!!.onClick {

            //拨打电话
            if (TextUtils.isEmpty(item.mobile)) {
                toast("未添加电话！！")
                return@onClick
            }
            AndPermission.with(context)
                    .runtime()
                    .permission(Manifest.permission.CALL_PHONE)
                    .onGranted(Action<List<String?>?> {
                        val intent = Intent(Intent.ACTION_DIAL)
                        val uri = Uri.parse("tel:$item.mobile")
                        intent.data = uri
                        context!!.startActivity(intent)
                    }).start()

        }

    }

}
