package com.orange.widget.ui

import android.content.Intent
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.orange.widget.vm.MainViewModel
import com.orange.origin.origin.BaseAgentActivity
import com.orange.tool.RouterPath
import com.orange.widget.R
import com.orange.widget.databinding.WidgetActivityMainBinding

@Route(path = RouterPath.WIDGET_MAIN)
 class MainActivity :BaseAgentActivity<MainViewModel,WidgetActivityMainBinding>(){
    private var data:ArrayList<Int> = ArrayList()

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

    override fun createLooker() {
    }

    override fun initDo(){
        for (i in 1..10){
            data.add(1)
        }
    }

    override fun initUi() {
        initRv()
    }

    private fun initRv(){
        iDataBinding.rv.run {
            layoutManager = LinearLayoutManager(activity)

            val adapter = object : BaseQuickAdapter<Int,BaseViewHolder>(R.layout.widget,data){
                override fun convert(holder: BaseViewHolder, item: Int) {
                    holder.itemView.layoutParams.height = 1000

                    holder.getView<ImageView>(R.id.iv).run {
                        setBackgroundResource(R.mipmap.aa)
                    }

                    holder.getView<TextView>(R.id.tv).run {
                        text = if(holder.layoutPosition%2==0) "图片" else "视频"
                    }
                }
            }
            this.adapter = adapter

            adapter.setOnItemClickListener { adapter, view, position ->
                if(position == 0){
                    startActivity(Intent(this@MainActivity,ModelActivity::class.java))
                }else{
                    if(position%2==0)
                        PictureActivity.start(this@MainActivity)
                    else
                        VideoActivity.start(this@MainActivity)
                }
                }


        }
    }

    override fun initData() {

    }

    override fun initEvent() {
    }

}