pull/1835/head
kunfei 3 years ago
parent 8aaadee0ff
commit fabb74990a
  1. 1
      app/src/main/assets/updateLog.md
  2. 2
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  3. 4
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
  4. 2
      app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt
  5. 6
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -16,6 +16,7 @@
* 更新cronet: 101.0.4951.41 * 更新cronet: 101.0.4951.41
* 优化webDav备份,显示错误代码,自动备份错误不提示只记录错误日志, * 优化webDav备份,显示错误代码,自动备份错误不提示只记录错误日志,
* 修复图片加载失败卡顿的问题 * 修复图片加载失败卡顿的问题
* 打开应用时如果服务器备份比本地新,提示是否恢复
**2022/04/23** **2022/04/23**

@ -63,6 +63,7 @@ object Backup {
} }
suspend fun backup(context: Context, path: String?, isAuto: Boolean = false) { suspend fun backup(context: Context, path: String?, isAuto: Boolean = false) {
LocalConfig.lastBackup = System.currentTimeMillis()
withContext(IO) { withContext(IO) {
FileUtils.delete(backupPath) FileUtils.delete(backupPath)
writeListToJson(appDb.bookDao.all, "bookshelf.json", backupPath) writeListToJson(appDb.bookDao.all, "bookshelf.json", backupPath)
@ -118,7 +119,6 @@ object Backup {
} }
AppWebDav.backUpWebDav(backupPath) AppWebDav.backUpWebDav(backupPath)
} }
LocalConfig.lastBackup = System.currentTimeMillis()
} }
private fun writeListToJson(list: List<Any>, fileName: String, path: String) { private fun writeListToJson(list: List<Any>, fileName: String, path: String) {

@ -133,12 +133,12 @@ open class WebDav(urlStr: String, val authorization: Authorization) {
element.getElementsByTag("d:getcontentlength") element.getElementsByTag("d:getcontentlength")
.firstOrNull()?.text()?.toLong() ?: 0 .firstOrNull()?.text()?.toLong() ?: 0
}.getOrDefault(0) }.getOrDefault(0)
val lastModify: Date = kotlin.runCatching { val lastModify: Date? = kotlin.runCatching {
element.getElementsByTag("d:getcontentlength") element.getElementsByTag("d:getcontentlength")
.firstOrNull()?.text()?.let { .firstOrNull()?.text()?.let {
dateFormat.parse(it) dateFormat.parse(it)
} }
}.getOrNull() ?: Date() }.getOrNull()
webDavFile = WebDavFile( webDavFile = WebDavFile(
baseUrl + fileName, baseUrl + fileName,
authorization, authorization,

@ -12,5 +12,5 @@ class WebDavFile(
val urlName: String, val urlName: String,
val size: Long, val size: Long,
val contentType: String, val contentType: String,
val lastModify: Date val lastModify: Date?
) : WebDav(urlStr, authorization) ) : WebDav(urlStr, authorization)

@ -96,10 +96,8 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
}, 3000) }, 3000)
launch { launch {
val lastBackupFile = withContext(IO) { AppWebDav.lastBackUp().getOrNull() } val lastBackupFile = withContext(IO) { AppWebDav.lastBackUp().getOrNull() }
if (System.currentTimeMillis() - LocalConfig.lastBackup > DateUtils.MINUTE_IN_MILLIS ?: return@launch
&& lastBackupFile != null if (lastBackupFile.lastModify?.time ?: 0 - LocalConfig.lastBackup > DateUtils.MINUTE_IN_MILLIS) {
) {
alert("恢复", "webDav书源比本地新,是否恢复") { alert("恢复", "webDav书源比本地新,是否恢复") {
cancelButton() cancelButton()
okButton { okButton {

Loading…
Cancel
Save