From 8885ac4a835f41ada625572b90a3bfbafa41d4e5 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Tue, 31 Dec 2024 13:30:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/AppWebDav.kt | 14 ++++++++++--- .../book/import/local/ImportBookViewModel.kt | 20 ++++++++----------- .../book/import/remote/RemoteBookViewModel.kt | 7 +++++-- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/AppWebDav.kt b/app/src/main/java/io/legado/app/help/AppWebDav.kt index 5f02c69e4..748baf9c6 100644 --- a/app/src/main/java/io/legado/app/help/AppWebDav.kt +++ b/app/src/main/java/io/legado/app/help/AppWebDav.kt @@ -16,12 +16,20 @@ import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.WebDavException import io.legado.app.lib.webdav.WebDavFile import io.legado.app.model.remote.RemoteBookWebDav -import io.legado.app.utils.* +import io.legado.app.utils.AlphanumComparator +import io.legado.app.utils.FileUtils +import io.legado.app.utils.GSON +import io.legado.app.utils.NetworkUtils +import io.legado.app.utils.UrlUtil import io.legado.app.utils.compress.ZipUtils +import io.legado.app.utils.fromJsonObject +import io.legado.app.utils.getPrefString +import io.legado.app.utils.isJson +import io.legado.app.utils.removePref +import io.legado.app.utils.toastOnUi import kotlinx.coroutines.runBlocking import splitties.init.appCtx import java.io.File -import java.util.* /** * webDav初始化会访问网络,不要放到主线程 @@ -133,7 +141,7 @@ object AppWebDav { WebDav(rootWebDavUrl, it).listFiles().reversed().forEach { webDavFile -> if (webDavFile.displayName.startsWith("backup")) { if (lastBackupFile == null - || webDavFile.lastModify > lastBackupFile!!.lastModify + || webDavFile.lastModify > lastBackupFile.lastModify ) { lastBackupFile = webDavFile } diff --git a/app/src/main/java/io/legado/app/ui/book/import/local/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/import/local/ImportBookViewModel.kt index ef3977f03..fe9faa0cf 100644 --- a/app/src/main/java/io/legado/app/ui/book/import/local/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/import/local/ImportBookViewModel.kt @@ -9,6 +9,7 @@ import io.legado.app.constant.AppPattern.archiveFileRegex import io.legado.app.constant.AppPattern.bookFileRegex import io.legado.app.constant.PreferKey import io.legado.app.model.localBook.LocalBook +import io.legado.app.utils.AlphanumComparator import io.legado.app.utils.FileDoc import io.legado.app.utils.getPrefInt import io.legado.app.utils.isContentScheme @@ -74,17 +75,12 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application) } }.map { docList -> - when (sort) { - 2 -> docList.sortedWith( - compareBy({ !it.isDir }, { -it.lastModified }, { it.name }) - ) - 1 -> docList.sortedWith( - compareBy({ !it.isDir }, { -it.size }, { it.name }) - ) - else -> docList.sortedWith( - compareBy({ !it.isDir }, { it.name }) - ) - } + val comparator = when (sort) { + 2 -> compareBy({ !it.isDir }, { -it.lastModified }) + 1 -> compareBy({ !it.isDir }, { -it.size }) + else -> compareBy { !it.isDir } + } then compareBy(AlphanumComparator) { it.name } + docList.sortedWith(comparator) }.flowOn(IO) fun addToBookshelf(uriList: HashSet, finally: () -> Unit) { @@ -181,7 +177,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application) } fun updateCallBackFlow(filterKey: String?) { - dataCallback?.screen(filterKey) + dataCallback?.screen(filterKey) } interface DataCallback { diff --git a/app/src/main/java/io/legado/app/ui/book/import/remote/RemoteBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/import/remote/RemoteBookViewModel.kt index 2c3ae1020..51be1e278 100644 --- a/app/src/main/java/io/legado/app/ui/book/import/remote/RemoteBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/import/remote/RemoteBookViewModel.kt @@ -14,6 +14,7 @@ import io.legado.app.model.analyzeRule.CustomUrl import io.legado.app.model.localBook.LocalBook import io.legado.app.model.remote.RemoteBook import io.legado.app.model.remote.RemoteBookWebDav +import io.legado.app.utils.AlphanumComparator import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.awaitClose @@ -68,13 +69,15 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application) } }.map { list -> if (sortAscending) when (sortKey) { - RemoteBookSort.Name -> list.sortedWith(compareBy({ !it.isDir }, { it.filename })) + RemoteBookSort.Name -> list.sortedWith(compareBy { !it.isDir } + then compareBy(AlphanumComparator) { it.filename }) + else -> list.sortedWith(compareBy({ !it.isDir }, { it.lastModify })) } else when (sortKey) { RemoteBookSort.Name -> list.sortedWith { o1, o2 -> val compare = -compareValues(o1.isDir, o2.isDir) if (compare == 0) { - return@sortedWith -compareValues(o1.filename, o2.filename) + return@sortedWith -AlphanumComparator.compare(o1.filename, o2.filename) } return@sortedWith compare }