Move KeysBackupStateListener to a dedicated file

This commit is contained in:
Benoit Marty 2019-06-13 11:13:05 +02:00
parent 02d3fea4a9
commit c20b256b24
6 changed files with 39 additions and 15 deletions

View File

@ -189,8 +189,4 @@ interface KeysBackupService {
val isStucked: Boolean
val state: KeysBackupState
interface KeysBackupStateListener {
fun onStateChange(newState: KeysBackupState)
}
}

View File

@ -0,0 +1,26 @@
/*
* Copyright 2019 New Vector Ltd
*
* 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 im.vector.matrix.android.api.session.crypto.keysbackup
interface KeysBackupStateListener {
/**
* The keys backup state has changed
* @param newState the new state
*/
fun onStateChange(newState: KeysBackupState)
}

View File

@ -30,6 +30,7 @@ import im.vector.matrix.android.api.listeners.ProgressListener
import im.vector.matrix.android.api.listeners.StepProgressListener
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupStateListener
import im.vector.matrix.android.internal.crypto.*
import im.vector.matrix.android.internal.crypto.actions.MegolmSessionDataImporter
import im.vector.matrix.android.internal.crypto.keysbackup.model.KeysBackupVersionTrust
@ -104,7 +105,7 @@ internal class KeysBackup(
private var backupAllGroupSessionsCallback: MatrixCallback<Unit>? = null
private var keysBackupStateListener: KeysBackupService.KeysBackupStateListener? = null
private var keysBackupStateListener: KeysBackupStateListener? = null
override val isEnabled: Boolean
get() = keysBackupStateManager.isEnabled
@ -118,11 +119,11 @@ internal class KeysBackup(
override val currentBackupVersion: String?
get() = keysBackupVersion?.version
override fun addListener(listener: KeysBackupService.KeysBackupStateListener) {
override fun addListener(listener: KeysBackupStateListener) {
keysBackupStateManager.addListener(listener)
}
override fun removeListener(listener: KeysBackupService.KeysBackupStateListener) {
override fun removeListener(listener: KeysBackupStateListener) {
keysBackupStateManager.removeListener(listener)
}
@ -309,7 +310,7 @@ internal class KeysBackup(
backupAllGroupSessionsCallback = callback
// Listen to `state` change to determine when to call onBackupProgress and onComplete
keysBackupStateListener = object : KeysBackupService.KeysBackupStateListener {
keysBackupStateListener = object : KeysBackupStateListener {
override fun onStateChange(newState: KeysBackupState) {
getBackupProgress(object : ProgressListener {
override fun onProgress(progress: Int, total: Int) {

View File

@ -17,14 +17,14 @@
package im.vector.matrix.android.internal.crypto.keysbackup
import android.os.Handler
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupStateListener
import timber.log.Timber
import java.util.*
internal class KeysBackupStateManager(private val uiHandler: Handler) {
private val listeners = ArrayList<KeysBackupService.KeysBackupStateListener>()
private val listeners = ArrayList<KeysBackupStateListener>()
// Backup state
var state = KeysBackupState.Unknown
@ -56,13 +56,13 @@ internal class KeysBackupStateManager(private val uiHandler: Handler) {
|| state == KeysBackupState.WrongBackUpVersion
|| state == KeysBackupState.NotTrusted
fun addListener(listener: KeysBackupService.KeysBackupStateListener) {
fun addListener(listener: KeysBackupStateListener) {
synchronized(listeners) {
listeners.add(listener)
}
}
fun removeListener(listener: KeysBackupService.KeysBackupStateListener) {
fun removeListener(listener: KeysBackupStateListener) {
synchronized(listeners) {
listeners.remove(listener)
}

View File

@ -20,6 +20,7 @@ import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupStateListener
import im.vector.matrix.android.internal.crypto.keysbackup.model.KeysBackupVersionTrust
import im.vector.riotredesign.core.platform.VectorViewModel
import org.koin.android.ext.android.get
@ -27,7 +28,7 @@ import org.koin.android.ext.android.get
class KeysBackupSettingsViewModel(initialState: KeysBackupSettingViewState,
session: Session) : VectorViewModel<KeysBackupSettingViewState>(initialState),
KeysBackupService.KeysBackupStateListener {
KeysBackupStateListener {
companion object : MvRxViewModelFactory<KeysBackupSettingsViewModel, KeysBackupSettingViewState> {

View File

@ -19,10 +19,10 @@ package im.vector.riotredesign.features.workers.signout
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupStateListener
class SignOutViewModel : ViewModel(), KeysBackupService.KeysBackupStateListener {
class SignOutViewModel : ViewModel(), KeysBackupStateListener {
// Keys exported manually
var keysExportedToFile = MutableLiveData<Boolean>()