From 1365240f69778f245ecf79327b841873ef8b7bfb Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 8 Jun 2020 22:07:35 +0200 Subject: [PATCH] Cleanup --- .../riotx/features/home/HomeActivity.kt | 17 +++++---- .../features/home/HomeActivityViewModel.kt | 35 +++++++++++++++++++ .../home/HomeSharedActionViewModel.kt | 5 +-- 3 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/features/home/HomeActivityViewModel.kt diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt index 97ac5f933b..2b873b33a4 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt @@ -27,6 +27,7 @@ import androidx.core.view.GravityCompat import androidx.core.view.isVisible import androidx.drawerlayout.widget.DrawerLayout import androidx.lifecycle.Observer +import com.airbnb.mvrx.viewModel import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.util.toMatrixItem @@ -59,6 +60,8 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet private lateinit var sharedActionViewModel: HomeSharedActionViewModel + private val homeActivityViewModel: HomeActivityViewModel by viewModel() + @Inject lateinit var activeSessionHolder: ActiveSessionHolder @Inject lateinit var vectorUncaughtExceptionHandler: VectorUncaughtExceptionHandler @Inject lateinit var pushManager: PushersManager @@ -117,7 +120,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet } if (intent.getBooleanExtra(EXTRA_ACCOUNT_CREATION, false)) { sharedActionViewModel.post(HomeActivitySharedAction.PromptForSecurityBootstrap) - sharedActionViewModel.isAccountCreation = true + homeActivityViewModel.isAccountCreation = true intent.removeExtra(EXTRA_ACCOUNT_CREATION) } @@ -126,7 +129,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet waiting_view.isVisible = false promptCompleteSecurityIfNeeded() } else { - sharedActionViewModel.hasDisplayedCompleteSecurityPrompt = false + homeActivityViewModel.hasDisplayedCompleteSecurityPrompt = false Timber.v("${getString(status.statusText)} ${status.percentProgress}") waiting_view.setOnClickListener { // block interactions @@ -146,7 +149,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet }) // Ask again if the app is relaunched - if (!sharedActionViewModel.hasDisplayedCompleteSecurityPrompt + if (!homeActivityViewModel.hasDisplayedCompleteSecurityPrompt && activeSessionHolder.getSafeActiveSession()?.hasAlreadySynced() == true) { promptCompleteSecurityIfNeeded() } @@ -158,7 +161,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet private fun promptCompleteSecurityIfNeeded() { val session = activeSessionHolder.getSafeActiveSession() ?: return if (!session.hasAlreadySynced()) return - if (sharedActionViewModel.hasDisplayedCompleteSecurityPrompt) return + if (homeActivityViewModel.hasDisplayedCompleteSecurityPrompt) return // ensure keys are downloaded session.cryptoService().downloadKeys(listOf(session.myUserId), true, object : MatrixCallback> { @@ -175,7 +178,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet .getMyCrossSigningKeys() val crossSigningEnabledOnAccount = myCrossSigningKeys != null - if (!crossSigningEnabledOnAccount && !sharedActionViewModel.isAccountCreation) { + if (!crossSigningEnabledOnAccount && !homeActivityViewModel.isAccountCreation) { // Do not propose for SSO accounts, because we do not support yet confirming account credentials using SSO if (session.getHomeServerCapabilities().canChangePassword) { // We need to ask @@ -188,7 +191,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet } } else { // Do not do it again - sharedActionViewModel.hasDisplayedCompleteSecurityPrompt = true + homeActivityViewModel.hasDisplayedCompleteSecurityPrompt = true } } else if (myCrossSigningKeys?.isTrusted() == false) { // We need to ask @@ -203,7 +206,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet } private fun promptSecurityEvent(session: Session, titleRes: Int, descRes: Int, action: ((VectorBaseActivity) -> Unit)) { - sharedActionViewModel.hasDisplayedCompleteSecurityPrompt = true + homeActivityViewModel.hasDisplayedCompleteSecurityPrompt = true popupAlertManager.postVectorAlert( VerificationVectorAlert( uid = "upgradeSecurity", diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeActivityViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeActivityViewModel.kt new file mode 100644 index 0000000000..7ad6cb8528 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeActivityViewModel.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 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.riotx.features.home + +import com.airbnb.mvrx.MvRxState +import im.vector.riotx.core.platform.EmptyAction +import im.vector.riotx.core.platform.EmptyViewEvents +import im.vector.riotx.core.platform.VectorViewModel + +data class EmptyState( + val dummy: Boolean = false +) : MvRxState + +class HomeActivityViewModel : VectorViewModel(EmptyState()) { + var hasDisplayedCompleteSecurityPrompt: Boolean = false + var isAccountCreation: Boolean = false + + override fun handle(action: EmptyAction) { + // NA + } +} diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeSharedActionViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeSharedActionViewModel.kt index 4af9262d05..cd81448a0a 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeSharedActionViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeSharedActionViewModel.kt @@ -19,7 +19,4 @@ package im.vector.riotx.features.home import im.vector.riotx.core.platform.VectorSharedActionViewModel import javax.inject.Inject -class HomeSharedActionViewModel @Inject constructor() : VectorSharedActionViewModel() { - var hasDisplayedCompleteSecurityPrompt : Boolean = false - var isAccountCreation : Boolean = false -} +class HomeSharedActionViewModel @Inject constructor() : VectorSharedActionViewModel()