feat: 优化代码

pull/379/head
kunfei 5 years ago
parent 1b0dc675a9
commit 1fde270208
  1. 5
      app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt
  2. 14
      app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt

@ -10,8 +10,9 @@ import io.legado.app.utils.fromJsonArray
@Suppress("BlockingMethodInNonBlockingContext")
object SyncBookProgress {
private val file = FileUtils.createFileIfNotExist(App.INSTANCE.cacheDir, "bookProgress.json")
private val webDavUrl = "${WebDavHelp.rootWebDavUrl}bookProgress.json"
const val fileName = "bookProgress.json"
private val file = FileUtils.createFileIfNotExist(App.INSTANCE.cacheDir, fileName)
private val webDavUrl = "${WebDavHelp.rootWebDavUrl}$fileName"
fun uploadBookProgress() {
Coroutine.async {

@ -88,11 +88,15 @@ object WebDavHelp {
private fun restoreWebDav(name: String, success: () -> Unit) {
Coroutine.async {
rootWebDavUrl.let {
val webDav = WebDav(it + name)
webDav.downloadTo(zipFilePath, true)
@Suppress("BlockingMethodInNonBlockingContext")
ZipUtils.unzipFile(zipFilePath, Backup.backupPath)
Restore.restore(Backup.backupPath)
if (name == SyncBookProgress.fileName) {
SyncBookProgress.downloadBookProgress()
} else {
val webDav = WebDav(it + name)
webDav.downloadTo(zipFilePath, true)
@Suppress("BlockingMethodInNonBlockingContext")
ZipUtils.unzipFile(zipFilePath, Backup.backupPath)
Restore.restore(Backup.backupPath)
}
}
}.onSuccess {
success.invoke()

Loading…
Cancel
Save