I am use Otto library in my project. And me need any functionality from this library wherein not.I want to do so:
Bus.post(MessageType.USER_SIGN_UP_SUCCESS, user);
and in my method realise do so:
@Subscribe({MessageType.USER_LOGGED_IN_SUCCESS, MessageType.USER_SIGN_UP_SUCCESS})
public void getUserFromServer(User user) {
,,,,,,,,,,,,,,
}
for this I had to copy all Otto classes from githab, and change them. I could not implement from Otto because some variables private.
and changed the access modifiers in Bus class and extends from it.
public class SkipBus extends Bus {
public void post(MessageType messageType, Object event) {
if (event == null) {
throw new NullPointerException("Event to post must not be null.");
}
enforcer.enforce(this);
Set<Class<?>> dispatchTypes = flattenHierarchy(event.getClass());
boolean dispatched = false;
for (Class<?> eventType : dispatchTypes) {
Set<EventHandler> wrappers = getHandlersForEventType(eventType);
if (null == wrappers || wrappers.isEmpty()) {
continue;
}
dispatched = true;
for (EventHandler wrapper : wrappers) {
Subscribe annotation = wrapper.method.getAnnotation(Subscribe.class);
boolean isFounded = false;
MessageType messageTypes[] = annotation.value();
for (MessageType type : messageTypes) {
if (type == messageType) {
isFounded = true;
break;
}
}
if (isFounded) {
enqueueEvent(event, wrapper);
}
}
}
if (!dispatched && !(event instanceof DeadEvent)) {
post(new DeadEvent(this, event));
}
dispatchQueuedEvents();
}
}
but for this I had to copy all the classes in my project. tell me how can I make it easier? or tell me another library that can do what I want