|
|
@ -2,39 +2,45 @@ package io.legado.app.help.storage |
|
|
|
|
|
|
|
|
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.data.entities.BookProgress |
|
|
|
import io.legado.app.data.entities.BookProgress |
|
|
|
|
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
import io.legado.app.lib.webdav.WebDav |
|
|
|
import io.legado.app.lib.webdav.WebDav |
|
|
|
import io.legado.app.utils.FileUtils |
|
|
|
import io.legado.app.utils.FileUtils |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.fromJsonArray |
|
|
|
import io.legado.app.utils.fromJsonArray |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Suppress("BlockingMethodInNonBlockingContext") |
|
|
|
object SyncBookProgress { |
|
|
|
object SyncBookProgress { |
|
|
|
private val file = FileUtils.createFileIfNotExist(App.INSTANCE.cacheDir, "bookProgress.json") |
|
|
|
private val file = FileUtils.createFileIfNotExist(App.INSTANCE.cacheDir, "bookProgress.json") |
|
|
|
private val webDavUrl = WebDavHelp.getWebDavUrl() + "legado/bookProgress.json" |
|
|
|
private val webDavUrl = WebDavHelp.getWebDavUrl() + "legado/bookProgress.json" |
|
|
|
|
|
|
|
|
|
|
|
fun uploadBookProgress() { |
|
|
|
fun uploadBookProgress() { |
|
|
|
val value = App.db.bookDao().allBookProgress |
|
|
|
Coroutine.async { |
|
|
|
if (value.isNotEmpty()) { |
|
|
|
val value = App.db.bookDao().allBookProgress |
|
|
|
val json = GSON.toJson(value) |
|
|
|
if (value.isNotEmpty()) { |
|
|
|
file.writeText(json) |
|
|
|
val json = GSON.toJson(value) |
|
|
|
if (WebDavHelp.initWebDav()) { |
|
|
|
file.writeText(json) |
|
|
|
WebDav(WebDavHelp.getWebDavUrl() + "legado").makeAsDir() |
|
|
|
if (WebDavHelp.initWebDav()) { |
|
|
|
WebDav(webDavUrl).upload(file.absolutePath) |
|
|
|
WebDav(WebDavHelp.getWebDavUrl() + "legado").makeAsDir() |
|
|
|
|
|
|
|
WebDav(webDavUrl).upload(file.absolutePath) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun downloadBookProgress() { |
|
|
|
fun downloadBookProgress() { |
|
|
|
WebDav(webDavUrl).downloadTo(file.absolutePath, true) |
|
|
|
Coroutine.async { |
|
|
|
if (file.exists()) { |
|
|
|
WebDav(webDavUrl).downloadTo(file.absolutePath, true) |
|
|
|
val json = file.readText() |
|
|
|
if (file.exists()) { |
|
|
|
GSON.fromJsonArray<BookProgress>(json)?.forEach { |
|
|
|
val json = file.readText() |
|
|
|
App.db.bookDao().upBookProgress( |
|
|
|
GSON.fromJsonArray<BookProgress>(json)?.forEach { |
|
|
|
it.bookUrl, |
|
|
|
App.db.bookDao().upBookProgress( |
|
|
|
it.durChapterIndex, |
|
|
|
it.bookUrl, |
|
|
|
it.durChapterPos, |
|
|
|
it.durChapterIndex, |
|
|
|
it.durChapterTime |
|
|
|
it.durChapterPos, |
|
|
|
) |
|
|
|
it.durChapterTime |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|