package com.khmer9.yuki.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.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.khmer9.yuki.R;

public class CircleView  extends ConstraintLayout {
    ImageView imageViewLoto;
    TextView tvValue;

    public CircleView(@NonNull Context context) {
        super(context);
        init();
    }

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

    }

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

    public CircleView(@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_circle, this, true);
        imageViewLoto = view.findViewById(R.id.iv_logo) ;
        tvValue = view.findViewById(R.id.tv_value);

    }

    private void setStyle(AttributeSet attrs){
        TypedArray a = getContext().getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.CircleView,
                0, 0);

        try {
           // Drawable drawable = a.getDrawable(R.styleable.CircleView_currencyImage);
            int symbol_resID = a.getResourceId(R.styleable.CircleView_currencyImage, R.drawable.text_dollar);
            imageViewLoto.setImageResource(symbol_resID);
            String text = a.getString(R.styleable.CircleView_currencyValue);
           // imageViewLoto.setBackground(drawable);
            tvValue.setText(text);

        } finally {
            a.recycle();
        }
    }
//    public boolean isShowText() {
//        return mShowText;
//    }
//
//    public void setShowText(boolean showText) {
//        mShowText = showText;
//        invalidate();
//        requestLayout();
//    }
}
