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.ItemPeopleinfoBinding
import com.zswc.creativity.model.DataInfoBean
import com.yanzhenjie.permission.Action
import com.yanzhenjie.permission.AndPermission
import com.ysnows.base.base.BAdapter
import com.ysnows.base.ccretrofit.CCRetrofit
import com.ysnows.base.model.PositionBean
import com.ysnows.base.route.IGaode

class OrderInfoadapter(var list: ArrayList<PositionBean>, var isShow: Boolean) : BAdapter<DataInfoBean.OrderBean.SendBean,
        BaseDataBindingHolder<ItemPeopleinfoBinding>>(R.layout.item_peopleinfo) {
    @SuppressLint("WrongConstant")
    override fun convert(holder: BaseDataBindingHolder<ItemPeopleinfoBinding>, item: DataInfoBean.OrderBean.SendBean) {
        holder.dataBinding?.item = item
        holder.dataBinding?.isShow = isShow
        holder.dataBinding?.imgMap!!.onClick {

            CCRetrofit.instance()
                    .with(context)
                    .create(IGaode::class.java)
                    .goPolyline(list)
                    .subscribe()
        }


        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()

        }

    }
}
