From 75a70543b3def38d3e89fce489c2c99c1bb45d5f Mon Sep 17 00:00:00 2001 From: Fabian Henneke Date: Tue, 14 Apr 2020 21:27:51 +0200 Subject: Improve search logic and UI (#703) * Don't list the current directory in search results * Scroll to top result when search term is changed * Match relative path in StrictDomain filter mode * Improve and document DirectoryStructure null handling Signed-off-by: Harsh Shandilya --- app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt') diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt index f5d9b3ab..e4551f1c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt @@ -124,10 +124,18 @@ class PasswordFragment : Fragment() { // and not on folder navigations since the latter leads to too many removal animations. (recyclerView.itemAnimator as OnOffItemAnimator).isEnabled = result.isFiltered recyclerAdapter.submitList(result.passwordItems) { - recyclerViewStateToRestore?.let { - recyclerView.layoutManager!!.onRestoreInstanceState(it) + if (result.isFiltered) { + // When the result is filtered, we always scroll to the top since that is where + // the best fuzzy match appears. + recyclerView.scrollToPosition(0) + } else { + // When the result is not filtered and there is a saved scroll position for it, + // we try to restore it. + recyclerViewStateToRestore?.let { + recyclerView.layoutManager!!.onRestoreInstanceState(it) + } + recyclerViewStateToRestore = null } - recyclerViewStateToRestore = null } } } -- cgit v1.2.3