diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupService.kt index 061a656403..02111012eb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupService.kt @@ -189,8 +189,4 @@ interface KeysBackupService { val isStucked: Boolean val state: KeysBackupState - interface KeysBackupStateListener { - fun onStateChange(newState: KeysBackupState) - } - } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupStateListener.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupStateListener.kt new file mode 100644 index 0000000000..f145d779f1 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/keysbackup/KeysBackupStateListener.kt @@ -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) +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt index 810cc4893d..b80b063fbc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt @@ -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? = 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) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupStateManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupStateManager.kt index b82a63958d..ff812e75c0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupStateManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupStateManager.kt @@ -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() + private val listeners = ArrayList() // 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) } diff --git a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupSettingsViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupSettingsViewModel.kt index 2376cb2676..969ff02820 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/settings/KeysBackupSettingsViewModel.kt @@ -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(initialState), - KeysBackupService.KeysBackupStateListener { + KeysBackupStateListener { companion object : MvRxViewModelFactory { diff --git a/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutViewModel.kt index ec619d157a..ea3989eea2 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutViewModel.kt @@ -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()