Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Mar 31, 2023
1 parent 6c26d38 commit adfab44
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions app/src/main/java/io/legado/app/ui/document/FileManageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV

override val binding by viewBinding(ActivityFileManageBinding::inflate)
override val viewModel by viewModels<FileManageViewModel>()
private val dirParent = ".."
private val searchView: SearchView by lazy {
binding.titleBar.findViewById(R.id.search_view)
}
Expand All @@ -38,6 +39,7 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
private val fileAdapter by lazy {
FileAdapter()
}
private val currentFiles = arrayListOf<File>()

override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
Expand Down Expand Up @@ -65,15 +67,30 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
}

override fun onQueryTextChange(newText: String?): Boolean {

updateFiles()
return false
}
})
}

private fun updateFiles() {
if (searchView.query.isNotEmpty()) {
currentFiles.filter {
it.name == dirParent || it.name.contains(searchView.query)
}.let {
fileAdapter.setItems(it)
}
} else {
fileAdapter.setItems(currentFiles)
}
}

override fun observeLiveBus() {
viewModel.filesLiveData.observe(this) {
fileAdapter.setItems(it)
searchView.setQuery("", false)
currentFiles.clear()
currentFiles.addAll(it)
updateFiles()
}
}

Expand Down Expand Up @@ -126,7 +143,6 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
private val upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUpDir())!!
private val folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFolder())!!
private val fileIcon = ConvertUtils.toDrawable(FilePickerIcon.getFile())!!
private val dirParent = ".."

override fun getViewBinding(parent: ViewGroup): ItemFileBinding {
return ItemFileBinding.inflate(inflater, parent, false)
Expand Down

0 comments on commit adfab44

Please sign in to comment.