new setting to show/hide new stt button - defaults to 'show' to enable discovery by user. move compose stt feature from double-tap compose entry box to new button on compose activity

This commit is contained in:
gavine99
2025-02-12 14:35:17 +11:00
parent 7003306666
commit 51a0576ce0
11 changed files with 112 additions and 59 deletions
@@ -108,6 +108,7 @@ class Preferences @Inject constructor(
val black = rxPrefs.getBoolean("black", false)
val autoColor = rxPrefs.getBoolean("autoColor", true)
val systemFont = rxPrefs.getBoolean("systemFont", false)
val showStt = rxPrefs.getBoolean("showStt", true)
val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL)
val blockingManager = rxPrefs.getInteger("blockingManager", BLOCKING_MANAGER_QKSMS)
val drop = rxPrefs.getBoolean("drop", false)
@@ -108,6 +108,9 @@ import kotlinx.android.synthetic.main.compose_activity.sendAsGroupBackground
import kotlinx.android.synthetic.main.compose_activity.sendAsGroupSwitch
import kotlinx.android.synthetic.main.compose_activity.sim
import kotlinx.android.synthetic.main.compose_activity.simIndex
import kotlinx.android.synthetic.main.compose_activity.speechToTextFrame
import kotlinx.android.synthetic.main.compose_activity.speechToTextIcon
import kotlinx.android.synthetic.main.compose_activity.speechToTextIconBorder
import kotlinx.android.synthetic.main.compose_activity.toolbarSubtitle
import kotlinx.android.synthetic.main.compose_activity.toolbarTitle
import kotlinx.android.synthetic.main.main_activity.toolbar
@@ -160,31 +163,12 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
override val confirmDeleteIntent: Subject<List<Long>> = PublishSubject.create()
override val messageLinkAskIntent: Subject<Uri> by lazy { messageAdapter.messageLinkClicks }
override val speechRecogniserIntent by lazy { speechToTextIconBorder.clicks() }
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ComposeViewModel::class.java] }
private var cameraDestination: Uri? = null
private val speechResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode != Activity.RESULT_OK)
return@registerForActivityResult
// check returned results are good
val match = result.data?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
if ((match === null) || (match.size < 1) || (match[0].isNullOrEmpty()))
return@registerForActivityResult
// get the edit text view
val message = findViewById<QkEditText>(R.id.message)
if (message === null)
return@registerForActivityResult
// populate message box with data returned by STT, set cursor to end, and focus
message.append(match[0])
message.setSelection(message.text.length)
message.requestFocus()
}
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
@@ -215,46 +199,13 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
.doOnNext { loading.setTint(it.theme) }
.doOnNext { attach.setBackgroundTint(it.theme) }
.doOnNext { attach.setTint(it.textPrimary) }
.doOnNext { speechToTextIconBorder.setBackgroundTint(it.theme) }
.doOnNext { speechToTextIcon.setBackgroundTint(it.textPrimary) }
.doOnNext { speechToTextIcon.setTint(it.theme) }
.doOnNext { messageAdapter.theme = it }
.autoDisposable(scope())
.subscribe()
message.setOnTouchListener(object : OnTouchListener {
private val gestureDetector =
GestureDetector(this@ComposeActivity, object : SimpleOnGestureListener() {
private var lastUpEvent: MotionEvent? = null
override fun onDoubleTap(e: MotionEvent): Boolean {
val speechRecognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
.putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
)
// include if want a custom message that the STT can (optionally) display .putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak your message")
speechResultLauncher.launch(speechRecognizerIntent)
return true
}
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
if (lastUpEvent !== null) {
message.onTouchEvent(lastUpEvent)
lastUpEvent?.recycle()
lastUpEvent = null
}
return true
}
override fun onSingleTapUp(e: MotionEvent): Boolean {
lastUpEvent = MotionEvent.obtain(e)
return true // don't show soft keyboard on this event
}
})
override fun onTouch(v: View, e: MotionEvent): Boolean {
return gestureDetector.onTouchEvent(e)
}
})
// context menu registration for message parts
messagePartContextMenuRegistrar
.mapNotNull { it }
@@ -375,6 +326,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
// if scheduling mode is set, show schedule dialog
if (state.scheduling)
scheduleAction.onNext(true)
speechToTextFrame.isVisible = (prefs.showStt.get())
}
override fun clearSelection() = messageAdapter.clearSelection()
@@ -460,6 +413,18 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
startActivityForResult(intent, ComposeView.SelectContactRequestCode)
}
override fun startSpeechRecognition() {
startActivityForResult(
Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
),
// include below if want a custom message that the STT can (optionally) display
// .putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak your message")
ComposeView.SpeechRecognitionRequestCode
)
}
override fun themeChanged() {
messageList.scrapViews()
}
@@ -576,6 +541,21 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
data?.data?.let(contactSelectedIntent::onNext)
}
ComposeView.SpeechRecognitionRequestCode -> {
// check returned results are good
val match = data?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
if ((match !== null) && (match.size > 0) && (!match[0].isNullOrEmpty())) {
// get the edit text view
val messageEditBox = findViewById<QkEditText>(R.id.message)
if (messageEditBox !== null) {
// populate message box with data returned by STT, set cursor to end, and focus
messageEditBox.append(match[0])
messageEditBox.setSelection(messageEditBox.text.length)
messageEditBox.requestFocus()
}
}
}
else -> super.onActivityResult(requestCode, resultCode, data)
}
}
@@ -34,8 +34,9 @@ interface ComposeView : QkView<ComposeState> {
companion object {
const val SelectContactRequestCode = 0
const val TakePhotoRequestCode = 1
const val AttachAFileRequestCode = 4
const val AttachContactRequestCode = 3
const val AttachAFileRequestCode = 4
const val SpeechRecognitionRequestCode = 5
const val CameraDestinationKey = "camera_destination"
}
@@ -73,6 +74,7 @@ interface ComposeView : QkView<ComposeState> {
val backPressedIntent: Observable<Unit>
val confirmDeleteIntent: Observable<List<Long>>
val messageLinkAskIntent: Observable<Uri>
val speechRecogniserIntent: Observable<*>
fun clearSelection()
fun toggleSelectAll()
@@ -93,5 +95,6 @@ interface ComposeView : QkView<ComposeState> {
fun scrollToMessage(id: Long)
fun showQksmsPlusSnackbar(@StringRes message: Int)
fun showDeleteDialog( messages: List<Long>)
fun startSpeechRecognition()
}
@@ -763,6 +763,11 @@ class ComposeViewModel @Inject constructor(
.autoDisposable(view.scope())
.subscribe()
// speech recognition button clicked
view.speechRecogniserIntent
.autoDisposable(view.scope())
.subscribe { view.startSpeechRecognition() }
// Send a message when the send button is clicked, and disable editing mode if it's enabled
view.sendIntent
.withLatestFrom(view.textChangedIntent) { _, body -> body.toString() }
@@ -184,6 +184,8 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
systemFont.checkbox.isChecked = state.systemFontEnabled
showStt.checkbox.isChecked = state.showStt
unicode.checkbox.isChecked = state.stripUnicodeEnabled
mobileOnly.checkbox.isChecked = state.mobileOnly
@@ -116,7 +116,10 @@ class SettingsPresenter @Inject constructor(
.subscribe { autoColor -> newState { copy(autoColor = autoColor) } }
disposables += prefs.systemFont.asObservable()
.subscribe { enabled -> newState { copy(systemFontEnabled = enabled) } }
.subscribe { enabled -> newState { copy(systemFontEnabled = enabled) } }
disposables += prefs.showStt.asObservable()
.subscribe { enabled -> newState { copy(showStt = enabled) } }
disposables += prefs.unicode.asObservable()
.subscribe { enabled -> newState { copy(stripUnicodeEnabled = enabled) } }
@@ -207,6 +210,8 @@ class SettingsPresenter @Inject constructor(
R.id.systemFont -> prefs.systemFont.set(!prefs.systemFont.get())
R.id.showStt -> prefs.showStt.set(!prefs.showStt.get())
R.id.unicode -> prefs.unicode.set(!prefs.unicode.get())
R.id.mobileOnly -> prefs.mobileOnly.set(!prefs.mobileOnly.get())
@@ -39,6 +39,7 @@ data class SettingsState(
val textSizeSummary: String = "",
val textSizeId: Int = Preferences.TEXT_SIZE_NORMAL,
val systemFontEnabled: Boolean = false,
val showStt: Boolean = true,
val splitSmsEnabled: Boolean = false,
val stripUnicodeEnabled: Boolean = false,
val mobileOnly: Boolean = false,
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<vector xmlns:aapt="http://schemas.android.com/aapt"
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="56dp"
android:width="56dp"
android:viewportHeight="100.0"
android:viewportWidth="100.0">
<path android:fillColor="#FF000000" android:pathData="m41.16 52.48h0.37891l0.46875-0.019531c0.32031 0 0.62891-0.03125 0.94141-0.089844 0.62891-0.078125 1.25-0.23047 1.8516-0.42969 2.4102-0.80078 4.4805-2.5391 5.7109-4.7695 1.2383-2.2383 1.5898-4.9492 0.98047-7.4492-0.30859-1.25-0.85156-2.4492-1.5898-3.5117-0.37109-0.53125-0.80078-1.0312-1.2617-1.4805l-1.0586-1.0391c-5.3086-5.3086-9.0508-12.078-10.648-19.211-0.33984-1.5781-0.80078-3.9297-1.7617-5.4805-0.96094-1.5781-2.4297-2.5312-4.8203-1.7812-1.9609 0.60938-2.4805 2.1016-2.3984 3.8516 0.039063 0.87891 0.23828 1.8086 0.48047 2.7383 0.12891 0.46094 0.26172 0.92188 0.37891 1.3711 0.14844 0.48047 0.28906 0.94922 0.42969 1.3984 2.5117 8.0508 7.1914 15.391 13.301 21.129 0.37109 0.37109 0.76953 0.71094 1.1602 1.0586l0.57031 0.51172c0.10156 0.078125 0.19141 0.17188 0.28125 0.26172 0.35156 0.35938 0.64844 0.78906 0.85156 1.2617 0.42188 0.92969 0.46094 2.0586 0.12109 3.0391-0.32812 0.98828-1.0586 1.8594-1.9883 2.3789-0.46094 0.26172-0.96875 0.42188-1.5 0.48828-0.33984 0.058594-1.5586 0.039063-2.4805 0.039063h-1.5781c-1.6602 0.019531-3.2891 0.91016-4.1914 2.3008-0.46094 0.69141-0.75 1.5-0.82812 2.3281l-0.019532 0.30859v0.23828 0.19141 0.37891 1.5195 6.0781 6.0781 2.9297c-0.019531 0.39062-0.12891 0.76172-0.33984 1.0898-0.19922 0.32812-0.51172 0.60156-0.83984 0.78125-0.17188 0.089844-0.35156 0.14844-0.53125 0.19922-0.089844 0.019531-0.19141 0.03125-0.28125 0.039062-0.10938 0-0.14062 0.019531-0.46094 0.011719h-6.0781-3.0391-0.37891-0.33984c-0.14844 0-0.30078 0.019531-0.44922 0.039062-0.60156 0.070313-1.1914 0.23047-1.75 0.46875-1.1094 0.48047-2.0703 1.3086-2.7188 2.3281-0.16016 0.26172-0.30859 0.53125-0.42188 0.80078l-0.14844 0.35156-0.30859 0.69922-0.62109 1.3906-1.2305 2.7812c-1.0781 2.4414-3.5898 5.6602-0.30078 7.3086 3.5586 1.7812 4.2305-2.4609 5.3008-4.7617l2.4883-5.3984c0.12109-0.23828 0.23828-0.26172 0.39844-0.28125l2.9414 0.019532 5.9492 0.019531c0.51172 0 0.92188 0.019531 1.6797-0.03125 0.67969-0.070313 1.3594-0.19922 2-0.44922 1.3008-0.46094 2.4492-1.2812 3.3398-2.3203 0.89062-1.0391 1.5-2.3203 1.7617-3.6719 0.050781-0.33984 0.10938-0.67969 0.12109-1.0195l0.019531-0.5v-0.37109-1.4883l-0.019531-5.9492v-5.9492-2.7617h2.5z "/>
<path android:fillColor="#FF000000" android:pathData="m60.738 79.211c2.8281 2.7891 2.6914 1.2695 3.0898 0.87891 2.5391-2.7188 3.7891-6.4688 4.0195-10.129 0.12891-1.8516 0.050782-3.6992-0.16016-5.5898s-0.55078-3.8398-1.0586-5.9102c-0.21094-0.96875-0.82812-2.3711-4.6719 0.80859-3.1797 2.6211-2.3711 2.8906-2.1094 3.3594 0.62109 1.0117 1.1719 2.0508 1.6094 3.1797 0.42969 1.1289 0.71875 2.3516 0.67969 3.5898-0.12109 2.5898-1.0703 5.0898-2.6406 7.1289-0.30078 0.33984-1.3906 0.10156 1.2383 2.6797z "/>
<path android:fillColor="#FF000000" android:pathData="m77.199 88.02c-0.62891 0.82812-2.2812 1.3789 0.51172 3.8008 3 2.6094 3.3008 0.39844 4.0117-0.46875 4.3203-5.6914 6.6602-12.762 7.1289-19.859 0.25-3.5586 0.089844-7.1289-0.37891-10.699-0.46875-3.5781-1.2695-7.1602-2.4102-10.762-0.21875-0.85938-0.66016-1.8594-1.5-2.3281-0.85156-0.46875-2.1289-0.33984-4.1914 1.0703-3.3984 2.3398-2 3.6484-1.4219 4.8086 1.3711 2.5898 2.4414 5.3281 3.1992 8.1797 0.75 2.8516 1.1602 5.8281 1.0195 8.8086-0.33984 6.2305-2.4414 12.309-5.9609 17.43z "/>
</vector>
@@ -27,6 +27,41 @@
android:orientation="vertical"
tools:context="dev.octoshrimpy.quik.feature.compose.ComposeActivity">
<FrameLayout
android:id="@+id/speechToTextFrame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:elevation="4dp"
android:padding="8dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/sendAsGroupBackground"
tools:visibility="visible">
<ImageView
android:id="@+id/speechToTextIconBorder"
android:layout_width="78dp"
android:layout_height="78dp"
android:background="@drawable/circle"
android:padding="6dp"
tools:backgroundTint="@color/tools_theme"
tools:tint="@color/textPrimaryDark" />
<ImageView
android:id="@+id/speechToTextIcon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/circle"
android:elevation="1dp"
android:padding="8dp"
app:srcCompat="@drawable/ic_speech_to_text_black"
tools:tint="@color/tools_theme" />
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/messageList"
android:layout_width="0dp"
@@ -39,7 +74,8 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sendAsGroupBackground"
app:stackFromEnd="true"
tools:listitem="@layout/message_list_item_in" />
tools:listitem="@layout/message_list_item_in"
tools:visibility="invisible" />
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/messagesEmpty"
@@ -100,6 +100,14 @@
app:title="@string/settings_system_font_title"
app:widget="@layout/settings_switch_widget" />
<dev.octoshrimpy.quik.common.widget.PreferenceView
android:id="@+id/showStt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_speech_to_text_black"
app:title="@string/settings_system_show_stt_title"
app:widget="@layout/settings_switch_widget" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
@@ -240,6 +240,7 @@
<string name="settings_automatic_colors_title">Automatic contact colors</string>
<string name="settings_text_size_title">Font size</string>
<string name="settings_system_font_title">Use system font</string>
<string name="settings_system_show_stt_title">Show the speech to text button</string>
<string name="settings_auto_emoji_title">Automatic emoji</string>
<string name="settings_notifications_title">Notifications</string>
<string name="settings_notifications_o_summary">Tap to customize</string>