Skip to content

Commit 850f1bf

Browse files
authored
move duck.ai input screen return button, improve input string management (#6308)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1208671518894266/task/1210659642047207?focus=true ### Description - Moves the return button in the Duck.ai input screen to the side of the submit button. - Fixes an issue where the submit button was visible when only new lines were in the input field. - Fixes an issue where return key didn't replace selected text. - Fixes voice input button's background color. ### Steps to test this PR - [ ] Verify that even if voice input is enabled, return key is next to submit button. - [ ] Open the input screen, clear text, add new lines. Verify the submit button is not visible. - [ ] Input some text, select all or portion of it, click the return key and verify that the whole selection is replaced.
1 parent ccf3f58 commit 850f1bf

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/ui/DuckChatOmnibarLayout.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class DuckChatOmnibarLayout @JvmOverloads constructor(
8585
var onSendMessageAvailable: ((Boolean) -> Unit)? = null
8686
set(value) {
8787
field = value
88-
value?.invoke(!duckChatInput.text.isNullOrEmpty())
88+
value?.invoke(duckChatInput.text.getTextToSubmit() != null)
8989
}
9090

9191
@IdRes
@@ -139,9 +139,9 @@ class DuckChatOmnibarLayout @JvmOverloads constructor(
139139
}
140140

141141
doOnTextChanged { text, _, _, _ ->
142+
onSendMessageAvailable?.invoke(duckChatInput.text.getTextToSubmit() != null)
142143
val isNullOrEmpty = text.isNullOrEmpty()
143144
fade(duckChatClearText, !isNullOrEmpty)
144-
onSendMessageAvailable?.invoke(!isNullOrEmpty)
145145

146146
if (isNullOrEmpty && duckChatInput.minLines > 1) {
147147
duckChatInput.post {
@@ -201,12 +201,13 @@ class DuckChatOmnibarLayout @JvmOverloads constructor(
201201
}
202202

203203
fun submitMessage(message: String? = null) {
204-
val text = message?.also(duckChatInput::setText) ?: duckChatInput.text.toString().trim()
205-
if (text.isNotBlank()) {
204+
val text = message?.also(duckChatInput::setText) ?: duckChatInput.text
205+
val textToSubmit = text.getTextToSubmit()?.toString()
206+
if (textToSubmit != null) {
206207
if (duckChatTabLayout.selectedTabPosition == 0) {
207-
onSearchSent?.invoke(text)
208+
onSearchSent?.invoke(textToSubmit)
208209
} else {
209-
onDuckChatSent?.invoke(text)
210+
onDuckChatSent?.invoke(textToSubmit)
210211
}
211212
duckChatInput.clearFocus()
212213
}
@@ -291,10 +292,16 @@ class DuckChatOmnibarLayout @JvmOverloads constructor(
291292

292293
fun printNewLine() {
293294
val currentText = duckChatInput.text.toString()
294-
val currentSelection = duckChatInput.selectionStart
295-
val newText = currentText.substring(0, currentSelection) + "\n" + currentText.substring(currentSelection)
295+
val selectionStart = duckChatInput.selectionStart
296+
val selectionEnd = duckChatInput.selectionEnd
297+
val newText = currentText.substring(0, selectionStart) + "\n" + currentText.substring(selectionEnd)
296298
duckChatInput.setText(newText)
297-
duckChatInput.setSelection(currentSelection + 1)
299+
duckChatInput.setSelection(selectionStart + 1)
300+
}
301+
302+
private fun CharSequence.getTextToSubmit(): CharSequence? {
303+
val text = this.trim()
304+
return text.ifBlank { null }
298305
}
299306

300307
companion object {

duckchat/duckchat-impl/src/main/res/layout/fragment_search_interstitial.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,19 @@
6363
app:layout_constraintEnd_toEndOf="parent"/>
6464

6565
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
66-
android:id="@+id/actionVoice"
66+
android:id="@+id/actionNewLine"
6767
android:layout_width="40dp"
6868
android:layout_height="40dp"
6969
android:minWidth="0dp"
7070
android:minHeight="0dp"
71-
android:backgroundTint="?attr/daxColorSurface"
71+
android:backgroundTint="?attr/daxColorWindow"
7272
android:layout_marginBottom="@dimen/keyline_3"
7373
android:layout_marginEnd="@dimen/keyline_3"
7474
android:importantForAccessibility="no"
7575
android:text="&#8203;"
7676
android:textColor="@android:color/transparent"
77-
android:visibility="gone"
78-
app:icon="@drawable/ic_microphone_24"
77+
android:visibility="visible"
78+
app:icon="@drawable/ic_return_24"
7979
app:iconTint="?attr/daxColorPrimaryIcon"
8080
app:iconPadding="0dp"
8181
app:iconGravity="textStart"
@@ -84,7 +84,7 @@
8484
app:layout_constraintEnd_toStartOf="@id/actionSend"/>
8585

8686
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
87-
android:id="@+id/actionNewLine"
87+
android:id="@+id/actionVoice"
8888
android:layout_width="40dp"
8989
android:layout_height="40dp"
9090
android:minWidth="0dp"
@@ -95,13 +95,13 @@
9595
android:importantForAccessibility="no"
9696
android:text="&#8203;"
9797
android:textColor="@android:color/transparent"
98-
android:visibility="visible"
99-
app:icon="@drawable/ic_return_24"
98+
android:visibility="gone"
99+
app:icon="@drawable/ic_microphone_24"
100100
app:iconTint="?attr/daxColorPrimaryIcon"
101101
app:iconPadding="0dp"
102102
app:iconGravity="textStart"
103103
app:rippleColor="?attr/daxColorRipple"
104104
app:layout_constraintBottom_toBottomOf="parent"
105-
app:layout_constraintEnd_toStartOf="@id/actionVoice"/>
105+
app:layout_constraintEnd_toStartOf="@id/actionNewLine"/>
106106

107107
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)