Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Sep 19, 2023
1 parent ff70a68 commit 2a6ca93
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/src/main/java/io/legado/app/ui/file/FileManageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.PopupMenu
import androidx.activity.addCallback
import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView
import androidx.core.content.FileProvider
Expand Down Expand Up @@ -55,6 +56,13 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.addItemDecoration(VerticalDivider(this))
binding.recyclerView.adapter = fileAdapter
onBackPressedDispatcher.addCallback(this) {
if (viewModel.lastDir != viewModel.rootDoc) {
gotoLastDir()
return@addCallback
}
finish()
}
}

private fun initSearchView() {
Expand Down Expand Up @@ -87,6 +95,12 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
}
}

private fun gotoLastDir() {
viewModel.subDocs.removeLastOrNull()
pathAdapter.setItems(viewModel.subDocs)
viewModel.upFiles(viewModel.lastDir)
}

override fun observeLiveBus() {
viewModel.filesLiveData.observe(this) {
searchView.setQuery("", false)
Expand Down Expand Up @@ -155,9 +169,7 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
val item = getItemByLayoutPosition(holder.layoutPosition)
item?.let {
if (item == viewModel.lastDir) {
viewModel.subDocs.removeLastOrNull()
pathAdapter.setItems(viewModel.subDocs)
viewModel.upFiles(viewModel.subDocs.lastOrNull() ?: viewModel.rootDoc)
gotoLastDir()
} else if (item.isDirectory) {
viewModel.subDocs.add(item)
pathAdapter.setItems(viewModel.subDocs)
Expand Down

0 comments on commit 2a6ca93

Please sign in to comment.