This repository was archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 553
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 #678 from RocketChat/develop
[RELEASE] Merge develop into master
- Loading branch information
Showing
93 changed files
with
5,594 additions
and
3,790 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
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
825 changes: 426 additions & 399 deletions
825
android-ddp/src/main/java/chat/rocket/android_ddp/DDPClientImpl.java
Large diffs are not rendered by default.
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
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
90 changes: 90 additions & 0 deletions
90
app/src/main/java/chat/rocket/android/ConnectionStatusManager.kt
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,90 @@ | ||
package chat.rocket.android | ||
|
||
import chat.rocket.android.extensions.printStackTraceOnDebug | ||
import chat.rocket.android.service.KeepAliveJob | ||
import unquietcode.tools.esm.EnumStateMachine | ||
import unquietcode.tools.esm.TransitionException | ||
|
||
object ConnectionStatusManager { | ||
enum class State { | ||
OFFLINE, CONNECTING, ONLINE | ||
} | ||
|
||
private const val DEBUG = false | ||
private val DEFAULT_CALLBACK = object : TransitionCallback { | ||
override fun onTransitioned(success: Boolean) { | ||
} | ||
} | ||
private val stateMachine: EnumStateMachine<State> | ||
|
||
init { | ||
stateMachine = EnumStateMachine(State.OFFLINE) | ||
|
||
stateMachine.addTransitions(State.OFFLINE, State.CONNECTING) | ||
stateMachine.addTransitions(State.CONNECTING, State.ONLINE, State.OFFLINE) | ||
stateMachine.addTransitions(State.ONLINE, State.OFFLINE) | ||
} | ||
|
||
@Synchronized | ||
fun transitionCount() = stateMachine.transitionCount() | ||
|
||
@Synchronized | ||
fun currentState() = stateMachine.currentState() | ||
|
||
@Synchronized | ||
fun setOnline(callback: TransitionCallback = DEFAULT_CALLBACK) { | ||
KeepAliveJob.cancelPendingJobRequests() | ||
tryTransitionTo(State.ONLINE, callback) | ||
} | ||
|
||
@Synchronized | ||
fun setOnline() { | ||
KeepAliveJob.cancelPendingJobRequests() | ||
tryTransitionTo(State.ONLINE, DEFAULT_CALLBACK) | ||
} | ||
|
||
@Synchronized | ||
fun setConnecting(callback: TransitionCallback = DEFAULT_CALLBACK) { | ||
KeepAliveJob.cancelPendingJobRequests() | ||
tryTransitionTo(State.CONNECTING, callback) | ||
} | ||
|
||
@Synchronized | ||
fun setConnecting() { | ||
KeepAliveJob.cancelPendingJobRequests() | ||
tryTransitionTo(State.CONNECTING, DEFAULT_CALLBACK) | ||
} | ||
|
||
@Synchronized | ||
fun setConnectionError(callback: TransitionCallback = DEFAULT_CALLBACK) { | ||
KeepAliveJob.schedule() | ||
tryTransitionTo(State.OFFLINE, callback) | ||
} | ||
|
||
@Synchronized | ||
fun setConnectionError() { | ||
KeepAliveJob.schedule() | ||
tryTransitionTo(State.OFFLINE, DEFAULT_CALLBACK) | ||
} | ||
|
||
@Synchronized | ||
fun setOffline() { | ||
stateMachine.reset() | ||
} | ||
|
||
private fun tryTransitionTo(newState: State, callback: TransitionCallback) { | ||
try { | ||
stateMachine.transition(newState) | ||
callback.onTransitioned(true) | ||
} catch (e: TransitionException) { | ||
if (DEBUG) { | ||
e.printStackTraceOnDebug() | ||
} | ||
callback.onTransitioned(false) | ||
} | ||
} | ||
|
||
interface TransitionCallback { | ||
fun onTransitioned(success: Boolean) | ||
} | ||
} |
Oops, something went wrong.