aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/autofill
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-04-10 13:18:42 +0200
committerGitHub <noreply@github.com>2020-04-10 16:48:42 +0530
commit575ef8472654f49dd60f0e6909164dd8dbd098fb (patch)
treebd94860a1dcb4a8c630ff5954c262716ac307b7a /app/src/main/java/com/zeapo/pwdstore/autofill
parent2738d7500fa0d4d925f698a04045d930c27a2d59 (diff)
downloadHardenedPass-575ef8472654f49dd60f0e6909164dd8dbd098fb.tar.gz
HardenedPass-575ef8472654f49dd60f0e6909164dd8dbd098fb.zip
Modernize legacy RecyclerView adapters (#694)
* Modernize legacy RecyclerView adapters Introduces new adapters based on the SearchableRepositoryViewModel and using androidx.recyclerview.selection for multiselection support. The following positive effects in behavior are observable to end-users: - Search and navigation actions are executed on IO threads. - RecyclerViews are now animated during searches (but not navigations). - Exact scroll position is restored when navigating back. - The ActionBar title is updated with the current folder name. The following negative effects may warrant attention: - Support for the "always search from root" setting has been removed. - Due to a limitation of the fast scroll dependency, using the scroller may result in unwanted multiselections. If this is not fixed in the library, native fast scroller capabilities could be used, but these are more limited in appearance and to not offer popups. * Fix lint * Fix FastScroller/SelectionTracker incompatibility * Immediately react to settings changes * List directory entries when search term is blank * Use isEmpty() instead of == "" * Replace adapter inheritance with builders and fix selection drags * Remove dividers in password lists * Run spotlessApply * Use a more logical string in action mode * Commonize and constify path bundle key * Make lambda parameter name explicit Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt47
1 files changed, 21 insertions, 26 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt
index 2bfe0ad3..e1cbc496 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt
@@ -19,15 +19,15 @@ import androidx.core.text.bold
import androidx.core.text.buildSpannedString
import androidx.core.text.underline
import androidx.core.widget.addTextChangedListener
-import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
-import androidx.recyclerview.widget.DividerItemDecoration
+import androidx.lifecycle.observe
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.ajalt.timberkt.e
-import com.zeapo.pwdstore.DelegatedSearchableRepositoryAdapter
import com.zeapo.pwdstore.FilterMode
+import com.zeapo.pwdstore.ListMode
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.SearchMode
+import com.zeapo.pwdstore.SearchableRepositoryAdapter
import com.zeapo.pwdstore.SearchableRepositoryViewModel
import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher
import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences
@@ -35,11 +35,7 @@ import com.zeapo.pwdstore.autofill.oreo.DirectoryStructure
import com.zeapo.pwdstore.autofill.oreo.FormOrigin
import com.zeapo.pwdstore.utils.PasswordItem
import kotlinx.android.synthetic.main.activity_oreo_autofill_filter.*
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.FlowPreview
-@FlowPreview
-@ExperimentalCoroutinesApi
@TargetApi(Build.VERSION_CODES.O)
class AutofillFilterView : AppCompatActivity() {
@@ -116,10 +112,9 @@ class AutofillFilterView : AppCompatActivity() {
}
private fun bindUI() {
- val searchableAdapter = DelegatedSearchableRepositoryAdapter(
+ val recyclerAdapter = 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) ?: "INVALID"
@@ -129,12 +124,12 @@ class AutofillFilterView : AppCompatActivity() {
bold { underline { append(identifier) } }
}
subtitle.text = accountPart
- itemView.setOnClickListener { decryptAndFill(item) }
+ }.onItemClicked { _, item ->
+ decryptAndFill(item)
}
rvPassword.apply {
- adapter = searchableAdapter
+ adapter = recyclerAdapter
layoutManager = LinearLayoutManager(context)
- addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
}
val initialFilter = formOrigin.getPrettyIdentifier(applicationContext, untrusted = false)
@@ -145,26 +140,26 @@ class AutofillFilterView : AppCompatActivity() {
initialFilter,
filterMode = filterMode,
searchMode = SearchMode.RecursivelyInSubdirectories,
- listFilesOnly = true
+ listMode = ListMode.FilesOnly
)
search.addTextChangedListener {
model.search(
- it.toString(),
+ it.toString().trim(),
filterMode = FilterMode.Fuzzy,
searchMode = SearchMode.RecursivelyInSubdirectories,
- listFilesOnly = true
+ listMode = ListMode.FilesOnly
)
}
- model.passwordItemsList.observe(
- this,
- Observer { list ->
- searchableAdapter.submitList(list)
- // 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() && rvPasswordSwitcher.nextView.id == rvPasswordEmpty.id) ||
- (list.isNotEmpty() && rvPasswordSwitcher.nextView.id == rvPassword.id))
- rvPasswordSwitcher.showNext()
- })
+ model.searchResult.observe(this) { result ->
+ val list = result.passwordItems
+ recyclerAdapter.submitList(list)
+ // 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() && rvPasswordSwitcher.nextView.id == rvPasswordEmpty.id) ||
+ (list.isNotEmpty() && rvPasswordSwitcher.nextView.id == rvPassword.id)
+ )
+ rvPasswordSwitcher.showNext()
+ }
shouldMatch.text = getString(
R.string.oreo_autofill_match_with,