package com.qimai.android.widget

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.qimai.android.widgetlib.rvrelate.GridItemDivider
import kotlinx.android.synthetic.main.activity_grid_divider.*

class GridDividerActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_grid_divider)
        val gridLayoutManager = GridLayoutManager(this, 3)
        val datas = mutableListOf<String>("1", "2")

        val adapter = GridAdatper(datas)
        grid.layoutManager   =gridLayoutManager
        grid.addItemDecoration(GridItemDivider(ContextCompat.getDrawable(this,R.drawable.griddivide)))
        grid.adapter = adapter

    }


}

class GridAdatper(var datas: MutableList<String>) : RecyclerView.Adapter<GridViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GridViewHolder {
        val itemview =
            LayoutInflater.from(parent.context).inflate(R.layout.grid_item, parent, false)
        return GridViewHolder(itemView = itemview)

    }

    override fun getItemCount(): Int {
        return datas.size
    }

    override fun onBindViewHolder(holder: GridViewHolder, position: Int) {
        holder.conent.text = datas[position]
    }

}

class GridViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    val conent: TextView = itemView.findViewById<TextView>(R.id.conent)


}
