package com.ysnows.base.binding;

import android.app.Activity;
import android.view.View;

import com.ysnows.base.utils.AnimateUtils;
import com.ysnows.base.utils.UiSwitch;

import androidx.core.view.ViewCompat;
import androidx.core.view.ViewPropertyAnimatorCompat;
import androidx.databinding.BindingAdapter;

public class ViewBindingAdapter {

    @BindingAdapter("view_push")
    public static void viewPush(View view, Class<Activity> activityClass) {
        UiSwitch.single(view.getContext(), activityClass);
    }

    @BindingAdapter("animate_visibility")
    public static void animateVisibility(View view, int visibility) {

        ViewPropertyAnimatorCompat animate = ViewCompat.animate(view);

        if (visibility == View.VISIBLE) {

            animate
                    .setDuration(150)
                    .scaleX(1f)
                    .scaleY(1f)
                    .alpha(1f)
                    .setInterpolator(new AnimateUtils.CycleInterpolator())
                    .withLayer()
                    .start();
        } else {
            animate
                    .setDuration(150)
                    .scaleX(0f)
                    .scaleY(0f)
                    .alpha(0f)
                    .setInterpolator(new AnimateUtils.CycleInterpolator())
                    .withLayer()
                    .start();

        }
    }

}
