package com.zswc.creativity.adapter

import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.qmuiteam.qmui.kotlin.onClick
import com.zswc.creativity.R
import com.zswc.creativity.databinding.ItemModelBinding
import com.yanzhenjie.permission.AndPermission
import com.yanzhenjie.permission.runtime.Permission
import com.ysnows.base.base.BAdapter
import com.ysnows.base.ccretrofit.CCRetrofit
import com.ysnows.base.route.ILookimg
import java.util.*

class ModelAdapter(var list: ArrayList<String>) : BAdapter<String, BaseDataBindingHolder<ItemModelBinding>>(R.layout.item_model) {

    override fun convert(holder: BaseDataBindingHolder<ItemModelBinding>, item: String) {
        holder.dataBinding?.item = item

        holder.dataBinding?.imgAttachment?.onClick {
            //查看大图


            AndPermission.with(context)
                    .runtime()
                    .permission(
                            Permission.WRITE_EXTERNAL_STORAGE,
                            Permission.READ_EXTERNAL_STORAGE
                    )
                    .onGranted { data ->
                        CCRetrofit.instance()
                                .create(ILookimg::class.java)
                                .previewImageArr(list,holder.adapterPosition)
                                .subscribe()
                    }
                    .start()

        }
    }
}
