Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interstitial search #719

Merged
merged 29 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
165adc0
Update to latest tooling
subsymbolic Jan 30, 2020
b0a920c
Remove unused parameter
subsymbolic Jan 30, 2020
84cdb3a
Remove unneeded unwrapping as per lint warning
subsymbolic Jan 30, 2020
75ae65e
Remove duplicate data and presentation logic from AutoCompleteApi
subsymbolic Jan 30, 2020
3271174
Initial interstitial screen
subsymbolic Jan 30, 2020
b4365ba
Add app list to view
subsymbolic Feb 3, 2020
45676b3
Tidy up device lookup and move off main thread
subsymbolic Feb 9, 2020
ea4578c
Use mini logo for better sizing
subsymbolic Feb 9, 2020
2214715
Merge branch 'develop' into feature/mia/interstitial_search
subsymbolic Feb 9, 2020
36b1d4b
Add scrolling
subsymbolic Feb 9, 2020
026a68e
Add view state reset and tweak app label text size
subsymbolic Feb 9, 2020
12b22bc
Remove colon from system search text as per design feedback
subsymbolic Feb 17, 2020
3be73e3
Update layout to show shadow at the bottom of autocomplete
subsymbolic Feb 17, 2020
b9b06de
Enable "no suggestions" and ensure it doesn't flash up on the screen
subsymbolic Feb 17, 2020
7a6cf08
Fix scrolling
subsymbolic Feb 20, 2020
e545232
Improve app lookup speed by reducing package manager lookups
subsymbolic Feb 20, 2020
bda60f6
Remove additional dev logging
subsymbolic Feb 20, 2020
b0ddd90
Tweak scrolling further
subsymbolic Feb 21, 2020
b235b09
Switch to word prefix matching
subsymbolic Feb 21, 2020
61fe705
Small tidy ups, remove dev logging, add explanatory comment and cance…
subsymbolic Feb 21, 2020
fa43e94
Make dax launch DuckDuckGo
subsymbolic Feb 21, 2020
6864a0e
Merge branch 'develop' into feature/mia/interstitial_search
subsymbolic Feb 21, 2020
95284bb
Add pixels
subsymbolic Feb 21, 2020
96d672f
Merge branch 'develop' into feature/mia/interstitial_search
subsymbolic Feb 21, 2020
005e188
Unit tests
subsymbolic Feb 24, 2020
cbea4ca
Merge branch 'develop' into feature/mia/interstitial_search
subsymbolic Feb 24, 2020
12451af
Rename variables and methods for clarity
subsymbolic Feb 26, 2020
c1343bd
Store app icon to avoid duplicate lookups and show message when app n…
subsymbolic Feb 26, 2020
4353881
Lint
subsymbolic Feb 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable "no suggestions" and ensure it doesn't flash up on the screen
  • Loading branch information
subsymbolic committed Feb 17, 2020
commit b9b06debb87dd365815ed63f4be46c03dbb256ce
Original file line number Diff line number Diff line change
Expand Up @@ -1157,8 +1157,7 @@ class BrowserTabFragment : Fragment(), FindListener, CoroutineScope {

if (viewState.showSuggestions) {
autoCompleteSuggestionsList.show()
val results = viewState.searchResults.suggestions
autoCompleteSuggestionsAdapter.updateData(results)
autoCompleteSuggestionsAdapter.updateData(viewState.searchResults.query, viewState.searchResults.suggestions)
} else {
autoCompleteSuggestionsList.gone()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ import com.duckduckgo.app.browser.autocomplete.BrowserAutoCompleteSuggestionsAda

class BrowserAutoCompleteSuggestionsAdapter(
private val immediateSearchClickListener: (AutoCompleteSuggestion) -> Unit,
private val editableSearchClickListener: (AutoCompleteSuggestion) -> Unit,
private val showsMessageOnNoSuggestions: Boolean = true
) : RecyclerView.Adapter<AutoCompleteViewHolder>() {
private val editableSearchClickListener: (AutoCompleteSuggestion) -> Unit
) : RecyclerView.Adapter<AutoCompleteViewHolder>() {

private val viewHolderFactoryMap: Map<Int, SuggestionViewHolderFactory> = mapOf(
EMPTY_TYPE to EmptySuggestionViewHolderFactory(),
SUGGESTION_TYPE to SearchSuggestionViewHolderFactory(),
BOOKMARK_TYPE to BookmarkSuggestionViewHolderFactory()
)
private val suggestions: MutableList<AutoCompleteSuggestion> = ArrayList()

private var phrase = ""
private var suggestions: List<AutoCompleteSuggestion> = emptyList()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AutoCompleteViewHolder =
viewHolderFactoryMap.getValue(viewType).onCreateViewHolder(parent)
Expand All @@ -64,18 +65,17 @@ class BrowserAutoCompleteSuggestionsAdapter(
}

override fun getItemCount(): Int {
if (suggestions.isNotEmpty()) {
return suggestions.size
if (suggestions.isEmpty() && phrase.isNotBlank()) {
subsymbolic marked this conversation as resolved.
Show resolved Hide resolved
return 1 // No suggestions message
}
return if (showsMessageOnNoSuggestions) 1 else 0
return suggestions.size
}

@UiThread
fun updateData(newSuggestions: List<AutoCompleteSuggestion>) {
if (suggestions == newSuggestions) return

suggestions.clear()
suggestions.addAll(newSuggestions)
fun updateData(newPhrase: String, newSuggestions: List<AutoCompleteSuggestion>) {
if (phrase == newPhrase && suggestions == newSuggestions) return
phrase = newPhrase
suggestions = newSuggestions
notifyDataSetChanged()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ class SystemSearchActivity : DuckDuckGoActivity() {
},
editableSearchClickListener = {
viewModel.userUpdatedQuery(it.phrase)
},
showsMessageOnNoSuggestions = false
}
)
autocompleteSuggestions.adapter = autocompleteSuggestionsAdapter
}
Expand Down Expand Up @@ -127,8 +126,8 @@ class SystemSearchActivity : DuckDuckGoActivity() {
omnibarTextInput.setText(viewState.queryText)
omnibarTextInput.setSelection(viewState.queryText.length)
}
autocompleteSuggestionsAdapter.updateData(viewState.autocompleteResults)
deviceLabel.isVisible = viewState.appResults.isNotEmpty()
autocompleteSuggestionsAdapter.updateData(viewState.autocompleteResults.query, viewState.autocompleteResults.suggestions)
deviceAppSuggestionsAdapter.updateData(viewState.appResults)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SystemSearchViewModel(

data class SystemSearchViewState(
val queryText: String = "",
val autocompleteResults: List<AutoCompleteApi.AutoCompleteSuggestion> = emptyList(),
val autocompleteResults: AutoCompleteApi.AutoCompleteResult = AutoCompleteApi.AutoCompleteResult("", emptyList()),
val appResults: List<DeviceApp> = emptyList()
)

Expand All @@ -52,7 +52,7 @@ class SystemSearchViewModel(

private val autoCompletePublishSubject = PublishRelay.create<String>()
private var appResults: List<DeviceApp> = emptyList()
private var autocompleteResults: List<AutoCompleteApi.AutoCompleteSuggestion> = emptyList()
private var autocompleteResults: AutoCompleteApi.AutoCompleteResult = AutoCompleteApi.AutoCompleteResult("", emptyList())

init {
resetState()
Expand All @@ -62,9 +62,9 @@ class SystemSearchViewModel(
private fun currentViewState(): SystemSearchViewState = viewState.value!!

fun resetState() {
autocompleteResults = emptyList()
appResults = emptyList()
viewState.value = SystemSearchViewState()
autocompleteResults = AutoCompleteApi.AutoCompleteResult("", emptyList())
appResults = emptyList()
}

private fun configureAutoComplete() {
Expand Down Expand Up @@ -105,15 +105,15 @@ class SystemSearchViewModel(
}

private fun updateAutocompleteResult(results: AutoCompleteApi.AutoCompleteResult) {
autocompleteResults = results.suggestions
autocompleteResults = results
refreshViewStateResults()
}

private fun refreshViewStateResults() {
val hasMultiResults = autocompleteResults.isNotEmpty() && appResults.isNotEmpty()
val newSuggestions = if (hasMultiResults) autocompleteResults.take(MULTI_RESULTS_MAX_PER_GROUP) else autocompleteResults
val hasMultiResults = autocompleteResults.suggestions.isNotEmpty() && appResults.isNotEmpty()
val newSuggestions = if (hasMultiResults) autocompleteResults.suggestions.take(MULTI_RESULTS_MAX_PER_GROUP) else autocompleteResults.suggestions
val newApps = if (hasMultiResults) appResults.take(MULTI_RESULTS_MAX_PER_GROUP) else appResults
viewState.postValue(currentViewState().copy(autocompleteResults = newSuggestions, appResults = newApps))
viewState.postValue(currentViewState().copy(autocompleteResults = AutoCompleteApi.AutoCompleteResult(autocompleteResults.query, newSuggestions), appResults = newApps))
}

fun userClearedQuery() {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_browser_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
android:backgroundTint="?attr/colorPrimary"
android:clipToPadding="false"
android:elevation="4dp"
android:paddingBottom="14dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginBottom="22dp"
android:layout_marginTop="8dp">

<TextView
Expand Down