package com.khmer9.lotto.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.khmer9.lotto.R;

public class SquareView  extends ConstraintLayout {
    TextView tvNumber;
    TextView tvRangNumber;

    public SquareView(@NonNull Context context) {
        super(context);
        init();

    }

    public SquareView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
        setStyle(attrs);

    }

    public SquareView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
        setStyle(attrs);
    }

    public SquareView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
        setStyle(attrs);
    }
    private void init() {
        View view = LayoutInflater.from(getContext()).inflate(
                R.layout.view_square, this, true);
        tvNumber = view.findViewById(R.id.tv_number) ;
        tvRangNumber = view.findViewById(R.id.tv_range);

    }
    private void setStyle(AttributeSet attrs){
        TypedArray a = getContext().getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.SquareView,
                0, 0);
        try {
            String textNumber = a.getString(R.styleable.SquareView_numberValue);
            String textRangeNumber = a.getString(R.styleable.SquareView_rangNumber);
            tvNumber.setText(textNumber);
            tvRangNumber.setText(textRangeNumber);

        } finally {
            a.recycle();
        }
    }

}
