package com.cooleshow.base.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Checkable;

import com.airbnb.lottie.LottieAnimationView;

/**
 * Author by pq, Date on 2022/8/2.
 */
public class TabAnimationView extends LottieAnimationView implements Checkable {
    private boolean checked;

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

    public TabAnimationView(Context context, AttributeSet attrs) {
        this(context, attrs, -1);
    }

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

    private void init() {

    }

    @Override
    public boolean isChecked() {
        return this.checked;
    }

    @Override
    public void setChecked(boolean checked) {

        try {
            if (this.checked != checked) {
                this.checked = checked;
                if (isAnimating()) {
                    cancelAnimation();
                }
                if (checked) {
                    playAnimation();
//                    if (getSpeed() < 0.0F) {
//                        reverseAnimationSpeed();
//                        playAnimation();
//                    }
                } else {
                    setFrame(0);
                    setProgress(0);
//                    if (getSpeed() > 0.0F) {
//                        reverseAnimationSpeed();
//                    }
                }
//                playAnimation();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void toggle() {
        setChecked(!this.checked);
    }
}
