package com.gh.gamecenter.personalhome

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.feature.view.GameIconView
import com.gh.gamecenter.R
import com.gh.gamecenter.feature.entity.GameInstall
import com.lightgame.adapter.BaseRecyclerAdapter

class InstalledGameAdapter(mContext: Context, val games: ArrayList<GameInstall>) :
    BaseRecyclerAdapter<RecyclerView.ViewHolder>(mContext) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val view = View.inflate(mContext, com.gh.gamecenter.feature.R.layout.dialog_select_game_item, null)
        return object : RecyclerView.ViewHolder(view) {}
    }

    override fun getItemCount(): Int = games.size

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val gameInstall = games[position]
        holder.itemView.apply {
            findViewById<GameIconView>(R.id.game_icon).displayGameIcon(
                gameInstall.icon,
                gameInstall.iconSubScript,
                gameInstall.iconFloat
            )
            findViewById<TextView>(R.id.game_name).text = gameInstall.name
        }
    }
}