From 0524ef0c9103d49782e0bda4dcdbc994dd456f8f Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 4 Mar 2022 20:30:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=AF=BC=E5=85=A5=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/local/ImportBookActivity.kt | 42 ++++++++++++++++++- .../app/ui/book/local/ImportBookViewModel.kt | 2 + 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index c1ad5aa96..9616ee388 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -70,11 +70,30 @@ class ImportBookActivity : VMBaseActivity selectFolder.launch() R.id.menu_scan_folder -> scanFolder() R.id.menu_import_file_name -> alertImportFileName() + R.id.menu_sort_name -> { + viewModel.sort = 0 + upPath() + } + R.id.menu_sort_size -> { + viewModel.sort = 1 + upPath() + } + R.id.menu_sort_time -> { + viewModel.sort = 2 + upPath() + } } return super.onCompatOptionsItemSelected(item) } @@ -205,7 +224,28 @@ class ImportBookActivity : VMBaseActivity item.name.matches(bookFileRegex) } } - docList.sortWith(compareBy({ !it.isDir }, { it.name })) + when (viewModel.sort) { + 2 -> docList.sortWith( + compareBy( + { !it.isDir }, + { it.date }, + { it.name } + ) + ) + 1 -> docList.sortWith( + compareBy( + { !it.isDir }, + { it.size }, + { it.name } + ) + ) + else -> docList.sortWith( + compareBy( + { !it.isDir }, + { it.name } + ) + ) + } withContext(Main) { adapter.setItems(docList) } diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt index 392f260f8..d8e193112 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt @@ -14,6 +14,8 @@ import java.io.File class ImportBookViewModel(application: Application) : BaseViewModel(application) { + var sort = 0 + fun addToBookshelf(uriList: HashSet, finally: () -> Unit) { execute { uriList.forEach {