package com.tencent.liteav.demo.player.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;

import com.tencent.liteav.demo.player.R;

public class MenuItemView extends LinearLayout {
    private ImageView imageIcon;
    private TextView textTitle;

    public MenuItemView(Context context) {
        this(context, null);
    }

    public MenuItemView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MenuItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public MenuItemView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context, attrs, defStyleAttr, defStyleRes);
    }

    private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        LayoutInflater.from(context).inflate(R.layout.item_menu, this);

        imageIcon = findViewById(R.id.item_menu_image);
        textTitle = findViewById(R.id.item_menu_text);
    }

    public void setTitle(String title) {
        textTitle.setText(title);
        invalidate();
    }

    public void setIcon(@DrawableRes int res) {
        imageIcon.setImageDrawable(getResources().getDrawable(res, null));
        invalidate();
    }
}
