forked from GitHub-Mirror/riotX-android
cleaning
This commit is contained in:
parent
95d83db90c
commit
8159a52bd7
@ -95,3 +95,18 @@ public inline fun <T> reportSubtask(reporter: DefaultInitialSyncProgressService?
|
|||||||
reporter?.endTask(nameRes)
|
reporter?.endTask(nameRes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public inline fun <K, V, R> Map<out K, V>.mapWithProgress(reporter: DefaultInitialSyncProgressService?, taskId: Int, weight: Float, transform: (Map.Entry<K, V>) -> R): List<R> {
|
||||||
|
val total = this.count()
|
||||||
|
var current = 0
|
||||||
|
reporter?.startTask(taskId, 100, weight)
|
||||||
|
return this.map {
|
||||||
|
reporter?.reportProgress((current / total.toFloat() * 100).toInt())
|
||||||
|
current++
|
||||||
|
transform.invoke(it)
|
||||||
|
}.also {
|
||||||
|
reporter?.endTask(taskId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ import im.vector.matrix.android.api.session.room.model.Membership
|
|||||||
import im.vector.matrix.android.internal.database.model.GroupEntity
|
import im.vector.matrix.android.internal.database.model.GroupEntity
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
import im.vector.matrix.android.internal.session.DefaultInitialSyncProgressService
|
import im.vector.matrix.android.internal.session.DefaultInitialSyncProgressService
|
||||||
|
import im.vector.matrix.android.internal.session.mapWithProgress
|
||||||
import im.vector.matrix.android.internal.session.sync.model.GroupsSyncResponse
|
import im.vector.matrix.android.internal.session.sync.model.GroupsSyncResponse
|
||||||
import im.vector.matrix.android.internal.session.sync.model.InvitedGroupSync
|
import im.vector.matrix.android.internal.session.sync.model.InvitedGroupSync
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
@ -47,36 +48,21 @@ internal class GroupSyncHandler @Inject constructor(private val monarchy: Monarc
|
|||||||
|
|
||||||
private fun handleGroupSync(realm: Realm, handlingStrategy: HandlingStrategy, reporter: DefaultInitialSyncProgressService?) {
|
private fun handleGroupSync(realm: Realm, handlingStrategy: HandlingStrategy, reporter: DefaultInitialSyncProgressService?) {
|
||||||
val groups = when (handlingStrategy) {
|
val groups = when (handlingStrategy) {
|
||||||
is HandlingStrategy.JOINED -> {
|
is HandlingStrategy.JOINED ->
|
||||||
val total = handlingStrategy.data.size
|
handlingStrategy.data.mapWithProgress(reporter, R.string.initial_sync_start_importing_account_groups, 0.6f) {
|
||||||
reporter?.startTask(R.string.initial_sync_start_importing_account_groups, total, 0.6f)
|
|
||||||
var current = 0
|
|
||||||
handlingStrategy.data.map {
|
|
||||||
reporter?.reportProgress((current / total.toFloat() * 100).toInt())
|
|
||||||
current++
|
|
||||||
handleJoinedGroup(realm, it.key)
|
handleJoinedGroup(realm, it.key)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
is HandlingStrategy.INVITED -> {
|
is HandlingStrategy.INVITED ->
|
||||||
val total = handlingStrategy.data.size
|
handlingStrategy.data.mapWithProgress(reporter, R.string.initial_sync_start_importing_account_groups, 0.3f) {
|
||||||
reporter?.startTask(R.string.initial_sync_start_importing_account_groups, total, 0.3f)
|
|
||||||
var current = 0
|
|
||||||
handlingStrategy.data.map {
|
|
||||||
reporter?.reportProgress((current / total.toFloat() * 100).toInt())
|
|
||||||
current++
|
|
||||||
handleInvitedGroup(realm, it.key)
|
handleInvitedGroup(realm, it.key)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
is HandlingStrategy.LEFT -> {
|
is HandlingStrategy.LEFT ->
|
||||||
val total = handlingStrategy.data.size
|
handlingStrategy.data.mapWithProgress(reporter, R.string.initial_sync_start_importing_account_groups, 0.1f) {
|
||||||
reporter?.startTask(R.string.initial_sync_start_importing_account_groups, total, 0.1f)
|
|
||||||
var current = 0
|
|
||||||
handlingStrategy.data.map {
|
|
||||||
reporter?.reportProgress((current / total.toFloat() * 100).toInt())
|
|
||||||
current++
|
|
||||||
handleLeftGroup(realm, it.key)
|
handleLeftGroup(realm, it.key)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
realm.insertOrUpdate(groups)
|
realm.insertOrUpdate(groups)
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import im.vector.matrix.android.internal.database.query.find
|
|||||||
import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom
|
import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
import im.vector.matrix.android.internal.session.DefaultInitialSyncProgressService
|
import im.vector.matrix.android.internal.session.DefaultInitialSyncProgressService
|
||||||
|
import im.vector.matrix.android.internal.session.mapWithProgress
|
||||||
import im.vector.matrix.android.internal.session.notification.DefaultPushRuleService
|
import im.vector.matrix.android.internal.session.notification.DefaultPushRuleService
|
||||||
import im.vector.matrix.android.internal.session.notification.ProcessEventForPushTask
|
import im.vector.matrix.android.internal.session.notification.ProcessEventForPushTask
|
||||||
import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater
|
import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater
|
||||||
@ -92,33 +93,19 @@ internal class RoomSyncHandler @Inject constructor(private val monarchy: Monarch
|
|||||||
private fun handleRoomSync(realm: Realm, handlingStrategy: HandlingStrategy, reporter: DefaultInitialSyncProgressService?) {
|
private fun handleRoomSync(realm: Realm, handlingStrategy: HandlingStrategy, reporter: DefaultInitialSyncProgressService?) {
|
||||||
|
|
||||||
val rooms = when (handlingStrategy) {
|
val rooms = when (handlingStrategy) {
|
||||||
is HandlingStrategy.JOINED -> {
|
is HandlingStrategy.JOINED ->
|
||||||
val total = handlingStrategy.data.size
|
handlingStrategy.data.mapWithProgress(reporter, R.string.initial_sync_start_importing_account_joined_rooms, 0.6f) {
|
||||||
reporter?.startTask(R.string.initial_sync_start_importing_account_joined_rooms, total, 0.6f)
|
handleJoinedRoom(realm, it.key, it.value)
|
||||||
var current = 0
|
}
|
||||||
handlingStrategy.data.map {
|
is HandlingStrategy.INVITED ->
|
||||||
reporter?.reportProgress((current / total.toFloat() * 100).toInt())
|
handlingStrategy.data.mapWithProgress(reporter, R.string.initial_sync_start_importing_account_invited_rooms, 0.4f) {
|
||||||
current++
|
handleInvitedRoom(realm, it.key, it.value)
|
||||||
handleJoinedRoom(realm, it.key, it.value).also {
|
|
||||||
reporter?.endTask(R.string.initial_sync_start_importing_account_joined_rooms)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
is HandlingStrategy.INVITED -> {
|
|
||||||
val total = handlingStrategy.data.size
|
|
||||||
reporter?.startTask(R.string.initial_sync_start_importing_account_invited_rooms, total, 0.4f)
|
|
||||||
var current = 0
|
|
||||||
handlingStrategy.data.map {
|
|
||||||
reporter?.reportProgress((current / total.toFloat() * 100).toInt())
|
|
||||||
current++
|
|
||||||
handleInvitedRoom(realm, it.key, it.value)
|
|
||||||
}.also {
|
|
||||||
reporter?.endTask(R.string.initial_sync_start_importing_account_invited_rooms)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is HandlingStrategy.LEFT -> {
|
is HandlingStrategy.LEFT -> {
|
||||||
handlingStrategy.data.map { handleLeftRoom(realm, it.key, it.value) }
|
handlingStrategy.data.mapWithProgress(reporter, R.string.initial_sync_start_importing_account_left_rooms, 0.2f) {
|
||||||
|
handleLeftRoom(realm, it.key, it.value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
realm.insertOrUpdate(rooms)
|
realm.insertOrUpdate(rooms)
|
||||||
|
Loading…
Reference in New Issue
Block a user