diff --git a/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt b/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt index 0b084639e..e219ee59c 100644 --- a/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt +++ b/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt @@ -142,7 +142,7 @@ object AppWebDav { return kotlin.runCatching { authorization?.let { var lastBackupFile: WebDavFile? = null - WebDav(rootWebDavUrl, it).listFiles().forEach { webDavFile -> + WebDav(rootWebDavUrl, it).listFiles().reversed().forEach { webDavFile -> if (webDavFile.displayName.startsWith("backup")) { if (lastBackupFile == null || webDavFile.lastModify > lastBackupFile!!.lastModify diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index 013247a8b..d27e731de 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -20,7 +20,6 @@ import java.net.MalformedURLException import java.net.URL import java.net.URLEncoder import java.text.SimpleDateFormat -import java.util.* @Suppress("unused", "MemberVisibilityCanBePrivate") open class WebDav(urlStr: String, val authorization: Authorization) { @@ -133,12 +132,12 @@ open class WebDav(urlStr: String, val authorization: Authorization) { element.getElementsByTag("d:getcontentlength") .firstOrNull()?.text()?.toLong() ?: 0 }.getOrDefault(0) - val lastModify: Date? = kotlin.runCatching { + val lastModify: Long = kotlin.runCatching { element.getElementsByTag("d:getcontentlength") .firstOrNull()?.text()?.let { dateFormat.parse(it) } - }.getOrNull() + }.getOrNull()?.time ?: 0 webDavFile = WebDavFile( baseUrl + fileName, authorization, diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt index d5c00852f..b0ad187b7 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt @@ -1,10 +1,9 @@ package io.legado.app.lib.webdav -import java.util.* - /** * webDavFile */ +@Suppress("unused") class WebDavFile( urlStr: String, authorization: Authorization, @@ -12,5 +11,5 @@ class WebDavFile( val urlName: String, val size: Long, val contentType: String, - val lastModify: Date? + val lastModify: Long ) : WebDav(urlStr, authorization) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 72ba2267c..fae0b97bf 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -97,7 +97,7 @@ class MainActivity : VMBaseActivity(), launch { val lastBackupFile = withContext(IO) { AppWebDav.lastBackUp().getOrNull() } ?: return@launch - if (lastBackupFile.lastModify?.time ?: 0 - LocalConfig.lastBackup > DateUtils.MINUTE_IN_MILLIS) { + if (lastBackupFile.lastModify - LocalConfig.lastBackup > DateUtils.MINUTE_IN_MILLIS) { alert("恢复", "webDav书源比本地新,是否恢复") { cancelButton() okButton {