mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-26 17:14:59 +01:00
Move to dedicated package and split into several files
This commit is contained in:
parent
649edffa30
commit
24e9e6bbd7
@ -35,6 +35,7 @@ import org.matrix.android.sdk.api.session.file.FileService
|
||||
import org.matrix.android.sdk.api.session.group.GroupService
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
||||
import org.matrix.android.sdk.api.session.identity.IdentityService
|
||||
import org.matrix.android.sdk.api.session.initsync.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
|
||||
import org.matrix.android.sdk.api.session.media.MediaService
|
||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
||||
|
@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.matrix.android.sdk.api.session
|
||||
package org.matrix.android.sdk.api.session.initsync
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.lifecycle.LiveData
|
@ -24,7 +24,7 @@ import org.matrix.android.sdk.api.auth.data.SessionParams
|
||||
import org.matrix.android.sdk.api.failure.GlobalError
|
||||
import org.matrix.android.sdk.api.federation.FederationService
|
||||
import org.matrix.android.sdk.api.pushrules.PushRuleService
|
||||
import org.matrix.android.sdk.api.session.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.initsync.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.account.AccountService
|
||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
||||
|
@ -32,7 +32,7 @@ import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
import org.matrix.android.sdk.api.auth.data.SessionParams
|
||||
import org.matrix.android.sdk.api.auth.data.sessionId
|
||||
import org.matrix.android.sdk.api.crypto.MXCryptoConfig
|
||||
import org.matrix.android.sdk.api.session.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.initsync.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
||||
@ -77,6 +77,7 @@ import org.matrix.android.sdk.internal.session.call.CallEventProcessor
|
||||
import org.matrix.android.sdk.internal.session.download.DownloadProgressInterceptor
|
||||
import org.matrix.android.sdk.internal.session.homeserver.DefaultHomeServerCapabilitiesService
|
||||
import org.matrix.android.sdk.internal.session.identity.DefaultIdentityService
|
||||
import org.matrix.android.sdk.internal.session.initsync.DefaultInitialSyncProgressService
|
||||
import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManager
|
||||
import org.matrix.android.sdk.internal.session.permalinks.DefaultPermalinkService
|
||||
import org.matrix.android.sdk.internal.session.room.EventRelationsAggregationProcessor
|
||||
|
@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@ -13,25 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.matrix.android.sdk.internal.session
|
||||
package org.matrix.android.sdk.internal.session.initsync
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import org.matrix.android.sdk.api.session.InitialSyncProgressService
|
||||
import timber.log.Timber
|
||||
import org.matrix.android.sdk.api.session.initsync.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.internal.session.SessionScope
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface ProgressReporter {
|
||||
fun startTask(@StringRes nameRes: Int,
|
||||
totalProgress: Int,
|
||||
parentWeight: Float)
|
||||
|
||||
fun reportProgress(progress: Float)
|
||||
|
||||
fun endTask()
|
||||
}
|
||||
|
||||
@SessionScope
|
||||
internal class DefaultInitialSyncProgressService @Inject constructor()
|
||||
: InitialSyncProgressService,
|
||||
@ -94,63 +84,3 @@ internal class DefaultInitialSyncProgressService @Inject constructor()
|
||||
status.postValue(InitialSyncProgressService.Status.Idle)
|
||||
}
|
||||
}
|
||||
|
||||
private class TaskInfo(@StringRes val nameRes: Int,
|
||||
val totalProgress: Int,
|
||||
val parent: TaskInfo?,
|
||||
val parentWeight: Float) {
|
||||
var child: TaskInfo? = null
|
||||
var currentProgress = 0F
|
||||
private set
|
||||
private val offset = parent?.currentProgress ?: 0F
|
||||
|
||||
/**
|
||||
* Get the further child
|
||||
*/
|
||||
fun leaf(): TaskInfo {
|
||||
var last = this
|
||||
while (last.child != null) {
|
||||
last = last.child!!
|
||||
}
|
||||
return last
|
||||
}
|
||||
|
||||
/**
|
||||
* Set progress of this task and update the parent progress iteratively
|
||||
*/
|
||||
fun setProgress(progress: Float) {
|
||||
Timber.v("setProgress: $progress / $totalProgress")
|
||||
currentProgress = progress
|
||||
|
||||
parent?.let {
|
||||
val parentProgress = (currentProgress / totalProgress) * (parentWeight * it.totalProgress)
|
||||
it.setProgress(offset + parentProgress)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun <T> reportSubtask(reporter: ProgressReporter?,
|
||||
@StringRes nameRes: Int,
|
||||
totalProgress: Int,
|
||||
parentWeight: Float,
|
||||
block: () -> T): T {
|
||||
reporter?.startTask(nameRes, totalProgress, parentWeight)
|
||||
return block().also {
|
||||
reporter?.endTask()
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun <K, V, R> Map<out K, V>.mapWithProgress(reporter: ProgressReporter?,
|
||||
@StringRes nameRes: Int,
|
||||
parentWeight: Float,
|
||||
transform: (Map.Entry<K, V>) -> R): List<R> {
|
||||
var current = 0F
|
||||
reporter?.startTask(nameRes, count() + 1, parentWeight)
|
||||
return map {
|
||||
reporter?.reportProgress(current)
|
||||
current++
|
||||
transform.invoke(it)
|
||||
}.also {
|
||||
reporter?.endTask()
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.initsync
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
|
||||
internal inline fun <T> reportSubtask(reporter: ProgressReporter?,
|
||||
@StringRes nameRes: Int,
|
||||
totalProgress: Int,
|
||||
parentWeight: Float,
|
||||
block: () -> T): T {
|
||||
reporter?.startTask(nameRes, totalProgress, parentWeight)
|
||||
return block().also {
|
||||
reporter?.endTask()
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun <K, V, R> Map<out K, V>.mapWithProgress(reporter: ProgressReporter?,
|
||||
@StringRes nameRes: Int,
|
||||
parentWeight: Float,
|
||||
transform: (Map.Entry<K, V>) -> R): List<R> {
|
||||
var current = 0F
|
||||
reporter?.startTask(nameRes, count() + 1, parentWeight)
|
||||
return map {
|
||||
reporter?.reportProgress(current)
|
||||
current++
|
||||
transform.invoke(it)
|
||||
}.also {
|
||||
reporter?.endTask()
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.initsync
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
|
||||
internal interface ProgressReporter {
|
||||
fun startTask(@StringRes nameRes: Int,
|
||||
totalProgress: Int,
|
||||
parentWeight: Float)
|
||||
|
||||
fun reportProgress(progress: Float)
|
||||
|
||||
fun endTask()
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.initsync
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import timber.log.Timber
|
||||
|
||||
internal class TaskInfo(@StringRes val nameRes: Int,
|
||||
val totalProgress: Int,
|
||||
val parent: TaskInfo?,
|
||||
val parentWeight: Float) {
|
||||
var child: TaskInfo? = null
|
||||
var currentProgress = 0F
|
||||
private set
|
||||
private val offset = parent?.currentProgress ?: 0F
|
||||
|
||||
/**
|
||||
* Get the further child
|
||||
*/
|
||||
fun leaf(): TaskInfo {
|
||||
var last = this
|
||||
while (last.child != null) {
|
||||
last = last.child!!
|
||||
}
|
||||
return last
|
||||
}
|
||||
|
||||
/**
|
||||
* Set progress of this task and update the parent progress iteratively
|
||||
*/
|
||||
fun setProgress(progress: Float) {
|
||||
Timber.v("setProgress: $progress / $totalProgress")
|
||||
currentProgress = progress
|
||||
|
||||
parent?.let {
|
||||
val parentProgress = (currentProgress / totalProgress) * (parentWeight * it.totalProgress)
|
||||
it.setProgress(offset + parentProgress)
|
||||
}
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ import org.matrix.android.sdk.internal.crypto.MXEventDecryptionResult
|
||||
import org.matrix.android.sdk.internal.crypto.algorithms.olm.OlmDecryptionResult
|
||||
import org.matrix.android.sdk.internal.crypto.model.event.OlmEventContent
|
||||
import org.matrix.android.sdk.internal.crypto.verification.DefaultVerificationService
|
||||
import org.matrix.android.sdk.internal.session.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.initsync.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.sync.model.SyncResponse
|
||||
import org.matrix.android.sdk.internal.session.sync.model.ToDeviceSyncResponse
|
||||
import timber.log.Timber
|
||||
|
@ -23,8 +23,8 @@ import org.matrix.android.sdk.internal.database.model.GroupEntity
|
||||
import org.matrix.android.sdk.internal.database.model.GroupSummaryEntity
|
||||
import org.matrix.android.sdk.internal.database.query.getOrCreate
|
||||
import org.matrix.android.sdk.internal.database.query.where
|
||||
import org.matrix.android.sdk.internal.session.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.mapWithProgress
|
||||
import org.matrix.android.sdk.internal.session.initsync.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.initsync.mapWithProgress
|
||||
import org.matrix.android.sdk.internal.session.sync.model.GroupsSyncResponse
|
||||
import org.matrix.android.sdk.internal.session.sync.model.InvitedGroupSync
|
||||
import javax.inject.Inject
|
||||
|
@ -49,9 +49,9 @@ import org.matrix.android.sdk.internal.database.query.where
|
||||
import org.matrix.android.sdk.internal.di.MoshiProvider
|
||||
import org.matrix.android.sdk.internal.di.UserId
|
||||
import org.matrix.android.sdk.internal.extensions.clearWith
|
||||
import org.matrix.android.sdk.internal.session.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.mapWithProgress
|
||||
import org.matrix.android.sdk.internal.session.reportSubtask
|
||||
import org.matrix.android.sdk.internal.session.initsync.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.initsync.mapWithProgress
|
||||
import org.matrix.android.sdk.internal.session.initsync.reportSubtask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.RoomChangeMembershipStateDataSource
|
||||
import org.matrix.android.sdk.internal.session.room.membership.RoomMemberEventHandler
|
||||
import org.matrix.android.sdk.internal.session.room.read.FullyReadContent
|
||||
|
@ -25,10 +25,10 @@ import org.matrix.android.sdk.internal.crypto.DefaultCryptoService
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.di.SessionId
|
||||
import org.matrix.android.sdk.internal.di.WorkManagerProvider
|
||||
import org.matrix.android.sdk.internal.session.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.initsync.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.group.GetGroupDataWorker
|
||||
import org.matrix.android.sdk.internal.session.notification.ProcessEventForPushTask
|
||||
import org.matrix.android.sdk.internal.session.reportSubtask
|
||||
import org.matrix.android.sdk.internal.session.initsync.reportSubtask
|
||||
import org.matrix.android.sdk.internal.session.sync.model.GroupsSyncResponse
|
||||
import org.matrix.android.sdk.internal.session.sync.model.RoomsSyncResponse
|
||||
import org.matrix.android.sdk.internal.session.sync.model.SyncResponse
|
||||
|
@ -24,10 +24,10 @@ import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
||||
import org.matrix.android.sdk.internal.network.TimeOutInterceptor
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.network.toFailure
|
||||
import org.matrix.android.sdk.internal.session.DefaultInitialSyncProgressService
|
||||
import org.matrix.android.sdk.internal.session.initsync.DefaultInitialSyncProgressService
|
||||
import org.matrix.android.sdk.internal.session.filter.FilterRepository
|
||||
import org.matrix.android.sdk.internal.session.homeserver.GetHomeServerCapabilitiesTask
|
||||
import org.matrix.android.sdk.internal.session.reportSubtask
|
||||
import org.matrix.android.sdk.internal.session.initsync.reportSubtask
|
||||
import org.matrix.android.sdk.internal.session.sync.model.LazyRoomSync
|
||||
import org.matrix.android.sdk.internal.session.sync.model.SyncResponse
|
||||
import org.matrix.android.sdk.internal.session.sync.parsing.InitialSyncResponseParser
|
||||
|
@ -60,7 +60,7 @@ import im.vector.app.features.workers.signout.ServerBackupStatusViewState
|
||||
import im.vector.app.push.fcm.FcmHelper
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.matrix.android.sdk.api.session.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.initsync.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
import org.matrix.android.sdk.internal.session.sync.InitialSyncStrategy
|
||||
|
@ -40,7 +40,7 @@ import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
|
||||
import org.matrix.android.sdk.api.auth.registration.nextUncompletedStage
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
import org.matrix.android.sdk.api.session.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.initsync.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||
@ -130,7 +130,7 @@ class HomeActivityViewModel @AssistedInject constructor(
|
||||
// Schedule a check of the bootstrap when the init sync will be finished
|
||||
checkBootstrap = true
|
||||
}
|
||||
is InitialSyncProgressService.Status.Idle -> {
|
||||
is InitialSyncProgressService.Status.Idle -> {
|
||||
if (checkBootstrap) {
|
||||
checkBootstrap = false
|
||||
maybeBootstrapCrossSigningAfterInitialSync()
|
||||
|
@ -17,7 +17,7 @@
|
||||
package im.vector.app.features.home
|
||||
|
||||
import com.airbnb.mvrx.MvRxState
|
||||
import org.matrix.android.sdk.api.session.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.initsync.InitialSyncProgressService
|
||||
|
||||
data class HomeActivityViewState(
|
||||
val initialSyncProgressServiceStatus: InitialSyncProgressService.Status = InitialSyncProgressService.Status.Idle
|
||||
|
Loading…
Reference in New Issue
Block a user