From 261b4be2875acb80fa1dcae8991b43b719556b25 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 11 Dec 2019 18:51:46 +0100 Subject: [PATCH] Follow naming convention --- .../android/api/session/sync/SyncState.kt | 14 +++++----- .../internal/session/sync/job/SyncThread.kt | 28 +++++++++---------- .../features/home/HomeDetailViewState.kt | 2 +- .../home/room/detail/RoomDetailViewState.kt | 2 +- .../features/sync/widget/SyncStateView.kt | 4 +-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/sync/SyncState.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/sync/SyncState.kt index 6656d52e5e..4890c28331 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/sync/SyncState.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/sync/SyncState.kt @@ -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() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt index 19cde7d597..69e03c6269 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt @@ -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() 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) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeDetailViewState.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeDetailViewState.kt index c7c5e4a233..1777fa03c1 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeDetailViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeDetailViewState.kt @@ -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 diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt index a0be8fc9dc..b2ad29668e 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt @@ -58,7 +58,7 @@ data class RoomDetailViewState( val isEncrypted: Boolean = false, val tombstoneEvent: Event? = null, val tombstoneEventHandling: Async = Uninitialized, - val syncState: SyncState = SyncState.IDLE, + val syncState: SyncState = SyncState.Idle, val highlightedEventId: String? = null, val unreadState: UnreadState = UnreadState.Unknown, val canShowJumpToReadMarker: Boolean = true diff --git a/vector/src/main/java/im/vector/riotx/features/sync/widget/SyncStateView.kt b/vector/src/main/java/im/vector/riotx/features/sync/widget/SyncStateView.kt index d03c49acc0..b8856dddb1 100755 --- a/vector/src/main/java/im/vector/riotx/features/sync/widget/SyncStateView.kt +++ b/vector/src/main/java/im/vector/riotx/features/sync/widget/SyncStateView.kt @@ -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 } }