package app.furmeet.events.brasilfurfest.schedule.adapters

import android.database.DataSetObserver
import android.view.View
import android.view.ViewGroup
import android.widget.ListAdapter
import com.adlerosn.brasilfurfest.R
import app.furmeet.events.brasilfurfest.helper.Language
import app.furmeet.events.brasilfurfest.helper.inflate
import app.furmeet.events.brasilfurfest.helper.layoutInflater
import kotlinx.android.synthetic.main.dialogview_languageselector_item.view.*

class LanguageSelectorListAdapter(private val languages: List<Language>) : ListAdapter {
    override fun isEmpty(): Boolean = languages.isEmpty()
    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = convertView
                ?: parent.context.layoutInflater.inflate(R.layout.dialogview_languageselector_item)
        val item = getItem(position)
        view.lang_icon.setImageResource(item.drawableId)
        view.lang_label.text = item.nativeName
        return view
    }

    override fun registerDataSetObserver(observer: DataSetObserver?) {}
    override fun getItemViewType(position: Int): Int = 0
    override fun getViewTypeCount(): Int = 1
    override fun isEnabled(position: Int): Boolean = true
    override fun getItemId(position: Int): Long = position.toLong()
    override fun hasStableIds(): Boolean = true
    override fun areAllItemsEnabled(): Boolean = true
    override fun unregisterDataSetObserver(observer: DataSetObserver?) {}
    override fun getCount(): Int = languages.size
    override fun getItem(position: Int): Language = languages[position]
}
