优化
This commit is contained in:
@@ -16,12 +16,20 @@ import io.legado.app.lib.webdav.WebDav
|
|||||||
import io.legado.app.lib.webdav.WebDavException
|
import io.legado.app.lib.webdav.WebDavException
|
||||||
import io.legado.app.lib.webdav.WebDavFile
|
import io.legado.app.lib.webdav.WebDavFile
|
||||||
import io.legado.app.model.remote.RemoteBookWebDav
|
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.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 kotlinx.coroutines.runBlocking
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* webDav初始化会访问网络,不要放到主线程
|
* webDav初始化会访问网络,不要放到主线程
|
||||||
@@ -133,7 +141,7 @@ object AppWebDav {
|
|||||||
WebDav(rootWebDavUrl, it).listFiles().reversed().forEach { webDavFile ->
|
WebDav(rootWebDavUrl, it).listFiles().reversed().forEach { webDavFile ->
|
||||||
if (webDavFile.displayName.startsWith("backup")) {
|
if (webDavFile.displayName.startsWith("backup")) {
|
||||||
if (lastBackupFile == null
|
if (lastBackupFile == null
|
||||||
|| webDavFile.lastModify > lastBackupFile!!.lastModify
|
|| webDavFile.lastModify > lastBackupFile.lastModify
|
||||||
) {
|
) {
|
||||||
lastBackupFile = webDavFile
|
lastBackupFile = webDavFile
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import io.legado.app.constant.AppPattern.archiveFileRegex
|
|||||||
import io.legado.app.constant.AppPattern.bookFileRegex
|
import io.legado.app.constant.AppPattern.bookFileRegex
|
||||||
import io.legado.app.constant.PreferKey
|
import io.legado.app.constant.PreferKey
|
||||||
import io.legado.app.model.localBook.LocalBook
|
import io.legado.app.model.localBook.LocalBook
|
||||||
|
import io.legado.app.utils.AlphanumComparator
|
||||||
import io.legado.app.utils.FileDoc
|
import io.legado.app.utils.FileDoc
|
||||||
import io.legado.app.utils.getPrefInt
|
import io.legado.app.utils.getPrefInt
|
||||||
import io.legado.app.utils.isContentScheme
|
import io.legado.app.utils.isContentScheme
|
||||||
@@ -74,17 +75,12 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}.map { docList ->
|
}.map { docList ->
|
||||||
when (sort) {
|
val comparator = when (sort) {
|
||||||
2 -> docList.sortedWith(
|
2 -> compareBy<FileDoc>({ !it.isDir }, { -it.lastModified })
|
||||||
compareBy({ !it.isDir }, { -it.lastModified }, { it.name })
|
1 -> compareBy({ !it.isDir }, { -it.size })
|
||||||
)
|
else -> compareBy { !it.isDir }
|
||||||
1 -> docList.sortedWith(
|
} then compareBy(AlphanumComparator) { it.name }
|
||||||
compareBy({ !it.isDir }, { -it.size }, { it.name })
|
docList.sortedWith(comparator)
|
||||||
)
|
|
||||||
else -> docList.sortedWith(
|
|
||||||
compareBy({ !it.isDir }, { it.name })
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}.flowOn(IO)
|
}.flowOn(IO)
|
||||||
|
|
||||||
fun addToBookshelf(uriList: HashSet<String>, finally: () -> Unit) {
|
fun addToBookshelf(uriList: HashSet<String>, finally: () -> Unit) {
|
||||||
@@ -181,7 +177,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateCallBackFlow(filterKey: String?) {
|
fun updateCallBackFlow(filterKey: String?) {
|
||||||
dataCallback?.screen(filterKey)
|
dataCallback?.screen(filterKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DataCallback {
|
interface DataCallback {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import io.legado.app.model.analyzeRule.CustomUrl
|
|||||||
import io.legado.app.model.localBook.LocalBook
|
import io.legado.app.model.localBook.LocalBook
|
||||||
import io.legado.app.model.remote.RemoteBook
|
import io.legado.app.model.remote.RemoteBook
|
||||||
import io.legado.app.model.remote.RemoteBookWebDav
|
import io.legado.app.model.remote.RemoteBookWebDav
|
||||||
|
import io.legado.app.utils.AlphanumComparator
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
@@ -68,13 +69,15 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
}
|
}
|
||||||
}.map { list ->
|
}.map { list ->
|
||||||
if (sortAscending) when (sortKey) {
|
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 -> list.sortedWith(compareBy({ !it.isDir }, { it.lastModify }))
|
||||||
} else when (sortKey) {
|
} else when (sortKey) {
|
||||||
RemoteBookSort.Name -> list.sortedWith { o1, o2 ->
|
RemoteBookSort.Name -> list.sortedWith { o1, o2 ->
|
||||||
val compare = -compareValues(o1.isDir, o2.isDir)
|
val compare = -compareValues(o1.isDir, o2.isDir)
|
||||||
if (compare == 0) {
|
if (compare == 0) {
|
||||||
return@sortedWith -compareValues(o1.filename, o2.filename)
|
return@sortedWith -AlphanumComparator.compare(o1.filename, o2.filename)
|
||||||
}
|
}
|
||||||
return@sortedWith compare
|
return@sortedWith compare
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user