This commit is contained in:
Horis 2024-12-31 13:30:15 +08:00
parent 3dec19f0ee
commit 8885ac4a83
3 changed files with 24 additions and 17 deletions

View File

@ -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
}

View File

@ -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<FileDoc>({ !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<String>, finally: () -> Unit) {
@ -181,7 +177,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
}
fun updateCallBackFlow(filterKey: String?) {
dataCallback?.screen(filterKey)
dataCallback?.screen(filterKey)
}
interface DataCallback {

View File

@ -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<RemoteBook> { !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
}