This commit is contained in:
kunfei
2023-08-02 21:14:33 +08:00
parent 5d9c9e0537
commit c3bea1cb0f
5 changed files with 127 additions and 101 deletions
+6
View File
@@ -12,7 +12,13 @@
* 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
**2023/08/02**
* 书签导出md格式
* 优化进度同步,减少webDav下载次数
**2023/07/30**
* 更新cronet: 115.0.5790.138
* 更新cronet: 115.0.5790.136
@@ -159,7 +159,7 @@ object AppWebDav {
/**
* 获取云端所有背景名称
*/
suspend fun getAllBgNames(): Result<List<WebDavFile>> {
suspend fun getAllBgWebDavFiles(): Result<List<WebDavFile>> {
return kotlin.runCatching {
if (!NetworkUtils.isAvailable())
throw NoStackTraceException("网络未连接")
@@ -170,6 +170,21 @@ object AppWebDav {
}
}
/**
* 上传背景图片
*/
suspend fun upBgs(files: List<File>) {
val authorization = authorization ?: return
if (!NetworkUtils.isAvailable()) return
}
/**
* 下载背景图片
*/
suspend fun downBgs(fileNames: String) {
val authorization = authorization ?: return
if (!NetworkUtils.isAvailable()) return
}
suspend fun exportWebDav(byteArray: ByteArray, fileName: String) {
if (!NetworkUtils.isAvailable()) return
@@ -113,7 +113,9 @@ class Coroutine<T>(
return this@Coroutine
}
// 如果协程被取消,有可能会不执行
/**
* 如果协程被取消,不执行
*/
fun onFinally(
context: CoroutineContext? = null,
block: suspend CoroutineScope.() -> Unit
@@ -187,7 +189,9 @@ class Coroutine<T>(
private suspend inline fun dispatchVoidCallback(scope: CoroutineScope, callback: VoidCallback) {
if (null == callback.context) {
withContext(scope.coroutineContext) {
callback.block.invoke(scope)
}
} else {
withContext(scope.coroutineContext + callback.context) {
callback.block.invoke(this)
@@ -27,6 +27,7 @@ import java.io.FileOutputStream
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.coroutines.coroutineContext
/**
* 备份
@@ -92,7 +93,6 @@ object Backup {
suspend fun backup(context: Context, path: String?) {
LocalConfig.lastBackup = System.currentTimeMillis()
withContext(IO) {
val aes = BackupAES()
FileUtils.delete(backupPath)
writeListToJson(appDb.bookDao.all, "bookshelf.json", backupPath)
@@ -101,7 +101,6 @@ object Backup {
writeListToJson(appDb.bookSourceDao.all, "bookSource.json", backupPath)
writeListToJson(appDb.rssSourceDao.all, "rssSources.json", backupPath)
writeListToJson(appDb.rssStarDao.all, "rssStar.json", backupPath)
ensureActive()
writeListToJson(appDb.replaceRuleDao.all, "replaceRule.json", backupPath)
writeListToJson(appDb.readRecordDao.all, "readRecord.json", backupPath)
writeListToJson(appDb.searchKeywordDao.all, "searchHistory.json", backupPath)
@@ -118,7 +117,7 @@ object Backup {
.writeText(it)
}
}
ensureActive()
coroutineContext.ensureActive()
GSON.toJson(ReadBookConfig.configList).let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName)
.writeText(it)
@@ -135,7 +134,7 @@ object Backup {
FileUtils.createFileIfNotExist(backupPath + File.separator + DirectLinkUpload.ruleFileName)
.writeText(GSON.toJson(it))
}
ensureActive()
coroutineContext.ensureActive()
appCtx.getSharedPreferences(backupPath, "config")?.let { sp ->
val edit = sp.edit()
appCtx.defaultSharedPreferences.all.forEach { (key, value) ->
@@ -159,7 +158,7 @@ object Backup {
}
edit.commit()
}
ensureActive()
coroutineContext.ensureActive()
val zipFileName = getNowZipFileName()
val paths = arrayListOf(*backupFileNames)
for (i in 0 until paths.size) {
@@ -191,9 +190,10 @@ object Backup {
FileUtils.delete(backupPath)
FileUtils.delete(zipFilePath)
}
}
private fun writeListToJson(list: List<Any>, fileName: String, path: String) {
private suspend fun writeListToJson(list: List<Any>, fileName: String, path: String) {
coroutineContext.ensureActive()
withContext(IO) {
if (list.isNotEmpty()) {
val file = FileUtils.createFileIfNotExist(path + File.separator + fileName)
FileOutputStream(file).use { fos ->
@@ -203,6 +203,7 @@ object Backup {
}
}
}
}
@Throws(Exception::class)
@Suppress("SameParameterValue")
@@ -269,7 +269,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
viewModel.searchBookLiveData.observe(this) {
adapter.setItems(it)
}
lifecycleScope.launch(IO) {
lifecycleScope.launch {
appDb.bookSourceDao.flowEnabledGroups().collect {
groups = it
}