Add a switch between Fuzzy and StrictDomain mode to Autofill search view

This commit is contained in:
Fabian Henneke
2020-04-15 17:22:44 +02:00
committed by Harsh Shandilya
parent 441b4d3b68
commit 7cd6f1d1cf
3 changed files with 80 additions and 60 deletions

View File

@@ -111,13 +111,17 @@ class AutofillFilterView : AppCompatActivity() {
supportActionBar?.hide()
bindUI()
updateSearch()
setResult(RESULT_CANCELED)
}
private fun bindUI() {
val recyclerAdapter = SearchableRepositoryAdapter(
with(binding) {
rvPassword.apply {
adapter = SearchableRepositoryAdapter(
R.layout.oreo_autofill_filter_row,
::PasswordViewHolder) { item ->
::PasswordViewHolder
) { item ->
val file = item.file.relativeTo(item.rootDir)
val pathToIdentifier = directoryStructure.getPathToIdentifierFor(file)
val identifier = directoryStructure.getIdentifierFor(file)
@@ -143,45 +147,45 @@ class AutofillFilterView : AppCompatActivity() {
}.onItemClicked { _, item ->
decryptAndFill(item)
}
binding.rvPassword.apply {
adapter = recyclerAdapter
layoutManager = LinearLayoutManager(context)
}
val initialFilter = formOrigin.getPrettyIdentifier(applicationContext, untrusted = false)
binding.search.setText(initialFilter, TextView.BufferType.EDITABLE)
val filterMode =
if (formOrigin is FormOrigin.Web) FilterMode.StrictDomain else FilterMode.Fuzzy
model.search(
initialFilter,
filterMode = filterMode,
searchMode = SearchMode.RecursivelyInSubdirectories,
listMode = ListMode.FilesOnly
)
binding.search.addTextChangedListener {
model.search(
it.toString().trim(),
filterMode = FilterMode.Fuzzy,
searchMode = SearchMode.RecursivelyInSubdirectories,
listMode = ListMode.FilesOnly
)
search.apply {
val initialSearch =
formOrigin.getPrettyIdentifier(applicationContext, untrusted = false)
setText(initialSearch, TextView.BufferType.EDITABLE)
addTextChangedListener { updateSearch() }
}
model.searchResult.observe(this) { result ->
strictDomainSearch.apply {
visibility = if (formOrigin is FormOrigin.Web) View.VISIBLE else View.GONE
isChecked = formOrigin is FormOrigin.Web
setOnCheckedChangeListener { _, _ -> updateSearch() }
}
shouldMatch.text = getString(
R.string.oreo_autofill_match_with,
formOrigin.getPrettyIdentifier(applicationContext)
)
model.searchResult.observe(this@AutofillFilterView) { result ->
val list = result.passwordItems
recyclerAdapter.submitList(list) {
binding.rvPassword.scrollToPosition(0)
(rvPassword.adapter as SearchableRepositoryAdapter).submitList(list) {
rvPassword.scrollToPosition(0)
}
// Switch RecyclerView out for a "no results" message if the new list is empty and
// the message is not yet shown (and vice versa).
if ((list.isEmpty() && binding.rvPasswordSwitcher.nextView.id == binding.rvPasswordEmpty.id) ||
(list.isNotEmpty() && binding.rvPasswordSwitcher.nextView.id == binding.rvPassword.id)
)
binding.rvPasswordSwitcher.showNext()
if ((list.isEmpty() && rvPasswordSwitcher.nextView.id == rvPasswordEmpty.id) ||
(list.isNotEmpty() && rvPasswordSwitcher.nextView.id == rvPassword.id)
) {
rvPasswordSwitcher.showNext()
}
}
}
}
binding.shouldMatch.text = getString(
R.string.oreo_autofill_match_with,
formOrigin.getPrettyIdentifier(applicationContext)
private fun updateSearch() {
model.search(
binding.search.text.toString().trim(),
filterMode = if (binding.strictDomainSearch.isChecked) FilterMode.StrictDomain else FilterMode.Fuzzy,
searchMode = SearchMode.RecursivelyInSubdirectories,
listMode = ListMode.FilesOnly
)
}

View File

@@ -46,7 +46,7 @@
android:id="@+id/rvPasswordSwitcher"
android:layout_width="0dp"
android:layout_marginTop="@dimen/activity_vertical_margin"
app:layout_constraintBottom_toTopOf="@id/shouldMatch"
app:layout_constraintBottom_toTopOf="@id/strictDomainSearch"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/searchLayout"
@@ -71,6 +71,21 @@
</ViewSwitcher>
<Switch
android:id="@+id/strictDomainSearch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:text="@string/oreo_autofill_strict_domain_search"
app:layout_constraintBottom_toTopOf="@id/shouldMatch"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rvPasswordSwitcher"
app:layout_constraintVertical_bias="1.0"
tools:text="Phishing-resistant search"/>
<Switch
android:id="@+id/shouldMatch"
android:layout_width="0dp"
@@ -82,7 +97,7 @@
app:layout_constraintBottom_toTopOf="@id/shouldClear"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rvPasswordSwitcher"
app:layout_constraintTop_toBottomOf="@id/strictDomainSearch"
app:layout_constraintVertical_bias="1.0"
tools:text="Match with example.org" />

View File

@@ -250,6 +250,7 @@
<string name="folder_icon_hint">Folder icon</string>
<!-- Oreo Autofill -->
<string name="oreo_autofill_strict_domain_search">Phishing-resistant search</string>
<string name="oreo_autofill_match_with">Match with %1$s</string>
<string name="oreo_autofill_matches_clear_existing">Clear existing matches</string>
<string name="oreo_autofill_filter_no_results">No results.</string>