From 5856e563c5ce58a87b972714f599cee4d6566280 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Wed, 7 Jul 2021 10:23:22 +0300 Subject: [PATCH] Put voice message preference under labs. --- .../features/home/room/detail/RoomDetailFragment.kt | 7 ++++--- .../features/home/room/detail/RoomDetailViewModel.kt | 7 +++++-- .../home/room/detail/composer/TextComposerView.kt | 12 +++++++++--- .../home/room/detail/composer/VoiceMessageHelper.kt | 3 +++ .../app/features/settings/VectorPreferences.kt | 7 +++++++ vector/src/main/res/values/strings.xml | 1 + vector/src/main/res/xml/vector_settings_labs.xml | 5 +++++ 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 4b6cc38264..493b8596c3 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -922,7 +922,7 @@ class RoomDetailFragment @Inject constructor( autoCompleter.exitSpecialMode() views.composerLayout.collapse() - views.voiceMessageRecorderView.isVisible = text.isBlank() + views.voiceMessageRecorderView.isVisible = text.isBlank() && vectorPreferences.labsUseVoiceMessage() updateComposerText(text) views.composerLayout.views.sendButton.contentDescription = getString(R.string.send) @@ -1239,7 +1239,7 @@ class RoomDetailFragment @Inject constructor( } override fun onTextBlankStateChanged(isBlank: Boolean) { - views.voiceMessageRecorderView.isVisible = !views.composerLayout.views.sendButton.isVisible + views.voiceMessageRecorderView.isVisible = !views.composerLayout.views.sendButton.isVisible && vectorPreferences.labsUseVoiceMessage() } override fun onTouchVoiceRecording() { @@ -1259,7 +1259,7 @@ class RoomDetailFragment @Inject constructor( if (text.isNotBlank()) { // We collapse ASAP, if not there will be a slight anoying delay views.composerLayout.collapse(true) - views.voiceMessageRecorderView.isVisible = true + views.voiceMessageRecorderView.isVisible = true && vectorPreferences.labsUseVoiceMessage() lockSendButton = true roomDetailViewModel.handle(RoomDetailAction.SendMessage(text, vectorPreferences.isMarkdownEnabled())) emojiPopup.dismiss() @@ -1314,6 +1314,7 @@ class RoomDetailFragment @Inject constructor( views.composerLayout.visibility = View.VISIBLE views.composerLayout.setRoomEncrypted(summary.isEncrypted) views.notificationAreaView.render(NotificationAreaView.State.Hidden) + views.composerLayout.alwaysShowSendButton = !vectorPreferences.labsUseVoiceMessage() } else { views.composerLayout.visibility = View.GONE views.notificationAreaView.render(NotificationAreaView.State.NoPermissionToPost) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index 166618fae7..3a961ccd4e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -615,8 +615,11 @@ class RoomDetailViewModel @AssistedInject constructor( return } voiceMessageHelper.stopRecording()?.let { audioType -> - room.sendMedia(audioType.toContentAttachmentData(), false, emptySet()) - //voiceMessageRecordingHelper.deleteRecording() + if (audioType.duration > 1000) { + room.sendMedia(audioType.toContentAttachmentData(), false, emptySet()) + } else { + voiceMessageHelper.deleteRecording() + } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/TextComposerView.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/TextComposerView.kt index 383d89749a..1ed54a1e8a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/TextComposerView.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/TextComposerView.kt @@ -20,7 +20,6 @@ import android.content.Context import android.net.Uri import android.text.Editable import android.util.AttributeSet -import android.view.KeyEvent import android.view.ViewGroup import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintSet @@ -63,6 +62,13 @@ class TextComposerView @JvmOverloads constructor( val text: Editable? get() = views.composerEditText.text + var alwaysShowSendButton = false + set(value) { + field = value + val shouldShowSendButton = currentConstraintSetId == R.layout.composer_layout_constraint_set_expanded || text?.isNotBlank().orFalse() || value + views.sendButton.isInvisible = !shouldShowSendButton + } + init { inflate(context, R.layout.composer_layout, this) views = ComposerLayoutBinding.bind(this) @@ -75,7 +81,7 @@ class TextComposerView @JvmOverloads constructor( } override fun onTextBlankStateChanged(isBlank: Boolean) { - val shouldShowSendButton = currentConstraintSetId == R.layout.composer_layout_constraint_set_expanded || !isBlank + val shouldShowSendButton = currentConstraintSetId == R.layout.composer_layout_constraint_set_expanded || !isBlank || alwaysShowSendButton TransitionManager.endTransitions(this@TextComposerView) if (views.sendButton.isVisible != shouldShowSendButton) { TransitionManager.beginDelayedTransition( @@ -110,7 +116,7 @@ class TextComposerView @JvmOverloads constructor( currentConstraintSetId = R.layout.composer_layout_constraint_set_compact applyNewConstraintSet(animate, transitionComplete) - val shouldShowSendButton = !views.composerEditText.text.isNullOrEmpty() + val shouldShowSendButton = !views.composerEditText.text.isNullOrEmpty() || alwaysShowSendButton views.sendButton.isInvisible = !shouldShowSendButton } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt index 1187567b99..84d2cab2a9 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt @@ -179,6 +179,9 @@ class VoiceMessageHelper @Inject constructor( } catch (e: IllegalStateException) { Timber.e(e, "Cannot get max amplitude. Amplitude recording timer will be stopped.") amplitudeTimerTask?.cancel() + } catch (e: RuntimeException) { + Timber.e(e, "Cannot get max amplitude (native error). Amplitude recording timer will be stopped.") + amplitudeTimerTask?.cancel() } } } 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 9fc496a914..3ce7e2a952 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 @@ -153,11 +153,14 @@ class VectorPreferences @Inject constructor(private val context: Context) { const val SETTINGS_LABS_USE_RESTRICTED_JOIN_RULE = "SETTINGS_LABS_USE_RESTRICTED_JOIN_RULE" const val SETTINGS_LABS_SPACES_HOME_AS_ORPHAN = "SETTINGS_LABS_SPACES_HOME_AS_ORPHAN" + const val SETTINGS_LABS_VOICE_MESSAGE = "SETTINGS_LABS_VOICE_MESSAGE" + private const val SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY = "SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY" private const val SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY = "SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY" private const val SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY = "SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY" private const val SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY = "SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY" + // SETTINGS_LABS_HIDE_TECHNICAL_E2E_ERRORS private const val SETTINGS_LABS_SHOW_COMPLETE_HISTORY_IN_ENCRYPTED_ROOM = "SETTINGS_LABS_SHOW_COMPLETE_HISTORY_IN_ENCRYPTED_ROOM" const val SETTINGS_LABS_UNREAD_NOTIFICATIONS_AS_TAB = "SETTINGS_LABS_UNREAD_NOTIFICATIONS_AS_TAB" @@ -973,4 +976,8 @@ class VectorPreferences @Inject constructor(private val context: Context) { putInt(TAKE_PHOTO_VIDEO_MODE, mode) } } + + fun labsUseVoiceMessage(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_LABS_VOICE_MESSAGE, false) + } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 50be146af8..dfbdc88611 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -3419,4 +3419,5 @@ Release to send %1$ds left Tap on the waveform to stop and playback + Enable voice message diff --git a/vector/src/main/res/xml/vector_settings_labs.xml b/vector/src/main/res/xml/vector_settings_labs.xml index 1e0f736db2..50227590be 100644 --- a/vector/src/main/res/xml/vector_settings_labs.xml +++ b/vector/src/main/res/xml/vector_settings_labs.xml @@ -57,4 +57,9 @@ android:key="SETTINGS_LABS_SPACES_HOME_AS_ORPHAN" android:title="@string/labs_space_show_orphan_in_home"/> + + \ No newline at end of file