Follow naming convention

This commit is contained in:
Benoit Marty 2019-12-11 18:51:46 +01:00
parent 205fc0d9d6
commit 261b4be287
5 changed files with 25 additions and 25 deletions

View File

@ -17,11 +17,11 @@
package im.vector.matrix.android.api.session.sync
sealed class SyncState {
object IDLE : SyncState()
data class RUNNING(val afterPause: Boolean) : SyncState()
object PAUSED : SyncState()
object KILLING : SyncState()
object KILLED : SyncState()
object NO_NETWORK : SyncState()
object INVALID_TOKEN : SyncState()
object Idle : SyncState()
data class Running(val afterPause: Boolean) : SyncState()
object Paused : SyncState()
object Killing : SyncState()
object Killed : SyncState()
object NoNetwork : SyncState()
object InvalidToken : SyncState()
}

View File

@ -44,7 +44,7 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
private val taskExecutor: TaskExecutor
) : Thread(), NetworkConnectivityChecker.Listener, BackgroundDetectionObserver.Listener {
private var state: SyncState = SyncState.IDLE
private var state: SyncState = SyncState.Idle
private var liveState = MutableLiveData<SyncState>()
private val lock = Object()
private var cancelableTask: Cancelable? = null
@ -53,11 +53,11 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
private var isTokenValid = true
init {
updateStateTo(SyncState.IDLE)
updateStateTo(SyncState.Idle)
}
fun setInitialForeground(initialForeground: Boolean) {
val newState = if (initialForeground) SyncState.IDLE else SyncState.PAUSED
val newState = if (initialForeground) SyncState.Idle else SyncState.Paused
updateStateTo(newState)
}
@ -81,7 +81,7 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
fun kill() = synchronized(lock) {
Timber.v("Kill sync...")
updateStateTo(SyncState.KILLING)
updateStateTo(SyncState.Killing)
cancelableTask?.cancel()
lock.notify()
}
@ -103,31 +103,31 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
networkConnectivityChecker.register(this)
backgroundDetectionObserver.register(this)
while (state != SyncState.KILLING) {
while (state != SyncState.Killing) {
Timber.v("Entering loop, state: $state")
if (!networkConnectivityChecker.hasInternetAccess) {
Timber.v("No network. Waiting...")
updateStateTo(SyncState.NO_NETWORK)
updateStateTo(SyncState.NoNetwork)
synchronized(lock) { lock.wait() }
Timber.v("...unlocked")
} else if (!isStarted) {
Timber.v("Sync is Paused. Waiting...")
updateStateTo(SyncState.PAUSED)
updateStateTo(SyncState.Paused)
synchronized(lock) { lock.wait() }
Timber.v("...unlocked")
} else if (!isTokenValid) {
Timber.v("Token is invalid. Waiting...")
updateStateTo(SyncState.INVALID_TOKEN)
updateStateTo(SyncState.InvalidToken)
synchronized(lock) { lock.wait() }
Timber.v("...unlocked")
} else {
if (state !is SyncState.RUNNING) {
updateStateTo(SyncState.RUNNING(afterPause = true))
if (state !is SyncState.Running) {
updateStateTo(SyncState.Running(afterPause = true))
}
// No timeout after a pause
val timeout = state.let { if (it is SyncState.RUNNING && it.afterPause) 0 else DEFAULT_LONG_POOL_TIMEOUT }
val timeout = state.let { if (it is SyncState.Running && it.afterPause) 0 else DEFAULT_LONG_POOL_TIMEOUT }
Timber.v("Execute sync request with timeout $timeout")
val latch = CountDownLatch(1)
@ -172,8 +172,8 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
latch.await()
state.let {
if (it is SyncState.RUNNING && it.afterPause) {
updateStateTo(SyncState.RUNNING(afterPause = false))
if (it is SyncState.Running && it.afterPause) {
updateStateTo(SyncState.Running(afterPause = false))
}
}
@ -181,7 +181,7 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
}
}
Timber.v("Sync killed")
updateStateTo(SyncState.KILLED)
updateStateTo(SyncState.Killed)
backgroundDetectionObserver.unregister(this)
networkConnectivityChecker.unregister(this)
}

View File

@ -34,5 +34,5 @@ data class HomeDetailViewState(
val notificationHighlightPeople: Boolean = false,
val notificationCountRooms: Int = 0,
val notificationHighlightRooms: Boolean = false,
val syncState: SyncState = SyncState.IDLE
val syncState: SyncState = SyncState.Idle
) : MvRxState

View File

@ -58,7 +58,7 @@ data class RoomDetailViewState(
val isEncrypted: Boolean = false,
val tombstoneEvent: Event? = null,
val tombstoneEventHandling: Async<String> = Uninitialized,
val syncState: SyncState = SyncState.IDLE,
val syncState: SyncState = SyncState.Idle,
val highlightedEventId: String? = null,
val unreadState: UnreadState = UnreadState.Unknown,
val canShowJumpToReadMarker: Boolean = true

View File

@ -34,9 +34,9 @@ class SyncStateView @JvmOverloads constructor(context: Context, attrs: Attribute
fun render(newState: SyncState) {
syncStateProgressBar.visibility = when (newState) {
is SyncState.RUNNING -> if (newState.afterPause) View.VISIBLE else View.GONE
is SyncState.Running -> if (newState.afterPause) View.VISIBLE else View.GONE
else -> View.GONE
}
syncStateNoNetwork.isVisible = newState == SyncState.NO_NETWORK
syncStateNoNetwork.isVisible = newState == SyncState.NoNetwork
}
}