Last active
July 9, 2018 18:12
-
-
Save mayuroks/c8423ae23934d953cdf418ef3a9c6ebb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Remote data source. | |
* | |
*/ | |
public class RemoteDataSource implements DataSource { | |
private static RemoteDataSource INSTANCE; | |
private static EventService mEventService = EventServiceImpl.getInstance(); | |
private EventListener mRepoEventListener; | |
private RemoteDataSource() { | |
mEventService.setEventListener(this); | |
} | |
public static RemoteDataSource getInstance() { | |
if (INSTANCE == null) { | |
INSTANCE = new RemoteDataSource(); | |
} | |
return INSTANCE; | |
} | |
@Override | |
public void setEventListener(EventListener eventListener) { | |
mRepoEventListener = eventListener; | |
} | |
@Override | |
public void connect(String username) throws URISyntaxException { | |
mEventService.connect(username); | |
} | |
@Override | |
public void disconnect() { | |
mEventService.disconnect(); | |
} | |
@Override | |
public void onConnect(Object... args) { | |
if (mRepoEventListener != null) | |
mRepoEventListener.onConnect(args); | |
} | |
@Override | |
public void onDisconnect(Object... args) { | |
if (mRepoEventListener != null) | |
mRepoEventListener.onDisconnect(args); | |
} | |
@Override | |
public void onNewMessage(Object... args) { | |
if (mRepoEventListener != null) | |
mRepoEventListener.onNewMessage(args); | |
} | |
@Override | |
public Flowable<ChatMessage> sendMessage(ChatMessage chatMessage) { | |
return mEventService.sendMessage(chatMessage); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment