diff --git a/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt b/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt index 350e1f6b7a..9912c25eb0 100644 --- a/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt @@ -31,6 +31,8 @@ import im.vector.app.core.error.DefaultErrorFormatter import im.vector.app.core.error.ErrorFormatter import im.vector.app.core.time.Clock import im.vector.app.core.time.DefaultClock +import im.vector.app.features.DefaultVectorFeatures +import im.vector.app.features.VectorFeatures import im.vector.app.features.invite.AutoAcceptInvites import im.vector.app.features.invite.CompileTimeAutoAcceptInvites import im.vector.app.features.navigation.DefaultNavigator @@ -133,4 +135,9 @@ object VectorStaticModule { fun providesCoroutineDispatchers(): CoroutineDispatchers { return CoroutineDispatchers(io = Dispatchers.IO, computation = Dispatchers.Default) } + + @Provides + fun providesFeatures(context: Context): VectorFeatures { + return DefaultVectorFeatures(context) + } } diff --git a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt new file mode 100644 index 0000000000..a5f08bf7d1 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 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.app.features + +import android.content.Context +import im.vector.app.R +import im.vector.app.features.VectorFeatures.LoginType + +interface VectorFeatures { + + fun loginType(): LoginType + + enum class LoginType { + V1, + V2 + } +} + +class DefaultVectorFeatures(private val context: Context) : VectorFeatures { + override fun loginType(): LoginType { + val v2LoginIsEnabled = context.resources.getBoolean(R.bool.useLoginV2) + return if (v2LoginIsEnabled) { + LoginType.V2 + } else { + LoginType.V1 + } + } +} diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index 2aec110221..af43dc6fe7 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -36,6 +36,7 @@ import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.error.fatalError import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.utils.toast +import im.vector.app.features.VectorFeatures import im.vector.app.features.call.conference.JitsiCallViewModel import im.vector.app.features.call.conference.VectorJitsiActivity import im.vector.app.features.call.transfer.CallTransferActivity @@ -104,24 +105,23 @@ class DefaultNavigator @Inject constructor( private val vectorPreferences: VectorPreferences, private val widgetArgsBuilder: WidgetArgsBuilder, private val appStateHandler: AppStateHandler, - private val supportedVerificationMethodsProvider: SupportedVerificationMethodsProvider + private val supportedVerificationMethodsProvider: SupportedVerificationMethodsProvider, + private val features: VectorFeatures ) : Navigator { override fun openLogin(context: Context, loginConfig: LoginConfig?, flags: Int) { - val intent = if (context.resources.getBoolean(R.bool.useLoginV2)) { - LoginActivity2.newIntent(context, loginConfig) - } else { - LoginActivity.newIntent(context, loginConfig) + val intent = when (features.loginType()) { + VectorFeatures.LoginType.V1 -> LoginActivity.newIntent(context, loginConfig) + VectorFeatures.LoginType.V2 -> LoginActivity2.newIntent(context, loginConfig) } intent.addFlags(flags) context.startActivity(intent) } override fun softLogout(context: Context) { - val intent = if (context.resources.getBoolean(R.bool.useLoginV2)) { - SoftLogoutActivity2.newIntent(context) - } else { - SoftLogoutActivity.newIntent(context) + val intent = when (features.loginType()) { + VectorFeatures.LoginType.V1 -> SoftLogoutActivity.newIntent(context) + VectorFeatures.LoginType.V2 -> SoftLogoutActivity2.newIntent(context) } context.startActivity(intent) }