From fabb74990aed017dba389356b0611e69711124ab Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 1 May 2022 22:33:32 +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 --- app/src/main/assets/updateLog.md | 1 + app/src/main/java/io/legado/app/help/storage/Backup.kt | 2 +- app/src/main/java/io/legado/app/lib/webdav/WebDav.kt | 4 ++-- app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt | 2 +- app/src/main/java/io/legado/app/ui/main/MainActivity.kt | 6 ++---- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index dd17e50f6..e2dc50b4a 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -16,6 +16,7 @@ * 更新cronet: 101.0.4951.41 * 优化webDav备份,显示错误代码,自动备份错误不提示只记录错误日志, * 修复图片加载失败卡顿的问题 +* 打开应用时如果服务器备份比本地新,提示是否恢复 **2022/04/23** diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 6cfe2a562..4335c4beb 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -63,6 +63,7 @@ object Backup { } suspend fun backup(context: Context, path: String?, isAuto: Boolean = false) { + LocalConfig.lastBackup = System.currentTimeMillis() withContext(IO) { FileUtils.delete(backupPath) writeListToJson(appDb.bookDao.all, "bookshelf.json", backupPath) @@ -118,7 +119,6 @@ object Backup { } AppWebDav.backUpWebDav(backupPath) } - LocalConfig.lastBackup = System.currentTimeMillis() } private fun writeListToJson(list: List, fileName: String, path: String) { 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 1070af216..013247a8b 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 @@ -133,12 +133,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: Date? = kotlin.runCatching { element.getElementsByTag("d:getcontentlength") .firstOrNull()?.text()?.let { dateFormat.parse(it) } - }.getOrNull() ?: Date() + }.getOrNull() 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 4519e4055..d5c00852f 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 @@ -12,5 +12,5 @@ class WebDavFile( val urlName: String, val size: Long, val contentType: String, - val lastModify: Date + val lastModify: Date? ) : 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 8db950962..72ba2267c 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 @@ -96,10 +96,8 @@ class MainActivity : VMBaseActivity(), }, 3000) launch { val lastBackupFile = withContext(IO) { AppWebDav.lastBackUp().getOrNull() } - if (System.currentTimeMillis() - LocalConfig.lastBackup > DateUtils.MINUTE_IN_MILLIS - && lastBackupFile != null - ) { - + ?: return@launch + if (lastBackupFile.lastModify?.time ?: 0 - LocalConfig.lastBackup > DateUtils.MINUTE_IN_MILLIS) { alert("恢复", "webDav书源比本地新,是否恢复") { cancelButton() okButton {