Skip to content

Commit 31e0df1

Browse files
When user tries to edit query by using the edit icon, modify the quer… (#890)
1 parent 743d22d commit 31e0df1

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

app/src/androidTest/java/com/duckduckgo/app/systemsearch/SystemSearchViewModelTest.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class SystemSearchViewModelTest {
8585

8686
val viewState = testee.onboardingViewState.value
8787
assertFalse(viewState!!.visible)
88-
assertFalse(viewState!!.expanded)
88+
assertFalse(viewState.expanded)
8989
}
9090

9191
@Test
@@ -95,7 +95,7 @@ class SystemSearchViewModelTest {
9595

9696
val viewState = testee.onboardingViewState.value
9797
assertTrue(viewState!!.visible)
98-
assertFalse(viewState!!.expanded)
98+
assertFalse(viewState.expanded)
9999
}
100100

101101
@Test
@@ -263,6 +263,14 @@ class SystemSearchViewModelTest {
263263
assertEquals(Command.ShowAppNotFoundMessage(deviceApp.shortName), commandCaptor.lastValue)
264264
}
265265

266+
@Test
267+
fun whenUserSelectedToUpdateQueryThenEditQueryCommandSent() {
268+
val query = "test"
269+
testee.onUserSelectedToEditQuery(query)
270+
verify(commandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
271+
assertEquals(Command.EditQuery(query), commandCaptor.lastValue)
272+
}
273+
266274
private suspend fun whenOnboardingShowing() {
267275
whenever(mockUserStageStore.getUserAppStage()).thenReturn(AppStage.NEW)
268276
testee.resetViewState()

app/src/main/java/com/duckduckgo/app/systemsearch/SystemSearchActivity.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class SystemSearchActivity : DuckDuckGoActivity() {
129129
viewModel.userSubmittedAutocompleteResult(it.phrase)
130130
},
131131
editableSearchClickListener = {
132-
viewModel.userUpdatedQuery(it.phrase)
132+
viewModel.onUserSelectedToEditQuery(it.phrase)
133133
}
134134
)
135135
autocompleteSuggestions.adapter = autocompleteSuggestionsAdapter
@@ -222,9 +222,17 @@ class SystemSearchActivity : DuckDuckGoActivity() {
222222
is DismissKeyboard -> {
223223
omnibarTextInput.hideKeyboard()
224224
}
225+
is EditQuery -> {
226+
editQuery(command.query)
227+
}
225228
}
226229
}
227230

231+
private fun editQuery(query: String) {
232+
omnibarTextInput.setText(query)
233+
omnibarTextInput.setSelection(query.length)
234+
}
235+
228236
private fun launchDuckDuckGo() {
229237
startActivity(BrowserActivity.intent(this))
230238
finish()

app/src/main/java/com/duckduckgo/app/systemsearch/SystemSearchViewModel.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class SystemSearchViewModel(
6767
data class LaunchDeviceApplication(val deviceApp: DeviceApp) : Command()
6868
data class ShowAppNotFoundMessage(val appName: String) : Command()
6969
object DismissKeyboard : Command()
70+
data class EditQuery(val query: String) : Command()
7071
}
7172

7273
val onboardingViewState: MutableLiveData<OnboardingViewState> = MutableLiveData()
@@ -149,6 +150,10 @@ class SystemSearchViewModel(
149150
}
150151
}
151152

153+
fun onUserSelectedToEditQuery(query: String) {
154+
command.value = Command.EditQuery(query)
155+
}
156+
152157
fun userUpdatedQuery(query: String) {
153158
appsJob?.cancel()
154159

app/src/main/res/layout/item_autocomplete_search_suggestion.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
android:padding="6dp"
6060
android:paddingStart="16dp"
6161
android:paddingEnd="14dp"
62+
android:background="?selectableItemBackground"
6263
app:layout_constraintBottom_toBottomOf="parent"
6364
app:layout_constraintEnd_toEndOf="parent"
6465
app:layout_constraintTop_toTopOf="parent">

0 commit comments

Comments
 (0)