-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from NaikSoftware/forresthopkins-feature/deep-…
…refactor Forresthopkins/DrStranges deep refactor
- Loading branch information
Showing
17 changed files
with
469 additions
and
373 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.idea | ||
.DS_Store | ||
/build | ||
/captures | ||
/captures |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Thu Feb 23 17:37:13 EET 2017 | ||
#Tue Sep 05 08:26:08 MST 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip |
This file contains 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
13 changes: 0 additions & 13 deletions
13
lib/src/androidTest/java/ua/naiksoftware/stomp/ApplicationTest.java
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="ua.naiksoftware.stomp"> | ||
<manifest package="com.github.forresthopkinsa"> | ||
|
||
<application/> | ||
<application /> | ||
|
||
</manifest> |
123 changes: 123 additions & 0 deletions
123
lib/src/main/java/ua/naiksoftware/stomp/AbstractConnectionProvider.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package ua.naiksoftware.stomp; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.util.Log; | ||
|
||
import io.reactivex.Completable; | ||
import io.reactivex.Observable; | ||
import io.reactivex.subjects.PublishSubject; | ||
|
||
/** | ||
* Created by forresthopkinsa on 8/8/2017. | ||
* <p> | ||
* Created because there was a lot of shared code between JWS and OkHttp connection providers. | ||
*/ | ||
|
||
abstract class AbstractConnectionProvider implements ConnectionProvider { | ||
|
||
private static final String TAG = AbstractConnectionProvider.class.getSimpleName(); | ||
|
||
@NonNull | ||
private final PublishSubject<LifecycleEvent> mLifecycleStream; | ||
@NonNull | ||
private final PublishSubject<String> mMessagesStream; | ||
|
||
AbstractConnectionProvider() { | ||
mLifecycleStream = PublishSubject.create(); | ||
mMessagesStream = PublishSubject.create(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Observable<String> messages() { | ||
return mMessagesStream.startWith(initSocket().toObservable()); | ||
} | ||
|
||
/** | ||
* Simply close socket. | ||
* <p> | ||
* For example: | ||
* <pre> | ||
* webSocket.close(); | ||
* </pre> | ||
*/ | ||
abstract void rawDisconnect(); | ||
|
||
@Override | ||
public Completable disconnect() { | ||
return Completable | ||
.fromAction(this::rawDisconnect); | ||
} | ||
|
||
private Completable initSocket() { | ||
return Completable | ||
.fromAction(this::createWebSocketConnection); | ||
} | ||
|
||
// Doesn't do anything at all, only here as a stub | ||
public Completable setHeartbeat(int ms) { | ||
return Completable.complete(); | ||
} | ||
|
||
/** | ||
* Most important method: connects to websocket and notifies program of messages. | ||
* <p> | ||
* See implementations in OkHttpConnectionProvider and WebSocketsConnectionProvider. | ||
*/ | ||
abstract void createWebSocketConnection(); | ||
|
||
@NonNull | ||
@Override | ||
public Completable send(String stompMessage) { | ||
return Completable.fromCallable(() -> { | ||
if (getSocket() == null) { | ||
throw new IllegalStateException("Not connected yet"); | ||
} else { | ||
Log.d(TAG, "Send STOMP message: " + stompMessage); | ||
rawSend(stompMessage); | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Just a simple message send. | ||
* <p> | ||
* For example: | ||
* <pre> | ||
* webSocket.send(stompMessage); | ||
* </pre> | ||
* | ||
* @param stompMessage message to send | ||
*/ | ||
abstract void rawSend(String stompMessage); | ||
|
||
/** | ||
* Get socket object. | ||
* Used for null checking; this object is expected to be null when the connection is not yet established. | ||
* <p> | ||
* For example: | ||
* <pre> | ||
* return webSocket; | ||
* </pre> | ||
*/ | ||
@Nullable | ||
abstract Object getSocket(); | ||
|
||
void emitLifecycleEvent(@NonNull LifecycleEvent lifecycleEvent) { | ||
Log.d(TAG, "Emit lifecycle event: " + lifecycleEvent.getType().name()); | ||
mLifecycleStream.onNext(lifecycleEvent); | ||
} | ||
|
||
void emitMessage(String stompMessage) { | ||
Log.d(TAG, "Emit STOMP message: " + stompMessage); | ||
mMessagesStream.onNext(stompMessage); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Observable<LifecycleEvent> lifecycle() { | ||
return mLifecycleStream; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.