From a2a89c1ee8ae0ef0ba96f26513b5362e2eaf6ce6 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 3 Dec 2021 11:58:13 +0000 Subject: [PATCH 1/8] moving the soft logout activity starting to the navigator --- .../im/vector/app/features/MainActivity.kt | 19 ++++++------------- .../features/navigation/DefaultNavigator.kt | 11 +++++++++++ .../app/features/navigation/Navigator.kt | 2 ++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/MainActivity.kt b/vector/src/main/java/im/vector/app/features/MainActivity.kt index f4c737c942..d3d51c3dbf 100644 --- a/vector/src/main/java/im/vector/app/features/MainActivity.kt +++ b/vector/src/main/java/im/vector/app/features/MainActivity.kt @@ -41,8 +41,6 @@ import im.vector.app.features.pin.UnlockedActivity import im.vector.app.features.popup.PopupAlertManager import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.signout.hard.SignedOutActivity -import im.vector.app.features.signout.soft.SoftLogoutActivity -import im.vector.app.features.signout.soft.SoftLogoutActivity2 import im.vector.app.features.themes.ActivityOtherThemes import im.vector.app.features.ui.UiStateRepository import kotlinx.coroutines.Dispatchers @@ -223,9 +221,11 @@ class MainActivity : VectorBaseActivity(), UnlockedActivity navigator.openLogin(this, null) null } - args.isSoftLogout -> + args.isSoftLogout -> { // The homeserver has invalidated the token, with a soft logout - getSoftLogoutActivityIntent() + navigator.softLogout(this) + null + } args.isUserLoggedOut -> // the homeserver has invalidated the token (password changed, device deleted, other security reasons) SignedOutActivity.newIntent(this) @@ -236,7 +236,8 @@ class MainActivity : VectorBaseActivity(), UnlockedActivity HomeActivity.newIntent(this) } else { // The token is still invalid - getSoftLogoutActivityIntent() + navigator.softLogout(this) + null } else -> { // First start, or no active session @@ -247,12 +248,4 @@ class MainActivity : VectorBaseActivity(), UnlockedActivity intent?.let { startActivity(it) } finish() } - - private fun getSoftLogoutActivityIntent(): Intent { - return if (resources.getBoolean(R.bool.useLoginV2)) { - SoftLogoutActivity2.newIntent(this) - } else { - SoftLogoutActivity.newIntent(this) - } - } } 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 89a05c88da..2aec110221 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 @@ -77,6 +77,8 @@ import im.vector.app.features.roomprofile.RoomProfileActivity import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorSettingsActivity import im.vector.app.features.share.SharedData +import im.vector.app.features.signout.soft.SoftLogoutActivity +import im.vector.app.features.signout.soft.SoftLogoutActivity2 import im.vector.app.features.spaces.InviteRoomSpaceChooserBottomSheet import im.vector.app.features.spaces.SpaceExploreActivity import im.vector.app.features.spaces.SpacePreviewActivity @@ -115,6 +117,15 @@ class DefaultNavigator @Inject constructor( context.startActivity(intent) } + override fun softLogout(context: Context) { + val intent = if (context.resources.getBoolean(R.bool.useLoginV2)) { + SoftLogoutActivity2.newIntent(context) + } else { + SoftLogoutActivity.newIntent(context) + } + context.startActivity(intent) + } + override fun openRoom(context: Context, roomId: String, eventId: String?, buildTask: Boolean) { if (sessionHolder.getSafeActiveSession()?.getRoom(roomId) == null) { fatalError("Trying to open an unknown room $roomId", vectorPreferences.failFast()) diff --git a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt index 264593fe18..e0c6eb26bb 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt @@ -41,6 +41,8 @@ interface Navigator { fun openLogin(context: Context, loginConfig: LoginConfig? = null, flags: Int = 0) + fun softLogout(context: Context) + fun openRoom(context: Context, roomId: String, eventId: String? = null, buildTask: Boolean = false) sealed class PostSwitchSpaceAction { From 9e367a8535b05ee07ed5b1db13122c79f4fbe3fd Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 3 Dec 2021 12:16:43 +0000 Subject: [PATCH 2/8] providing a features abstraction for the login - aims to have a centralised place for all feature login, overrideable by forks and debug flavours --- .../im/vector/app/core/di/SingletonModule.kt | 7 ++++ .../im/vector/app/features/VectorFeatures.kt | 42 +++++++++++++++++++ .../features/navigation/DefaultNavigator.kt | 18 ++++---- 3 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/VectorFeatures.kt 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) } From 54c45d3e71584c6d3ef77b8cb41422a7c71fc3f7 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 3 Dec 2021 14:51:20 +0000 Subject: [PATCH 3/8] separating the SSO redirection from the login activities - adds a dedicated routing activity to proxy the uri to the login selected by the feature flags --- vector/src/main/AndroidManifest.xml | 50 ++++++++----------- .../app/features/login/LoginActivity.kt | 7 +++ .../login/SSORedirectRouterActivity.kt | 35 +++++++++++++ .../app/features/login2/LoginActivity2.kt | 8 +++ .../features/navigation/DefaultNavigator.kt | 9 ++++ .../app/features/navigation/Navigator.kt | 3 ++ 6 files changed, 82 insertions(+), 30 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/login/SSORedirectRouterActivity.kt diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index 5b56107ef7..8e9e534f7a 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -113,45 +113,35 @@ - + + + + + + + + + + + + + - - - + android:windowSoftInputMode="adjustResize" /> - - - - - - - - - - - - - - - - - - + android:windowSoftInputMode="adjustResize" /> (), ToolbarCo putExtra(EXTRA_CONFIG, loginConfig) } } + + fun redirectIntent(context: Context, data: Uri?): Intent { + return Intent(context, LoginActivity::class.java).apply { + setData(data) + } + } } } diff --git a/vector/src/main/java/im/vector/app/features/login/SSORedirectRouterActivity.kt b/vector/src/main/java/im/vector/app/features/login/SSORedirectRouterActivity.kt new file mode 100644 index 0000000000..29f8559362 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/login/SSORedirectRouterActivity.kt @@ -0,0 +1,35 @@ +/* + * 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.login + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import dagger.hilt.android.AndroidEntryPoint +import im.vector.app.features.navigation.Navigator +import javax.inject.Inject + +@AndroidEntryPoint +class SSORedirectRouterActivity : AppCompatActivity() { + + @Inject lateinit var navigator: Navigator + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + navigator.loginSSORedirect(this, intent.data) + finish() + } +} diff --git a/vector/src/main/java/im/vector/app/features/login2/LoginActivity2.kt b/vector/src/main/java/im/vector/app/features/login2/LoginActivity2.kt index 8f1b20aa7f..e32ace35b2 100644 --- a/vector/src/main/java/im/vector/app/features/login2/LoginActivity2.kt +++ b/vector/src/main/java/im/vector/app/features/login2/LoginActivity2.kt @@ -18,6 +18,7 @@ package im.vector.app.features.login2 import android.content.Context import android.content.Intent +import android.net.Uri import android.view.View import android.view.ViewGroup import androidx.core.view.ViewCompat @@ -40,6 +41,7 @@ import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityLoginBinding import im.vector.app.features.home.HomeActivity +import im.vector.app.features.login.LoginActivity import im.vector.app.features.login.LoginCaptchaFragmentArgument import im.vector.app.features.login.LoginConfig import im.vector.app.features.login.LoginGenericTextInputFormFragmentArgument @@ -396,5 +398,11 @@ open class LoginActivity2 : VectorBaseActivity(), ToolbarC putExtra(EXTRA_CONFIG, loginConfig) } } + + fun redirectIntent(context: Context, data: Uri?): Intent { + return Intent(context, LoginActivity2::class.java).apply { + setData(data) + } + } } } 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 af43dc6fe7..ff57528c16 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 @@ -19,6 +19,7 @@ package im.vector.app.features.navigation import android.app.Activity import android.content.Context import android.content.Intent +import android.net.Uri import android.os.Build import android.view.View import android.view.Window @@ -118,6 +119,14 @@ class DefaultNavigator @Inject constructor( context.startActivity(intent) } + override fun loginSSORedirect(context: Context, data: Uri?) { + val intent = when (features.loginType()) { + VectorFeatures.LoginType.V1 -> LoginActivity.redirectIntent(context, data) + VectorFeatures.LoginType.V2 -> LoginActivity2.redirectIntent(context, data) + } + context.startActivity(intent) + } + override fun softLogout(context: Context) { val intent = when (features.loginType()) { VectorFeatures.LoginType.V1 -> SoftLogoutActivity.newIntent(context) diff --git a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt index e0c6eb26bb..a1f40f07c0 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt @@ -19,6 +19,7 @@ package im.vector.app.features.navigation import android.app.Activity import android.content.Context import android.content.Intent +import android.net.Uri import android.view.View import androidx.activity.result.ActivityResultLauncher import androidx.core.util.Pair @@ -41,6 +42,8 @@ interface Navigator { fun openLogin(context: Context, loginConfig: LoginConfig? = null, flags: Int = 0) + fun loginSSORedirect(context: Context, data: Uri?) + fun softLogout(context: Context) fun openRoom(context: Context, roomId: String, eventId: String? = null, buildTask: Boolean = false) From 8007654e2a0cf345089755c3eed67a347e89e06e Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 3 Dec 2021 15:02:09 +0000 Subject: [PATCH 4/8] setting login version via typed build config field instead of resources --- vector/build.gradle | 5 +---- vector/src/main/AndroidManifest.xml | 2 -- .../im/vector/app/core/di/SingletonModule.kt | 4 ++-- .../im/vector/app/features/VectorFeatures.kt | 19 +++++-------------- .../features/navigation/DefaultNavigator.kt | 18 +++++++++--------- 5 files changed, 17 insertions(+), 31 deletions(-) diff --git a/vector/build.gradle b/vector/build.gradle index ff81c4d721..6f36358aa3 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -140,10 +140,7 @@ android { buildConfigField "String", "BUILD_NUMBER", "\"${buildNumber}\"" resValue "string", "build_number", "\"${buildNumber}\"" - // The two booleans must not have the same value. We need two values for the manifest - // LoginFlowV2 is disabled to be merged on develop (changelog: Improve login/register flow (#1410, #2585, #3172)) - resValue "bool", "useLoginV1", "true" - resValue "bool", "useLoginV2", "false" + buildConfigField "im.vector.app.features.VectorFeatures.LoginVersion", "LOGIN_VERSION", "im.vector.app.features.VectorFeatures.LoginVersion.V1" // NotificationSettingsV2 is disabled. To be released in conjunction with iOS/Web def useNotificationSettingsV2 = true diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index 8e9e534f7a..6d3c6cdc51 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -133,13 +133,11 @@ 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 9912c25eb0..4fbeb549aa 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 @@ -137,7 +137,7 @@ object VectorStaticModule { } @Provides - fun providesFeatures(context: Context): VectorFeatures { - return DefaultVectorFeatures(context) + fun providesFeatures(): VectorFeatures { + return DefaultVectorFeatures() } } diff --git a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt index a5f08bf7d1..ccc54b5d8e 100644 --- a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt +++ b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt @@ -16,27 +16,18 @@ package im.vector.app.features -import android.content.Context -import im.vector.app.R -import im.vector.app.features.VectorFeatures.LoginType +import im.vector.app.BuildConfig interface VectorFeatures { - fun loginType(): LoginType + fun loginVersion(): LoginVersion - enum class LoginType { + enum class LoginVersion { 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 - } - } +class DefaultVectorFeatures : VectorFeatures { + override fun loginVersion(): VectorFeatures.LoginVersion = BuildConfig.LOGIN_VERSION } 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 ff57528c16..eacd8523cf 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 @@ -111,26 +111,26 @@ class DefaultNavigator @Inject constructor( ) : Navigator { override fun openLogin(context: Context, loginConfig: LoginConfig?, flags: Int) { - val intent = when (features.loginType()) { - VectorFeatures.LoginType.V1 -> LoginActivity.newIntent(context, loginConfig) - VectorFeatures.LoginType.V2 -> LoginActivity2.newIntent(context, loginConfig) + val intent = when (features.loginVersion()) { + VectorFeatures.LoginVersion.V1 -> LoginActivity.newIntent(context, loginConfig) + VectorFeatures.LoginVersion.V2 -> LoginActivity2.newIntent(context, loginConfig) } intent.addFlags(flags) context.startActivity(intent) } override fun loginSSORedirect(context: Context, data: Uri?) { - val intent = when (features.loginType()) { - VectorFeatures.LoginType.V1 -> LoginActivity.redirectIntent(context, data) - VectorFeatures.LoginType.V2 -> LoginActivity2.redirectIntent(context, data) + val intent = when (features.loginVersion()) { + VectorFeatures.LoginVersion.V1 -> LoginActivity.redirectIntent(context, data) + VectorFeatures.LoginVersion.V2 -> LoginActivity2.redirectIntent(context, data) } context.startActivity(intent) } override fun softLogout(context: Context) { - val intent = when (features.loginType()) { - VectorFeatures.LoginType.V1 -> SoftLogoutActivity.newIntent(context) - VectorFeatures.LoginType.V2 -> SoftLogoutActivity2.newIntent(context) + val intent = when (features.loginVersion()) { + VectorFeatures.LoginVersion.V1 -> SoftLogoutActivity.newIntent(context) + VectorFeatures.LoginVersion.V2 -> SoftLogoutActivity2.newIntent(context) } context.startActivity(intent) } From 11669fa2acefd13a36501f9b320ecab0d4bb7644 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 3 Dec 2021 15:26:43 +0000 Subject: [PATCH 5/8] porting the notifications setting version to the vector features --- vector/build.gradle | 7 +---- .../settings/SettingsNotificationsRobot.kt | 27 +++++++++++-------- .../im/vector/app/features/VectorFeatures.kt | 7 +++++ .../RoomListQuickActionsEpoxyController.kt | 6 +++-- .../roomprofile/RoomProfileFragment.kt | 18 ++++++++----- 5 files changed, 39 insertions(+), 26 deletions(-) diff --git a/vector/build.gradle b/vector/build.gradle index 6f36358aa3..d29f36c877 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -141,12 +141,7 @@ android { resValue "string", "build_number", "\"${buildNumber}\"" buildConfigField "im.vector.app.features.VectorFeatures.LoginVersion", "LOGIN_VERSION", "im.vector.app.features.VectorFeatures.LoginVersion.V1" - - // NotificationSettingsV2 is disabled. To be released in conjunction with iOS/Web - def useNotificationSettingsV2 = true - buildConfigField "Boolean", "USE_NOTIFICATION_SETTINGS_V2", "${useNotificationSettingsV2}" - resValue "bool", "useNotificationSettingsV1", "${!useNotificationSettingsV2}" - resValue "bool", "useNotificationSettingsV2", "${useNotificationSettingsV2}" + buildConfigField "im.vector.app.features.VectorFeatures.NotificationSettingsVersion", "NOTIFICATION_SETTINGS_VERSION", "im.vector.app.features.VectorFeatures.NotificationSettingsVersion.V2" buildConfigField "im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrategy", "outboundSessionKeySharingStrategy", "im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrategy.WhenTyping" diff --git a/vector/src/androidTest/java/im/vector/app/ui/robot/settings/SettingsNotificationsRobot.kt b/vector/src/androidTest/java/im/vector/app/ui/robot/settings/SettingsNotificationsRobot.kt index 448552ba8e..4dddc4c9cc 100644 --- a/vector/src/androidTest/java/im/vector/app/ui/robot/settings/SettingsNotificationsRobot.kt +++ b/vector/src/androidTest/java/im/vector/app/ui/robot/settings/SettingsNotificationsRobot.kt @@ -21,22 +21,27 @@ import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.espresso.tools.clickOnPreference +import im.vector.app.features.VectorFeatures class SettingsNotificationsRobot { fun crawl() { - if (BuildConfig.USE_NOTIFICATION_SETTINGS_V2) { - clickOn(R.string.settings_notification_default) - pressBack() - clickOn(R.string.settings_notification_mentions_and_keywords) - // TODO Test adding a keyword? - pressBack() - clickOn(R.string.settings_notification_other) - pressBack() - } else { - clickOn(R.string.settings_notification_advanced) - pressBack() + when (BuildConfig.NOTIFICATION_SETTINGS_VERSION!!) { + VectorFeatures.NotificationSettingsVersion.V1 -> { + clickOn(R.string.settings_notification_advanced) + pressBack() + } + VectorFeatures.NotificationSettingsVersion.V2 -> { + clickOn(R.string.settings_notification_default) + pressBack() + clickOn(R.string.settings_notification_mentions_and_keywords) + // TODO Test adding a keyword? + pressBack() + clickOn(R.string.settings_notification_other) + pressBack() + } } + /* clickOn(R.string.settings_noisy_notifications_preferences) TODO Cannot go back diff --git a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt index ccc54b5d8e..b40d2d02f2 100644 --- a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt +++ b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt @@ -21,13 +21,20 @@ import im.vector.app.BuildConfig interface VectorFeatures { fun loginVersion(): LoginVersion + fun notificationSettingsVersion(): NotificationSettingsVersion enum class LoginVersion { V1, V2 } + + enum class NotificationSettingsVersion { + V1, + V2 + } } class DefaultVectorFeatures : VectorFeatures { override fun loginVersion(): VectorFeatures.LoginVersion = BuildConfig.LOGIN_VERSION + override fun notificationSettingsVersion(): VectorFeatures.NotificationSettingsVersion = BuildConfig.NOTIFICATION_SETTINGS_VERSION } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt b/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt index 7e39156b18..4e0f329738 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt @@ -25,6 +25,7 @@ import im.vector.app.core.epoxy.bottomsheet.bottomSheetRoomPreviewItem import im.vector.app.core.epoxy.profiles.notifications.radioButtonItem import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.StringProvider +import im.vector.app.features.VectorFeatures import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.roomprofile.notifications.notificationOptions import im.vector.app.features.roomprofile.notifications.notificationStateMapped @@ -38,7 +39,8 @@ import javax.inject.Inject class RoomListQuickActionsEpoxyController @Inject constructor( private val avatarRenderer: AvatarRenderer, private val colorProvider: ColorProvider, - private val stringProvider: StringProvider + private val stringProvider: StringProvider, + private val features: VectorFeatures ) : TypedEpoxyController() { var listener: Listener? = null @@ -47,7 +49,7 @@ class RoomListQuickActionsEpoxyController @Inject constructor( val notificationViewState = state.notificationSettingsViewState val roomSummary = notificationViewState.roomSummary() ?: return val host = this - val isV2 = BuildConfig.USE_NOTIFICATION_SETTINGS_V2 + val isV2 = features.notificationSettingsVersion() == VectorFeatures.NotificationSettingsVersion.V2 // V2 always shows full details as we no longer display the sheet from RoomProfile > Notifications val showFull = state.roomListActionsArgs.mode == RoomListActionsArgs.Mode.FULL || isV2 diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt index e1a5cae907..4dac4be489 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt @@ -31,7 +31,6 @@ import com.airbnb.mvrx.args import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import com.google.android.material.dialog.MaterialAlertDialogBuilder -import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.animations.AppBarStateChangeListener import im.vector.app.core.animations.MatrixItemAppBarStateChangeListener @@ -45,6 +44,7 @@ import im.vector.app.core.utils.copyToClipboard import im.vector.app.core.utils.startSharePlainTextIntent import im.vector.app.databinding.FragmentMatrixProfileBinding import im.vector.app.databinding.ViewStubRoomProfileHeaderBinding +import im.vector.app.features.VectorFeatures import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.RoomDetailPendingAction import im.vector.app.features.home.room.detail.RoomDetailPendingActionStore @@ -70,6 +70,7 @@ class RoomProfileFragment @Inject constructor( private val roomProfileController: RoomProfileController, private val avatarRenderer: AvatarRenderer, private val roomDetailPendingActionStore: RoomDetailPendingActionStore, + private val features: VectorFeatures ) : VectorBaseFragment(), RoomProfileController.Callback { @@ -258,12 +259,15 @@ class RoomProfileFragment @Inject constructor( } override fun onNotificationsClicked() { - if (BuildConfig.USE_NOTIFICATION_SETTINGS_V2) { - roomProfileSharedActionViewModel.post(RoomProfileSharedAction.OpenRoomNotificationSettings) - } else { - RoomListQuickActionsBottomSheet - .newInstance(roomProfileArgs.roomId, RoomListActionsArgs.Mode.NOTIFICATIONS) - .show(childFragmentManager, "ROOM_PROFILE_NOTIFICATIONS") + when (features.notificationSettingsVersion()) { + VectorFeatures.NotificationSettingsVersion.V1 -> { + RoomListQuickActionsBottomSheet + .newInstance(roomProfileArgs.roomId, RoomListActionsArgs.Mode.NOTIFICATIONS) + .show(childFragmentManager, "ROOM_PROFILE_NOTIFICATIONS") + } + VectorFeatures.NotificationSettingsVersion.V2 -> { + roomProfileSharedActionViewModel.post(RoomProfileSharedAction.OpenRoomNotificationSettings) + } } } From 6a3d4044efbc87ffae78b6c21d3e814da3af5de5 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 3 Dec 2021 15:30:55 +0000 Subject: [PATCH 6/8] removing unused imports and increasing enum allowance --- tools/check/forbidden_strings_in_code.txt | 2 +- .../list/actions/RoomListQuickActionsEpoxyController.kt | 8 ++++---- .../java/im/vector/app/features/login2/LoginActivity2.kt | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/check/forbidden_strings_in_code.txt b/tools/check/forbidden_strings_in_code.txt index b135954f63..bbd6105b15 100644 --- a/tools/check/forbidden_strings_in_code.txt +++ b/tools/check/forbidden_strings_in_code.txt @@ -160,7 +160,7 @@ Formatter\.formatShortFileSize===1 # android\.text\.TextUtils ### This is not a rule, but a warning: the number of "enum class" has changed. For Json classes, it is mandatory that they have `@JsonClass(generateAdapter = false)`. If the enum is not used as a Json class, change the value in file forbidden_strings_in_code.txt -enum class===108 +enum class===110 ### Do not import temporary legacy classes import org.matrix.android.sdk.internal.legacy.riot===3 diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt b/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt index 4e0f329738..a2d10cf818 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt @@ -17,7 +17,6 @@ package im.vector.app.features.home.room.list.actions import androidx.annotation.StringRes import com.airbnb.epoxy.TypedEpoxyController -import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.epoxy.bottomSheetDividerItem import im.vector.app.core.epoxy.bottomsheet.bottomSheetActionItem @@ -75,14 +74,14 @@ class RoomListQuickActionsEpoxyController @Inject constructor( } if (isV2) { - notificationViewState.notificationOptions.forEach { notificationState -> + notificationViewState.notificationOptions.forEach { notificationState -> val title = titleForNotificationState(notificationState) radioButtonItem { id(notificationState.name) titleRes(title) selected(notificationViewState.notificationStateMapped() == notificationState) listener { - host.listener?.didSelectRoomNotificationState(notificationState) + host.listener?.didSelectRoomNotificationState(notificationState) } } } @@ -104,8 +103,9 @@ class RoomListQuickActionsEpoxyController @Inject constructor( RoomNotificationState.ALL_MESSAGES_NOISY -> R.string.room_settings_all_messages RoomNotificationState.MENTIONS_ONLY -> R.string.room_settings_mention_and_keyword_only RoomNotificationState.MUTE -> R.string.room_settings_none - else -> null + else -> null } + private fun RoomListQuickActionsSharedAction.toBottomSheetItem(index: Int, roomNotificationState: RoomNotificationState? = null) { val host = this@RoomListQuickActionsEpoxyController val selected = when (this) { diff --git a/vector/src/main/java/im/vector/app/features/login2/LoginActivity2.kt b/vector/src/main/java/im/vector/app/features/login2/LoginActivity2.kt index e32ace35b2..eea480864a 100644 --- a/vector/src/main/java/im/vector/app/features/login2/LoginActivity2.kt +++ b/vector/src/main/java/im/vector/app/features/login2/LoginActivity2.kt @@ -41,7 +41,6 @@ import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityLoginBinding import im.vector.app.features.home.HomeActivity -import im.vector.app.features.login.LoginActivity import im.vector.app.features.login.LoginCaptchaFragmentArgument import im.vector.app.features.login.LoginConfig import im.vector.app.features.login.LoginGenericTextInputFormFragmentArgument From 8a0fe41b8069fac95f6bd9192cd52c8efe6ff493 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 3 Dec 2021 15:40:53 +0000 Subject: [PATCH 7/8] adding changelog entry --- changelog.d/4626.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/4626.misc diff --git a/changelog.d/4626.misc b/changelog.d/4626.misc new file mode 100644 index 0000000000..9f2d979cbb --- /dev/null +++ b/changelog.d/4626.misc @@ -0,0 +1 @@ +Introducing feature flagging to the login and notification settings flows \ No newline at end of file From db406704c9fb74db1bbcdd28277691c9214b2fb3 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 3 Dec 2021 15:58:18 +0000 Subject: [PATCH 8/8] removing boolean notification version usage --- .../app/features/settings/VectorPreferences.kt | 3 +++ ...orSettingsNotificationPreferenceFragment.kt | 14 +++++++++++++- .../res/xml/vector_settings_notifications.xml | 18 +++++++----------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 07cd9d6dac..6eb8d7c195 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -47,6 +47,9 @@ class VectorPreferences @Inject constructor(private val context: Context) { const val SETTINGS_DISCOVERY_PREFERENCE_KEY = "SETTINGS_DISCOVERY_PREFERENCE_KEY" const val SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY" + const val SETTINGS_NOTIFICATION_DEFAULT_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_DEFAULT_PREFERENCE_KEY" + const val SETTINGS_NOTIFICATION_KEYWORD_AND_MENTIONS_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_KEYWORD_AND_MENTIONS_PREFERENCE_KEY" + const val SETTINGS_NOTIFICATION_OTHER_PREFERENCE_KEY = "SETTINGS_NOTIFICATION_OTHER_PREFERENCE_KEY" const val SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY = "SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY" const val SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY = "SETTINGS_OTHER_THIRD_PARTY_NOTICES_PREFERENCE_KEY" const val SETTINGS_COPYRIGHT_PREFERENCE_KEY = "SETTINGS_COPYRIGHT_PREFERENCE_KEY" diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt index 4199bd1753..3004d30913 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt @@ -40,6 +40,7 @@ import im.vector.app.core.pushers.PushersManager import im.vector.app.core.services.GuardServiceStarter import im.vector.app.core.utils.isIgnoringBatteryOptimizations import im.vector.app.core.utils.requestDisablingBatteryOptimization +import im.vector.app.features.VectorFeatures import im.vector.app.features.notifications.NotificationUtils import im.vector.app.features.settings.BackgroundSyncMode import im.vector.app.features.settings.BackgroundSyncModeChooserDialog @@ -63,7 +64,8 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( private val pushManager: PushersManager, private val activeSessionHolder: ActiveSessionHolder, private val vectorPreferences: VectorPreferences, - private val guardServiceStarter: GuardServiceStarter + private val guardServiceStarter: GuardServiceStarter, + private val features: VectorFeatures ) : VectorSettingsBaseFragment(), BackgroundSyncModeChooserDialog.InteractionListener { @@ -145,6 +147,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( refreshBackgroundSyncPrefs() handleSystemPreference() + handleVersionedSettings() } private fun bindEmailNotifications() { @@ -309,6 +312,15 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( } } + private fun handleVersionedSettings() { + val isNotificationSettingsV2Enabled = features.notificationSettingsVersion() == VectorFeatures.NotificationSettingsVersion.V2 + + findPreference(VectorPreferences.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY)?.isVisible = !isNotificationSettingsV2Enabled + findPreference(VectorPreferences.SETTINGS_NOTIFICATION_DEFAULT_PREFERENCE_KEY)?.isVisible = isNotificationSettingsV2Enabled + findPreference(VectorPreferences.SETTINGS_NOTIFICATION_KEYWORD_AND_MENTIONS_PREFERENCE_KEY)?.isVisible = isNotificationSettingsV2Enabled + findPreference(VectorPreferences.SETTINGS_NOTIFICATION_OTHER_PREFERENCE_KEY)?.isVisible = isNotificationSettingsV2Enabled + } + override fun onResume() { super.onResume() activeSessionHolder.getSafeActiveSession()?.refreshPushers() diff --git a/vector/src/main/res/xml/vector_settings_notifications.xml b/vector/src/main/res/xml/vector_settings_notifications.xml index 7d41bdbd86..154e7cca0d 100644 --- a/vector/src/main/res/xml/vector_settings_notifications.xml +++ b/vector/src/main/res/xml/vector_settings_notifications.xml @@ -26,38 +26,34 @@ android:persistent="false" android:summary="@string/settings_notification_advanced_summary" android:title="@string/settings_notification_advanced" - app:fragment="im.vector.app.features.settings.notifications.VectorSettingsAdvancedNotificationPreferenceFragment" - app:isPreferenceVisible="@bool/useNotificationSettingsV1" /> + app:fragment="im.vector.app.features.settings.notifications.VectorSettingsAdvancedNotificationPreferenceFragment" /> + app:fragment="im.vector.app.features.settings.notifications.VectorSettingsDefaultNotificationPreferenceFragment" /> + app:fragment="im.vector.app.features.settings.notifications.VectorSettingsKeywordAndMentionsNotificationPreferenceFragment" /> + app:fragment="im.vector.app.features.settings.notifications.VectorSettingsOtherNotificationPreferenceFragment" /> + android:title="@string/settings_notification_emails_category" />