package com.yidian.shenghuoquan.newscontent.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.yidian.shenghuoquan.newscontent.R
import com.yidian.shenghuoquan.newscontent.bean.Store
import com.yidian.shenghuoquan.newscontent.ui.EditStoreActivity
import com.yidian.shenghuoquan.newscontent.viewholder.StoreViewHolder

/**
 * Author: sym
 * Date: 2021/6/22 3:15 PM
 * Describe:
 */
class StoreAdapter(private val context: Context, private val dataList: ArrayList<Store>) : RecyclerView.Adapter<StoreViewHolder>() {
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StoreViewHolder {
    val view = LayoutInflater.from(context).inflate(R.layout.store_management_item, parent, false)
    return StoreViewHolder(view)
  }

  override fun onBindViewHolder(holder: StoreViewHolder, position: Int) {
    val store = dataList[position]
    holder.setData(store, position)
    holder.setOnListener(object : HolderListener {
      override fun jump() {
        context.startActivity(Intent(context, EditStoreActivity::class.java))
      }
    })
  }

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

  interface HolderListener {
    fun jump()
  }


}
