package com.phlx.anchorcollect.event;

import org.greenrobot.eventbus.EventBus;

/**
 * <pre>
 *     author : lei
 *     e-mail : 18600395998@163.com
 *     time   : 2019/08/26
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class EventUtils {

    private EventUtils() {
    }

    /**
     * 注册 EventBus
     *
     * @param subscriber 订阅者
     */
    public static void register(Object subscriber) {
        EventBus eventBus = EventBus.getDefault();
        if (!eventBus.isRegistered(subscriber)) {
            eventBus.register(subscriber);
        }
    }

    /**
     * 解除注册 EventBus
     *
     * @param subscriber 订阅者
     */
    public static void unregister(Object subscriber) {
        EventBus eventBus = EventBus.getDefault();
        if (eventBus.isRegistered(subscriber)) {
            eventBus.unregister(subscriber);
        }
    }

    /**
     * 发送事件消息
     *
     * @param event 带值传送
     */
    public static void post(@SuppressWarnings("rawtypes") EventMsg event) {
        EventBus.getDefault().post(event);
    }


}
