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 {