package com.example.myapplication.keyboard

import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import com.example.myapplication.R

class PageIndicator(
    private val container: LinearLayout
) {
    fun setPageCount(count: Int) {
        container.removeAllViews()
        val inflater = LayoutInflater.from(container.context)
        repeat(count) {
            container.addView(inflater.inflate(R.layout.item_dot, container, false))
        }
        setSelected(0)
    }

    fun setSelected(index: Int) {
        for (i in 0 until container.childCount) {
            container.getChildAt(i).isSelected = (i == index)
        }
    }

    fun clear() {
        container.removeAllViews()
    }
}
