package com.orange.widget.ui

import android.content.Context
import android.content.Intent
import android.view.View
import cc.shinichi.library.ImagePreview
import com.alibaba.android.arouter.facade.annotation.Route
import com.orange.origin.origin.BaseAgentActivity
import com.orange.tool.RouterPath
import com.orange.widget.R
import com.orange.widget.databinding.ActivityPictureBinding
import com.orange.widget.vm.PictureViewModel

@Route(path = RouterPath.WIDGET_DRAW)
class PictureActivity:BaseAgentActivity<PictureViewModel,ActivityPictureBinding>() {
    val data = ArrayList<String>()

    companion object{
        fun start(context: Context){
            context.startActivity(Intent(context,PictureActivity::class.java))
        }
    }

    override fun getLayoutId(): Int = R.layout.activity_picture

    override fun createLooker() {

    }

    override fun initUi() {

    }

    override fun initData() {
    }

    override fun initEvent() {
        addInitEvent({
                     when(it.id){
                         R.id.iv->{
                             preview()
                         }
                         else->{

                         }
                     }

        },iDataBinding.iv)
    }

    private fun preview(){
        data.run {
            clear()
            add("https://img2.baidu.com/it/u=3202947311,1179654885&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500")
            add("https://img1.baidu.com/it/u=1876627393,303388089&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=313")
            add("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fss2.meipian.me%2Fusers%2F32786690%2Forigin41d59d038765a5a09b861befc0f6f784.gif%3Fmeipian-raw%2Fbucket%2Fivwen%2Fkey%2FdXNlcnMvMzI3ODY2OTAvb3JpZ2luNDFkNTlkMDM4NzY1YTVhMDliODYxYmVmYzBmNmY3ODQuZ2lm%2Fsign%2F3151ea7791f366828fabffeaa6e6e3f6.jpg&refer=http%3A%2F%2Fss2.meipian.me&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1679473350&t=0d32c4384eb08e7f369996862738502d")


        }
        ImagePreview.instance
            .setContext(this)
            .setIndex(0)
            .setImageList(data)
            .start()
    }

    fun addInitEvent(l:(View)->Unit,vararg arr:View){
        for (v in arr){
            v.setOnClickListener(l)
        }
    }

}