mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-20 13:38:34 +01:00
providing a features abstraction for the login
- aims to have a centralised place for all feature login, overrideable by forks and debug flavours
This commit is contained in:
parent
a2a89c1ee8
commit
9e367a8535
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user