package com.dlc.eboard.ui.common

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.dlc.eboard.databinding.ItemNoticeFlipperBinding

/**
 * info
 *
 * @author ReiChin_
 */
class SimpleFlipperAdapter(
    private val textColor: Int = Color.WHITE,
    private val data: MutableList<String>?
) : BaseAdapter() {

    override fun getCount() = data?.size ?: 0

    override fun getItem(position: Int): String? {
        return data?.get(position)
    }

    override fun getItemId(position: Int) = position.toLong()

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val textView: TextView
        val viewHolder: ViewHolder
        if (convertView == null) {
            textView = ItemNoticeFlipperBinding.inflate(LayoutInflater.from(parent!!.context)).root
            viewHolder = ViewHolder(textView)
            textView.tag = viewHolder
        } else {
            textView = convertView as TextView
            viewHolder = convertView.tag as ViewHolder
        }

        viewHolder.textView.setTextColor(textColor)
        viewHolder.textView.text = getItem(position)
        return textView
    }

    class ViewHolder(val textView: TextView)

}