From c214fb65ca5ff5569c46e4c36b50bf64289db0a6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Oct 2022 18:58:17 +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/java/io/legado/app/App.kt | 4 +- .../app/api/controller/BookController.kt | 6 +-- .../java/io/legado/app/data/entities/Book.kt | 4 +- .../legado/app/help/{webdav => }/AppWebDav.kt | 2 +- .../app/help/{ => book}/BookExtensions.kt | 0 .../io/legado/app/help/{ => book}/BookHelp.kt | 5 ++- .../legado/app/help/{ => book}/ContentHelp.kt | 4 +- .../app/help/{ => book}/ContentProcessor.kt | 2 +- .../java/io/legado/app/help/storage/Backup.kt | 2 +- .../java/io/legado/app/lib/webdav/WebDav.kt | 40 +++++++++++-------- .../java/io/legado/app/model/AudioPlay.kt | 2 +- .../java/io/legado/app/model/CacheBook.kt | 2 +- .../main/java/io/legado/app/model/ReadBook.kt | 6 +-- .../io/legado/app/model/localBook/EpubFile.kt | 2 +- .../legado/app/model/localBook/LocalBook.kt | 4 +- .../app/model/remote/RemoteBookManager.kt | 35 ++++++++++++++++ .../remote}/RemoteBookWebDav.kt | 31 +++++--------- .../app/model/webBook/BookChapterList.kt | 2 +- .../legado/app/model/webBook/BookContent.kt | 2 +- .../io/legado/app/model/webBook/BookInfo.kt | 2 +- .../io/legado/app/model/webBook/BookList.kt | 2 +- .../association/ImportBookSourceViewModel.kt | 2 +- .../legado/app/ui/book/cache/CacheActivity.kt | 2 +- .../app/ui/book/cache/CacheViewModel.kt | 6 +-- .../changesource/ChangeChapterSourceDialog.kt | 2 +- .../app/ui/book/info/BookInfoActivity.kt | 8 +--- .../app/ui/book/info/BookInfoViewModel.kt | 2 +- .../app/ui/book/read/ContentEditDialog.kt | 4 +- .../app/ui/book/read/ReadBookActivity.kt | 2 +- .../app/ui/book/read/ReadBookViewModel.kt | 6 +-- .../book/read/page/provider/ImageProvider.kt | 2 +- .../app/ui/book/remote/RemoteBookManager.kt | 18 --------- .../app/ui/book/remote/RemoteBookViewModel.kt | 4 +- .../searchContent/SearchContentActivity.kt | 2 +- .../searchContent/SearchContentViewModel.kt | 4 +- .../app/ui/book/toc/ChapterListAdapter.kt | 2 +- .../app/ui/book/toc/ChapterListFragment.kt | 2 +- .../app/ui/config/BackupConfigFragment.kt | 2 +- .../legado/app/ui/config/ConfigViewModel.kt | 4 +- .../io/legado/app/ui/main/MainActivity.kt | 4 +- .../io/legado/app/ui/main/MainViewModel.kt | 4 +- .../app/ui/replace/ReplaceRuleActivity.kt | 2 +- .../app/ui/widget/dialog/PhotoDialog.kt | 2 +- 43 files changed, 128 insertions(+), 117 deletions(-) rename app/src/main/java/io/legado/app/help/{webdav => }/AppWebDav.kt (99%) rename app/src/main/java/io/legado/app/help/{ => book}/BookExtensions.kt (100%) rename app/src/main/java/io/legado/app/help/{ => book}/BookHelp.kt (99%) rename app/src/main/java/io/legado/app/help/{ => book}/ContentHelp.kt (99%) rename app/src/main/java/io/legado/app/help/{ => book}/ContentProcessor.kt (99%) create mode 100644 app/src/main/java/io/legado/app/model/remote/RemoteBookManager.kt rename app/src/main/java/io/legado/app/{help/webdav => model/remote}/RemoteBookWebDav.kt (86%) delete mode 100644 app/src/main/java/io/legado/app/ui/book/remote/RemoteBookManager.kt diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index be638a4d1..0ffea5a41 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -16,15 +16,15 @@ import io.legado.app.constant.AppConst.channelIdReadAloud import io.legado.app.constant.AppConst.channelIdWeb import io.legado.app.constant.PreferKey import io.legado.app.data.appDb -import io.legado.app.help.BookHelp +import io.legado.app.help.AppWebDav import io.legado.app.help.CrashHandler import io.legado.app.help.LifecycleHelp import io.legado.app.help.RuleBigDataHelp +import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ThemeConfig.applyDayNight import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.http.cronet.CronetLoader -import io.legado.app.help.webdav.AppWebDav import io.legado.app.model.BookCover import io.legado.app.utils.defaultSharedPreferences import io.legado.app.utils.getPrefBoolean diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index eaad3cf35..e93a6c204 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -7,12 +7,12 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookProgress import io.legado.app.data.entities.BookSource -import io.legado.app.help.BookHelp +import io.legado.app.help.AppWebDav import io.legado.app.help.CacheManager -import io.legado.app.help.ContentProcessor +import io.legado.app.help.book.BookHelp +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.glide.ImageLoader import io.legado.app.help.isLocal -import io.legado.app.help.webdav.AppWebDav import io.legado.app.model.BookCover import io.legado.app.model.localBook.LocalBook import io.legado.app.model.webBook.WebBook diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 2d3e2229a..977363912 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -6,8 +6,8 @@ import io.legado.app.constant.AppPattern import io.legado.app.constant.BookType import io.legado.app.constant.PageAnim import io.legado.app.data.appDb -import io.legado.app.help.BookHelp -import io.legado.app.help.ContentProcessor +import io.legado.app.help.book.BookHelp +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.isEpub diff --git a/app/src/main/java/io/legado/app/help/webdav/AppWebDav.kt b/app/src/main/java/io/legado/app/help/AppWebDav.kt similarity index 99% rename from app/src/main/java/io/legado/app/help/webdav/AppWebDav.kt rename to app/src/main/java/io/legado/app/help/AppWebDav.kt index ed3736d7a..58a5e0464 100644 --- a/app/src/main/java/io/legado/app/help/webdav/AppWebDav.kt +++ b/app/src/main/java/io/legado/app/help/AppWebDav.kt @@ -1,4 +1,4 @@ -package io.legado.app.help.webdav +package io.legado.app.help import android.content.Context import io.legado.app.R diff --git a/app/src/main/java/io/legado/app/help/BookExtensions.kt b/app/src/main/java/io/legado/app/help/book/BookExtensions.kt similarity index 100% rename from app/src/main/java/io/legado/app/help/BookExtensions.kt rename to app/src/main/java/io/legado/app/help/book/BookExtensions.kt diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/book/BookHelp.kt similarity index 99% rename from app/src/main/java/io/legado/app/help/BookHelp.kt rename to app/src/main/java/io/legado/app/help/book/BookHelp.kt index bfa3ce3e8..31d8ff217 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/book/BookHelp.kt @@ -1,4 +1,4 @@ -package io.legado.app.help +package io.legado.app.help.book import android.net.Uri import androidx.documentfile.provider.DocumentFile @@ -9,6 +9,9 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource +import io.legado.app.help.isEpub +import io.legado.app.help.isLocal +import io.legado.app.help.isLocalTxt import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.* diff --git a/app/src/main/java/io/legado/app/help/ContentHelp.kt b/app/src/main/java/io/legado/app/help/book/ContentHelp.kt similarity index 99% rename from app/src/main/java/io/legado/app/help/ContentHelp.kt rename to app/src/main/java/io/legado/app/help/book/ContentHelp.kt index a2064fe3a..82aaaa3d3 100644 --- a/app/src/main/java/io/legado/app/help/ContentHelp.kt +++ b/app/src/main/java/io/legado/app/help/book/ContentHelp.kt @@ -1,4 +1,4 @@ -package io.legado.app.help +package io.legado.app.help.book import java.util.regex.Pattern import kotlin.math.max @@ -478,7 +478,7 @@ object ContentHelp { val patten = Pattern.compile( """ (?<=["'”“])([^ - \p{P}]{1,${WORD_MAX_LENGTH}})(?=["'”“]) + \p{P}]{1,$WORD_MAX_LENGTH})(?=["'”“]) """.trimIndent() ) //Pattern patten = Pattern.compile("(?<=[\"'”“])([^\n\"'”“]{1,16})(?=[\"'”“])"); diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/book/ContentProcessor.kt similarity index 99% rename from app/src/main/java/io/legado/app/help/ContentProcessor.kt rename to app/src/main/java/io/legado/app/help/book/ContentProcessor.kt index 92dbec3ad..d600aafd6 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/book/ContentProcessor.kt @@ -1,4 +1,4 @@ -package io.legado.app.help +package io.legado.app.help.book import com.github.liuyueyi.quick.transfer.ChineseUtils import io.legado.app.constant.AppLog 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 61d1d2e4c..10becc903 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 @@ -6,12 +6,12 @@ import androidx.documentfile.provider.DocumentFile import io.legado.app.constant.AppLog import io.legado.app.constant.PreferKey import io.legado.app.data.appDb +import io.legado.app.help.AppWebDav import io.legado.app.help.DirectLinkUpload import io.legado.app.help.config.LocalConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ThemeConfig import io.legado.app.help.coroutine.Coroutine -import io.legado.app.help.webdav.AppWebDav import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.ensureActive 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 1753cba60..cc8970d97 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 @@ -8,6 +8,8 @@ import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.text import io.legado.app.utils.NetworkUtils import io.legado.app.utils.printOnDebug +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.withContext import okhttp3.Interceptor import okhttp3.MediaType.Companion.toMediaType import okhttp3.RequestBody.Companion.asRequestBody @@ -274,16 +276,18 @@ open class WebDav(val path: String, val authorization: Authorization) { contentType: String = "application/octet-stream" ) { kotlin.runCatching { - val file = File(localPath) - if (!file.exists()) throw WebDavException("文件不存在") - // 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 - val fileBody = file.asRequestBody(contentType.toMediaType()) - val url = httpUrl ?: throw WebDavException("url不能为空") - webDavClient.newCallResponse { - url(url) - put(fileBody) - }.let { - checkResult(it) + withContext(IO) { + val file = File(localPath) + if (!file.exists()) throw WebDavException("文件不存在") + // 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 + val fileBody = file.asRequestBody(contentType.toMediaType()) + val url = httpUrl ?: throw WebDavException("url不能为空") + webDavClient.newCallResponse { + url(url) + put(fileBody) + }.let { + checkResult(it) + } } }.onFailure { AppLog.put("WebDav上传失败\n${it.localizedMessage}", it) @@ -295,13 +299,15 @@ open class WebDav(val path: String, val authorization: Authorization) { suspend fun upload(byteArray: ByteArray, contentType: String) { // 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 kotlin.runCatching { - val fileBody = byteArray.toRequestBody(contentType.toMediaType()) - val url = httpUrl ?: throw NoStackTraceException("url不能为空") - webDavClient.newCallResponse { - url(url) - put(fileBody) - }.let { - checkResult(it) + withContext(IO) { + val fileBody = byteArray.toRequestBody(contentType.toMediaType()) + val url = httpUrl ?: throw NoStackTraceException("url不能为空") + webDavClient.newCallResponse { + url(url) + put(fileBody) + }.let { + checkResult(it) + } } }.onFailure { AppLog.put("WebDav上传失败\n${it.localizedMessage}", it) diff --git a/app/src/main/java/io/legado/app/model/AudioPlay.kt b/app/src/main/java/io/legado/app/model/AudioPlay.kt index b5e7cd87b..991a69a92 100644 --- a/app/src/main/java/io/legado/app/model/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/model/AudioPlay.kt @@ -10,7 +10,7 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource -import io.legado.app.help.ContentProcessor +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.coroutine.Coroutine import io.legado.app.service.AudioPlayService import io.legado.app.utils.postEvent diff --git a/app/src/main/java/io/legado/app/model/CacheBook.kt b/app/src/main/java/io/legado/app/model/CacheBook.kt index f3ea48281..2bc7c5dee 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -9,7 +9,7 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource import io.legado.app.exception.ConcurrentException -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.help.isLocal import io.legado.app.model.webBook.WebBook import io.legado.app.service.CacheBookService diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 9a12ea663..ee8d629b9 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -3,13 +3,13 @@ package io.legado.app.model import io.legado.app.constant.AppLog import io.legado.app.data.appDb import io.legado.app.data.entities.* -import io.legado.app.help.BookHelp -import io.legado.app.help.ContentProcessor +import io.legado.app.help.AppWebDav +import io.legado.app.help.book.BookHelp +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.isLocal -import io.legado.app.help.webdav.AppWebDav import io.legado.app.model.webBook.WebBook import io.legado.app.service.BaseReadAloudService import io.legado.app.ui.book.read.page.entities.TextChapter diff --git a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt index b3bdf41f6..1fd9f669a 100644 --- a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt @@ -6,7 +6,7 @@ import android.text.TextUtils import io.legado.app.constant.AppLog import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.utils.* import me.ag2s.epublib.domain.EpubBook import me.ag2s.epublib.domain.Resource diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index ef56d24f0..a1053d710 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -14,11 +14,11 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.TocEmptyException -import io.legado.app.help.BookHelp +import io.legado.app.help.AppWebDav +import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.help.isEpub import io.legado.app.help.isUmd -import io.legado.app.help.webdav.AppWebDav import io.legado.app.lib.webdav.WebDav import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.* diff --git a/app/src/main/java/io/legado/app/model/remote/RemoteBookManager.kt b/app/src/main/java/io/legado/app/model/remote/RemoteBookManager.kt new file mode 100644 index 000000000..082958303 --- /dev/null +++ b/app/src/main/java/io/legado/app/model/remote/RemoteBookManager.kt @@ -0,0 +1,35 @@ +package io.legado.app.model.remote + +import android.net.Uri +import io.legado.app.data.entities.Book +import io.legado.app.data.entities.RemoteBook + +abstract class RemoteBookManager { + protected val remoteBookFolder: String = "books" + + abstract suspend fun initRemoteContext() + + /** + * 获取书籍列表 + */ + @Throws(Exception::class) + abstract suspend fun getRemoteBookList(path: String): MutableList + + /** + * 上传书籍 + */ + @Throws(Exception::class) + abstract suspend fun upload(book: Book) + + /** + * 删除书籍 + */ + @Throws(Exception::class) + abstract suspend fun delete(remoteBookUrl: String) + + /** + * @return Uri:下载到本地的路径 + */ + @Throws(Exception::class) + abstract suspend fun getRemoteBook(remoteBook: RemoteBook): Uri +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/webdav/RemoteBookWebDav.kt b/app/src/main/java/io/legado/app/model/remote/RemoteBookWebDav.kt similarity index 86% rename from app/src/main/java/io/legado/app/help/webdav/RemoteBookWebDav.kt rename to app/src/main/java/io/legado/app/model/remote/RemoteBookWebDav.kt index b20990d3e..a301d9fe4 100644 --- a/app/src/main/java/io/legado/app/help/webdav/RemoteBookWebDav.kt +++ b/app/src/main/java/io/legado/app/model/remote/RemoteBookWebDav.kt @@ -1,4 +1,4 @@ -package io.legado.app.help.webdav +package io.legado.app.model.remote import android.net.Uri import io.legado.app.constant.AppPattern.bookFileRegex @@ -6,10 +6,10 @@ import io.legado.app.constant.BookType import io.legado.app.data.entities.Book import io.legado.app.data.entities.RemoteBook import io.legado.app.exception.NoStackTraceException +import io.legado.app.help.AppWebDav import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.WebDavFile import io.legado.app.model.localBook.LocalBook -import io.legado.app.ui.book.remote.RemoteBookManager import io.legado.app.utils.NetworkUtils import io.legado.app.utils.isContentScheme import io.legado.app.utils.readBytes @@ -32,9 +32,6 @@ object RemoteBookWebDav : RemoteBookManager() { } } - /** - * 获取远程书籍列表 - */ @Throws(Exception::class) override suspend fun getRemoteBookList(path: String): MutableList { val remoteBooks = mutableListOf() @@ -70,23 +67,17 @@ object RemoteBookWebDav : RemoteBookManager() { return remoteBooks } - /** - * 下载指定的远程书籍到本地 - */ - override suspend fun getRemoteBook(remoteBook: RemoteBook): Uri? { + override suspend fun getRemoteBook(remoteBook: RemoteBook): Uri { return AppWebDav.authorization?.let { val webdav = WebDav(remoteBook.path, it) webdav.downloadInputStream().let { inputStream -> LocalBook.saveBookFile(inputStream, remoteBook.filename) } - } + } ?: throw NoStackTraceException("webDav没有配置") } - /** - * 上传本地导入的书籍到远程 - */ - override suspend fun upload(book: Book): Boolean { - if (!NetworkUtils.isAvailable()) return false + override suspend fun upload(book: Book) { + if (!NetworkUtils.isAvailable()) throw NoStackTraceException("网络不可用") val localBookUri = Uri.parse(book.bookUrl) val putUrl = "$rootBookUrl${File.separator}${book.originName}" AppWebDav.authorization?.let { @@ -98,17 +89,15 @@ object RemoteBookWebDav : RemoteBookManager() { } else { WebDav(putUrl, it).upload(localBookUri.path!!) } - } + } ?: throw NoStackTraceException("webDav没有配置") book.origin = BookType.webDavTag + putUrl book.save() - return true } - override suspend fun delete(remoteBookUrl: String): Boolean { + override suspend fun delete(remoteBookUrl: String) { AppWebDav.authorization?.let { - return WebDav(remoteBookUrl, it).delete() - } - return false + WebDav(remoteBookUrl, it).delete() + } ?: throw NoStackTraceException("webDav没有配置") } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 8a5570f0b..d3fd32693 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -8,7 +8,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.rule.TocRule import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.TocEmptyException -import io.legado.app.help.ContentProcessor +import io.legado.app.help.book.ContentProcessor import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index 561122964..fc1e85806 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -8,7 +8,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.rule.ContentRule import io.legado.app.exception.ContentEmptyException import io.legado.app.exception.NoStackTraceException -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl diff --git a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt index 63c5b3249..1052d6a18 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt @@ -6,7 +6,7 @@ import io.legado.app.constant.BookType import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.utils.DebugLog diff --git a/app/src/main/java/io/legado/app/model/webBook/BookList.kt b/app/src/main/java/io/legado/app/model/webBook/BookList.kt index 5bb5e8935..f5b03b716 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookList.kt @@ -6,7 +6,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.rule.BookListRule import io.legado.app.exception.NoStackTraceException -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.help.getBookType import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeRule diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt index be268cdef..be5341cfb 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt @@ -10,7 +10,7 @@ import io.legado.app.constant.AppPattern import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException -import io.legado.app.help.ContentProcessor +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.config.AppConfig import io.legado.app.help.http.newCallResponseBody import io.legado.app.help.http.okHttpClient diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index cc8be4b35..512c055b5 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -18,7 +18,7 @@ import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookGroup import io.legado.app.databinding.ActivityCacheBookBinding import io.legado.app.databinding.DialogEditTextBinding -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.help.isAudio import io.legado.app.lib.dialogs.SelectItem diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 54584361b..be3e45da9 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -18,11 +18,11 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.exception.NoStackTraceException -import io.legado.app.help.BookHelp -import io.legado.app.help.ContentProcessor +import io.legado.app.help.AppWebDav +import io.legado.app.help.book.BookHelp +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.config.AppConfig import io.legado.app.help.coroutine.OrderCoroutine -import io.legado.app.help.webdav.AppWebDav import io.legado.app.utils.* import kotlinx.coroutines.delay import kotlinx.coroutines.ensureActive diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt index 57421706c..a7eb3d830 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt @@ -21,7 +21,7 @@ import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.DialogChapterChangeSourceBinding -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.elevation diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 36bbe57ac..c6d06fec1 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -23,12 +23,12 @@ import io.legado.app.help.config.AppConfig import io.legado.app.help.isAudio import io.legado.app.help.isLocal import io.legado.app.help.isLocalTxt -import io.legado.app.help.webdav.RemoteBookWebDav import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.model.BookCover +import io.legado.app.model.remote.RemoteBookWebDav import io.legado.app.ui.about.AppLogDialog import io.legado.app.ui.association.ImportOnLineBookFileDialog import io.legado.app.ui.book.audio.AudioPlayActivity @@ -213,11 +213,7 @@ class BookInfoActivity : waitDialog.setText("上传中.....") waitDialog.show() try { - val isUpload = RemoteBookWebDav.upload(it) - if (isUpload) - toastOnUi(getString(R.string.upload_book_success)) - else - toastOnUi(getString(R.string.upload_book_fail)) + RemoteBookWebDav.upload(it) } catch (e: Exception) { toastOnUi(e.localizedMessage) } finally { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 1db43d131..dd59b3138 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -14,7 +14,7 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.isLocal import io.legado.app.model.BookCover diff --git a/app/src/main/java/io/legado/app/ui/book/read/ContentEditDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/ContentEditDialog.kt index b53afd002..60228e431 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ContentEditDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ContentEditDialog.kt @@ -12,8 +12,8 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.DialogContentEditBinding import io.legado.app.databinding.DialogEditTextBinding -import io.legado.app.help.BookHelp -import io.legado.app.help.ContentProcessor +import io.legado.app.help.book.BookHelp +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.isLocal import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.primaryColor diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index d4d971485..b785323f5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -23,12 +23,12 @@ import io.legado.app.data.entities.BookProgress import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException import io.legado.app.help.* +import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ReadTipConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.storage.Backup -import io.legado.app.help.webdav.AppWebDav import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.selector diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index b24373ef9..ca0a377ef 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -15,12 +15,12 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookProgress import io.legado.app.exception.NoStackTraceException -import io.legado.app.help.BookHelp -import io.legado.app.help.ContentProcessor +import io.legado.app.help.AppWebDav +import io.legado.app.help.book.BookHelp +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.config.AppConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.isLocal -import io.legado.app.help.webdav.AppWebDav import io.legado.app.model.ReadAloud import io.legado.app.model.ReadBook import io.legado.app.model.analyzeRule.AnalyzeRule diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt index 77faf44be..04f664808 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt @@ -10,7 +10,7 @@ import io.legado.app.constant.PageAnim import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.isEpub diff --git a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookManager.kt b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookManager.kt deleted file mode 100644 index 49b064ccb..000000000 --- a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookManager.kt +++ /dev/null @@ -1,18 +0,0 @@ -package io.legado.app.ui.book.remote - -import android.net.Uri -import io.legado.app.data.entities.Book -import io.legado.app.data.entities.RemoteBook - -abstract class RemoteBookManager { - protected val remoteBookFolder : String = "books" - abstract suspend fun initRemoteContext() - abstract suspend fun getRemoteBookList(path: String): MutableList - abstract suspend fun upload(book: Book): Boolean - abstract suspend fun delete(remoteBookUrl: String): Boolean - - /** - * @return String:下载到本地的路径 - */ - abstract suspend fun getRemoteBook(remoteBook: RemoteBook): Uri? -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt index 6ca80f408..a2d24c611 100644 --- a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt @@ -5,8 +5,8 @@ import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppLog import io.legado.app.constant.BookType import io.legado.app.data.entities.RemoteBook -import io.legado.app.help.webdav.RemoteBookWebDav import io.legado.app.model.localBook.LocalBook +import io.legado.app.model.remote.RemoteBookWebDav import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.awaitClose @@ -96,7 +96,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application) execute { remoteBooks.forEach { remoteBook -> val downloadBookPath = RemoteBookWebDav.getRemoteBook(remoteBook) - downloadBookPath?.let { + downloadBookPath.let { val localBook = LocalBook.importFile(it) localBook.origin = BookType.webDavTag + remoteBook.path localBook.save() diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt index 3eca24466..d41e67d3c 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt @@ -13,8 +13,8 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.ActivitySearchContentBinding -import io.legado.app.help.BookHelp import io.legado.app.help.IntentData +import io.legado.app.help.book.BookHelp import io.legado.app.help.isLocal import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt index f93f67714..a5f81518b 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt @@ -7,8 +7,8 @@ import io.legado.app.base.BaseViewModel import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter -import io.legado.app.help.BookHelp -import io.legado.app.help.ContentProcessor +import io.legado.app.help.book.BookHelp +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.config.AppConfig import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ensureActive diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt index 7b152e77c..af0877f92 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt @@ -9,7 +9,7 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.ItemChapterListBinding -import io.legado.app.help.ContentProcessor +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.config.AppConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.theme.ThemeUtils diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt index a2aed4c82..7ddf732e1 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt @@ -14,7 +14,7 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.FragmentChapterListBinding -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.help.isLocal import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index e6beed7d5..8c22a534d 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -18,6 +18,7 @@ import androidx.preference.Preference import io.legado.app.R import io.legado.app.constant.AppLog import io.legado.app.constant.PreferKey +import io.legado.app.help.AppWebDav import io.legado.app.help.config.AppConfig import io.legado.app.help.config.LocalConfig import io.legado.app.help.coroutine.Coroutine @@ -25,7 +26,6 @@ import io.legado.app.help.storage.Backup import io.legado.app.help.storage.BackupConfig import io.legado.app.help.storage.ImportOldData import io.legado.app.help.storage.Restore -import io.legado.app.help.webdav.AppWebDav import io.legado.app.lib.dialogs.alert import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.PermissionsCompat diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt b/app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt index f653744ea..a3d4316d3 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt @@ -3,8 +3,8 @@ package io.legado.app.ui.config import android.app.Application import io.legado.app.R import io.legado.app.base.BaseViewModel -import io.legado.app.help.BookHelp -import io.legado.app.help.webdav.AppWebDav +import io.legado.app.help.AppWebDav +import io.legado.app.help.book.BookHelp import io.legado.app.utils.FileUtils import io.legado.app.utils.toastOnUi 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 b2976bec9..b55a240b7 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 @@ -21,12 +21,12 @@ import io.legado.app.constant.AppConst.appInfo import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.databinding.ActivityMainBinding -import io.legado.app.help.BookHelp +import io.legado.app.help.AppWebDav +import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.help.config.LocalConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.storage.Backup -import io.legado.app.help.webdav.AppWebDav import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.elevation import io.legado.app.lib.theme.primaryColor diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 1c3c5568c..90ce7031e 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -9,12 +9,12 @@ import io.legado.app.constant.EventBus import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookSource -import io.legado.app.help.BookHelp +import io.legado.app.help.AppWebDav import io.legado.app.help.DefaultData +import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.help.config.LocalConfig import io.legado.app.help.isLocal -import io.legado.app.help.webdav.AppWebDav import io.legado.app.model.CacheBook import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.webBook.WebBook diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index de2cb4919..3c453ea15 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -19,8 +19,8 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.ReplaceRule import io.legado.app.databinding.ActivityReplaceRuleBinding import io.legado.app.databinding.DialogEditTextBinding -import io.legado.app.help.ContentProcessor import io.legado.app.help.DirectLinkUpload +import io.legado.app.help.book.ContentProcessor import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.primaryColor diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt index 434cc76f9..1b1632d79 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt @@ -7,7 +7,7 @@ import com.bumptech.glide.request.RequestOptions import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.databinding.DialogPhotoViewBinding -import io.legado.app.help.BookHelp +import io.legado.app.help.book.BookHelp import io.legado.app.help.glide.ImageLoader import io.legado.app.help.glide.OkHttpModelLoader import io.legado.app.model.BookCover