From 87a8c786f722492165ba9477a0e408121d55d3fb Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 30 Jun 2022 12:22:39 +0100 Subject: [PATCH] moving the voice message limit to the config module --- .../main/java/im/vector/app/config/Config.kt | 5 +++++ vector/build.gradle | 2 -- .../im/vector/app/core/di/SingletonModule.kt | 6 ++++++ .../composer/voice/VoiceMessageConfig.kt | 21 +++++++++++++++++++ .../voice/VoiceMessageRecorderView.kt | 3 ++- 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/VoiceMessageConfig.kt 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 f96df302e9..31bb6ed1e0 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 @@ -37,6 +37,11 @@ object Config { */ const val ALLOW_EXTERNAL_UNIFIED_PUSH_DISTRIBUTORS = true + /** + * The maximum length of voice messages in milliseconds. + */ + const val VOICE_MESSAGE_LIMIT = 120_000L + /** * The analytics configuration to use for the Debug build type. * Can be disabled by providing Analytics.Disabled diff --git a/vector/build.gradle b/vector/build.gradle index 0b7973a148..d306b06bb3 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -160,8 +160,6 @@ android { buildConfigField "im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrategy", "outboundSessionKeySharingStrategy", "im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrategy.WhenTyping" - buildConfigField "Long", "VOICE_MESSAGE_DURATION_LIMIT_MS", "120_000L" - // If set, MSC3086 asserted identity messages sent on VoIP calls will cause the call to appear in the room corresponding to the asserted identity. // This *must* only be set in trusted environments. buildConfigField "Boolean", "handleCallAssertedIdentityEvents", "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 ea3bf98f26..e1d69f97d9 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 @@ -47,6 +47,7 @@ import im.vector.app.features.analytics.AnalyticsConfig import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.VectorAnalytics import im.vector.app.features.analytics.impl.DefaultVectorAnalytics +import im.vector.app.features.home.room.detail.composer.voice.VoiceMessageConfig import im.vector.app.features.invite.AutoAcceptInvites import im.vector.app.features.invite.CompileTimeAutoAcceptInvites import im.vector.app.features.navigation.DefaultNavigator @@ -228,6 +229,11 @@ object VectorStaticModule { @Provides fun providesPhoneNumberUtil(): PhoneNumberUtil = PhoneNumberUtil.getInstance() + @Provides + fun providesVoiceMessageConfig() = VoiceMessageConfig( + lengthLimitMs = Config.VOICE_MESSAGE_LIMIT + ) + @Provides @Singleton fun providesBuildMeta() = BuildMeta() diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/VoiceMessageConfig.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/VoiceMessageConfig.kt new file mode 100644 index 0000000000..5ba5e40ca8 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/VoiceMessageConfig.kt @@ -0,0 +1,21 @@ +/* + * 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.features.home.room.detail.composer.voice + +data class VoiceMessageConfig( + val lengthLimitMs: Long +) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/VoiceMessageRecorderView.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/VoiceMessageRecorderView.kt index 536a582ec1..c2775976fc 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/VoiceMessageRecorderView.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/VoiceMessageRecorderView.kt @@ -57,6 +57,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor( } @Inject lateinit var clock: Clock + @Inject lateinit var voiceMessageConfig: VoiceMessageConfig // We need to define views as lateinit var to be able to check if initialized for the bug fix on api 21 and 22. @Suppress("UNNECESSARY_LATEINIT") @@ -202,7 +203,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor( private fun onRecordingTick(isLocked: Boolean, milliseconds: Long) { voiceMessageViews.renderRecordingTimer(isLocked, milliseconds / 1_000) - val timeDiffToRecordingLimit = BuildConfig.VOICE_MESSAGE_DURATION_LIMIT_MS - milliseconds + val timeDiffToRecordingLimit = voiceMessageConfig.lengthLimitMs - milliseconds if (timeDiffToRecordingLimit <= 0) { post { callback.onRecordingLimitReached()