mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
ff70a68ee6
commit
2a6ca93ccd
@ -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
|
||||
@ -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() {
|
||||
@ -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)
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user