From 012840abbae87b92b424534dd2f45c3ea48b9ce2 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 5 Sep 2019 18:14:05 +0200 Subject: [PATCH] Progress in initial sync dialog is decreasing for a step and should not (#532) --- CHANGES.md | 1 + .../session/DefaultInitialSyncProgressService.kt | 6 +++--- .../internal/session/sync/RoomSyncHandler.kt | 16 ++++++---------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index df1379d4e2..7655c08dc5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Other changes: Bugfix: - Fix crash due to missing informationData (#535) + - Progress in initial sync dialog is decreasing for a step and should not (#532) Translations: - diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultInitialSyncProgressService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultInitialSyncProgressService.kt index 1d3ce23302..6eb1ec35c1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultInitialSyncProgressService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultInitialSyncProgressService.kt @@ -128,11 +128,11 @@ inline fun Map.mapWithProgress(reporter: DefaultInitialSyncP taskId: Int, weight: Float, transform: (Map.Entry) -> R): List { - val total = count() + val total = count().toFloat() var current = 0 reporter?.startTask(taskId, 100, weight) - return this.map { - reporter?.reportProgress((current / total.toFloat() * 100).toInt()) + return map { + reporter?.reportProgress((current / total * 100).toInt()) current++ transform.invoke(it) }.also { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt index 0ebca5e130..fccaa9b9b2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt @@ -97,12 +97,12 @@ internal class RoomSyncHandler @Inject constructor(private val monarchy: Monarch handleJoinedRoom(realm, it.key, it.value, isInitialSync) } is HandlingStrategy.INVITED -> - handlingStrategy.data.mapWithProgress(reporter, R.string.initial_sync_start_importing_account_invited_rooms, 0.4f) { + handlingStrategy.data.mapWithProgress(reporter, R.string.initial_sync_start_importing_account_invited_rooms, 0.1f) { handleInvitedRoom(realm, it.key, it.value) } is HandlingStrategy.LEFT -> { - handlingStrategy.data.mapWithProgress(reporter, R.string.initial_sync_start_importing_account_left_rooms, 0.2f) { + handlingStrategy.data.mapWithProgress(reporter, R.string.initial_sync_start_importing_account_left_rooms, 0.3f) { handleLeftRoom(realm, it.key, it.value) } } @@ -125,8 +125,7 @@ internal class RoomSyncHandler @Inject constructor(private val monarchy: Monarch handleRoomAccountDataEvents(realm, roomId, roomSync.accountData) } - val roomEntity = RoomEntity.where(realm, roomId).findFirst() - ?: realm.createObject(roomId) + val roomEntity = RoomEntity.where(realm, roomId).findFirst() ?: realm.createObject(roomId) if (roomEntity.membership == Membership.INVITE) { roomEntity.chunks.deleteAllFromRealm() @@ -135,8 +134,7 @@ internal class RoomSyncHandler @Inject constructor(private val monarchy: Monarch // State event if (roomSync.state != null && roomSync.state.events.isNotEmpty()) { - val minStateIndex = roomEntity.untimelinedStateEvents.where().min(EventEntityFields.STATE_INDEX)?.toInt() - ?: Int.MIN_VALUE + val minStateIndex = roomEntity.untimelinedStateEvents.where().min(EventEntityFields.STATE_INDEX)?.toInt() ?: Int.MIN_VALUE val untimelinedStateIndex = minStateIndex + 1 roomSync.state.events.forEach { event -> roomEntity.addStateEvent(event, filterDuplicates = true, stateIndex = untimelinedStateIndex) @@ -167,8 +165,7 @@ internal class RoomSyncHandler @Inject constructor(private val monarchy: Monarch roomSync: InvitedRoomSync): RoomEntity { Timber.v("Handle invited sync for room $roomId") - val roomEntity = RoomEntity.where(realm, roomId).findFirst() - ?: realm.createObject(roomId) + val roomEntity = RoomEntity.where(realm, roomId).findFirst() ?: realm.createObject(roomId) roomEntity.membership = Membership.INVITE if (roomSync.inviteState != null && roomSync.inviteState.events.isNotEmpty()) { val chunkEntity = handleTimelineEvents(realm, roomEntity, roomSync.inviteState.events) @@ -181,8 +178,7 @@ internal class RoomSyncHandler @Inject constructor(private val monarchy: Monarch private fun handleLeftRoom(realm: Realm, roomId: String, roomSync: RoomSync): RoomEntity { - val roomEntity = RoomEntity.where(realm, roomId).findFirst() - ?: realm.createObject(roomId) + val roomEntity = RoomEntity.where(realm, roomId).findFirst() ?: realm.createObject(roomId) roomEntity.membership = Membership.LEAVE roomEntity.chunks.deleteAllFromRealm()