//响应事件源,多tag
@Subscribe(thread = EventThread.MAIN_THREAD,
tags = {@Tag(RxBusAction.MAIN_HOME_REFRESH),
@Tag(RxBusAction.ON_APP_LOGOUT)})
public void loadHomeModule(RxBusMsg<HomeModule> event) {
Clog.e("loadHomeModule ");
}
//响应事件源,单tag
@Subscribe(thread = EventThread.MAIN_THREAD, tag=RxBusAction.ON_APP_LOGIN)
public void refresh(RxBusMsg<HomeModule> event) {
Clog.e("refresh");
}
//post msg,根据 Action:ON_APP_LOGOUT可以直接查找订阅者,提供了两中响应的纬度
//1.action 2.class
RxBus.post(RxBusAction.ON_APP_LOGOUT, new RxBusMsg<HomeModule>(null));
/**
* 定义event action的常量
*
* @author GanQuan
* @since 2018/3/15.
*/
// msg constants
public interface RxBusAction {
String MAIN_HOME_REFRESH = "main_home_refresh";
String ON_APP_LOGOUT = "on_app_logout";
String ON_APP_LOGIN = "on_app_login";
}
/**
* event消息体
*
* @author GanQuan
* @since 2018/3/15.
*/
public class RxBusMsg<T> implements Serializable {
public String tag;
public T value;
/**
* @param value 当value为空时必须传入泛型的类型
*/
public RxBusMsg(@NonNull T value) {
this.value = value;
}
public RxBusMsg<String> obtainMsg(String msg) {
return new RxBusMsg<>(msg);
}
}