From 9fe3fc69dd678b3b84db97c3a7d4ba48eacf68d0 Mon Sep 17 00:00:00 2001
From: Adam Brown <adampsbrown@gmail.com>
Date: Fri, 1 Jul 2022 14:20:18 +0100
Subject: [PATCH] extracting the config models to their own files

---
 .../java/im/vector/app/config/Analytics.kt    | 48 ++++++++++++++++
 .../main/java/im/vector/app/config/Config.kt  | 55 -------------------
 .../vector/app/config/KeySharingStrategy.kt   | 35 ++++++++++++
 .../im/vector/app/config/OnboardingVariant.kt | 23 ++++++++
 .../vector/app/core/di/ConfigurationModule.kt | 10 ++--
 .../im/vector/app/core/di/SingletonModule.kt  | 24 --------
 6 files changed, 112 insertions(+), 83 deletions(-)
 create mode 100644 vector-config/src/main/java/im/vector/app/config/Analytics.kt
 create mode 100644 vector-config/src/main/java/im/vector/app/config/KeySharingStrategy.kt
 create mode 100644 vector-config/src/main/java/im/vector/app/config/OnboardingVariant.kt

diff --git a/vector-config/src/main/java/im/vector/app/config/Analytics.kt b/vector-config/src/main/java/im/vector/app/config/Analytics.kt
new file mode 100644
index 0000000000..7fdc78dc8a
--- /dev/null
+++ b/vector-config/src/main/java/im/vector/app/config/Analytics.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2022 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.config
+
+/**
+ * The types of analytics Element currently supports.
+ */
+sealed interface Analytics {
+
+    /**
+     * Disables the analytics integrations.
+     */
+    object Disabled : Analytics
+
+    /**
+     * Analytics integration via PostHog.
+     */
+    data class PostHog(
+            /**
+             * The PostHog instance url.
+             */
+            val postHogHost: String,
+
+            /**
+             * The PostHog instance API key.
+             */
+            val postHogApiKey: String,
+
+            /**
+             * A URL to more information about the analytics collection.
+             */
+            val policyLink: String,
+    ) : Analytics
+}
diff --git a/vector-config/src/main/java/im/vector/app/config/Config.kt b/vector-config/src/main/java/im/vector/app/config/Config.kt
index a15ac198b9..ef9b6a7b8d 100644
--- a/vector-config/src/main/java/im/vector/app/config/Config.kt
+++ b/vector-config/src/main/java/im/vector/app/config/Config.kt
@@ -87,58 +87,3 @@ object Config {
      */
     val NIGHTLY_ANALYTICS_CONFIG = RELEASE_ANALYTICS_CONFIG
 }
-
-/**
- * The types of analytics Element currently supports.
- */
-sealed interface Analytics {
-
-    /**
-     * Disables the analytics integrations.
-     */
-    object Disabled : Analytics
-
-    /**
-     * Analytics integration via PostHog.
-     */
-    data class PostHog(
-            /**
-             * The PostHog instance url.
-             */
-            val postHogHost: String,
-
-            /**
-             * The PostHog instance API key.
-             */
-            val postHogApiKey: String,
-
-            /**
-             * A URL to more information about the analytics collection.
-             */
-            val policyLink: String,
-    ) : Analytics
-}
-
-enum class OnboardingVariant {
-    LEGACY,
-    LOGIN_2,
-    FTUE_AUTH
-}
-
-enum class KeySharingStrategy {
-    /**
-     * Keys will be sent for the first time when the first message is sent.
-     * This is handled by the Matrix SDK so there's no need to do it in Vector.
-     */
-    WhenSendingEvent,
-
-    /**
-     * Keys will be sent for the first time when the timeline displayed.
-     */
-    WhenEnteringRoom,
-
-    /**
-     * Keys will be sent for the first time when a typing started.
-     */
-    WhenTyping
-}
diff --git a/vector-config/src/main/java/im/vector/app/config/KeySharingStrategy.kt b/vector-config/src/main/java/im/vector/app/config/KeySharingStrategy.kt
new file mode 100644
index 0000000000..51f3d81151
--- /dev/null
+++ b/vector-config/src/main/java/im/vector/app/config/KeySharingStrategy.kt
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2022 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.config
+
+enum class KeySharingStrategy {
+    /**
+     * Keys will be sent for the first time when the first message is sent.
+     * This is handled by the Matrix SDK so there's no need to do it in Vector.
+     */
+    WhenSendingEvent,
+
+    /**
+     * Keys will be sent for the first time when the timeline displayed.
+     */
+    WhenEnteringRoom,
+
+    /**
+     * Keys will be sent for the first time when a typing started.
+     */
+    WhenTyping
+}
diff --git a/vector-config/src/main/java/im/vector/app/config/OnboardingVariant.kt b/vector-config/src/main/java/im/vector/app/config/OnboardingVariant.kt
new file mode 100644
index 0000000000..ae8cfd1172
--- /dev/null
+++ b/vector-config/src/main/java/im/vector/app/config/OnboardingVariant.kt
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2022 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.config
+
+enum class OnboardingVariant {
+    LEGACY,
+    LOGIN_2,
+    FTUE_AUTH
+}
diff --git a/vector/src/main/java/im/vector/app/core/di/ConfigurationModule.kt b/vector/src/main/java/im/vector/app/core/di/ConfigurationModule.kt
index 10c91a5dd1..25d3d8311f 100644
--- a/vector/src/main/java/im/vector/app/core/di/ConfigurationModule.kt
+++ b/vector/src/main/java/im/vector/app/core/di/ConfigurationModule.kt
@@ -37,10 +37,12 @@ import im.vector.app.features.raw.wellknown.CryptoConfig
 object ConfigurationModule {
 
     @Provides
-    fun providesAnalyticsConfig(buildMeta: BuildMeta): AnalyticsConfig {
-        val config: Analytics = when (buildMeta.isDebug) {
-            true -> Config.DEBUG_ANALYTICS_CONFIG
-            false -> Config.RELEASE_ANALYTICS_CONFIG
+    fun providesAnalyticsConfig(): AnalyticsConfig {
+        val config: Analytics = when (BuildConfig.BUILD_TYPE) {
+            "debug" -> Config.DEBUG_ANALYTICS_CONFIG
+            "nightly" -> Config.NIGHTLY_ANALYTICS_CONFIG
+            "release" -> Config.RELEASE_ANALYTICS_CONFIG
+            else -> throw IllegalStateException("Unhandled build type: ${BuildConfig.BUILD_TYPE}")
         }
         return when (config) {
             Analytics.Disabled -> AnalyticsConfig(isEnabled = false, "", "", "")
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 3ba9eb0f5b..0b7e3b347d 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
@@ -211,30 +211,6 @@ object VectorStaticModule {
     @Provides
     fun providesPhoneNumberUtil(): PhoneNumberUtil = PhoneNumberUtil.getInstance()
 
-    @Provides
-    fun providesAnalyticsConfig(): AnalyticsConfig {
-        val config: Analytics = when (BuildConfig.BUILD_TYPE) {
-            "debug" -> Config.DEBUG_ANALYTICS_CONFIG
-            "nightly" -> Config.NIGHTLY_ANALYTICS_CONFIG
-            "release" -> Config.RELEASE_ANALYTICS_CONFIG
-            else -> throw IllegalStateException("Unhandled build type: ${BuildConfig.BUILD_TYPE}")
-        }
-        return when (config) {
-            Analytics.Disabled -> AnalyticsConfig(isEnabled = false, "", "", "")
-            is Analytics.PostHog -> AnalyticsConfig(
-                    isEnabled = true,
-                    postHogHost = config.postHogHost,
-                    postHogApiKey = config.postHogApiKey,
-                    policyLink = config.policyLink
-            )
-        }
-    }
-
-    @Provides
-    fun providesVoiceMessageConfig() = VoiceMessageConfig(
-            lengthLimitMs = Config.VOICE_MESSAGE_LIMIT_MS
-    )
-
     @Provides
     @Singleton
     fun providesBuildMeta() = BuildMeta(