diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index c7560b819..97c71f04c 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -237,13 +237,7 @@ object BookHelp { private var bookName: String? = null private var bookOrigin: String? = null private var replaceRules: List = arrayListOf() - var bodyIndentCount = App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2) - set(value) { - field = value - App.INSTANCE.putPrefInt(PreferKey.bodyIndent, value) - bodyIndent = " ".repeat(value) - } - var bodyIndent = " ".repeat(bodyIndentCount) + fun disposeContent( @@ -281,6 +275,6 @@ object BookHelp { 1 -> c = ZhConvertBootstrap.newInstance().toSimple(c) 2 -> c = ZhConvertBootstrap.newInstance().toTraditional(c) } - return c.replace("\\s*\\n+\\s*".toRegex(), "\n$bodyIndent") + return c.replace("\\s*\\n+\\s*".toRegex(), "\n${ReadBookConfig.bodyIndent}") } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 0160000f7..32da4bb06 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -17,7 +17,7 @@ interface JsExtensions { fun ajax(urlStr: String): String? { return try { val analyzeUrl = AnalyzeUrl(urlStr, null, null, null, null, null) - val call = analyzeUrl.getResponse() + val call = analyzeUrl.getResponse(urlStr) val response = call.execute() response.body() } catch (e: Exception) { diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 229d5d7e6..a3a6de521 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -26,24 +26,6 @@ object ReadBookConfig { } val durConfig get() = getConfig(styleSelect) private val shareConfig get() = getConfig(5) - var styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) - set(value) { - field = value - App.INSTANCE.putPrefInt(PreferKey.readStyleSelect, value) - } - var shareLayout = App.INSTANCE.getPrefBoolean(PreferKey.shareLayout) - set(value) { - field = value - App.INSTANCE.putPrefBoolean(PreferKey.shareLayout, value) - } - var pageAnim = App.INSTANCE.getPrefInt(PreferKey.pageAnim) - set(value) { - field = value - isScroll = value == 3 - App.INSTANCE.putPrefInt(PreferKey.pageAnim, value) - } - var isScroll = pageAnim == 3 - val clickTurnPage get() = App.INSTANCE.getPrefBoolean(PreferKey.clickTurnPage, true) var bg: Drawable? = null init { @@ -113,6 +95,39 @@ object ReadBookConfig { } //配置写入读取 + var styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) + set(value) { + field = value + if (App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) != value) { + App.INSTANCE.putPrefInt(PreferKey.readStyleSelect, value) + } + } + var shareLayout = App.INSTANCE.getPrefBoolean(PreferKey.shareLayout) + set(value) { + field = value + if (App.INSTANCE.getPrefBoolean(PreferKey.shareLayout) != value) { + App.INSTANCE.putPrefBoolean(PreferKey.shareLayout, value) + } + } + var pageAnim = App.INSTANCE.getPrefInt(PreferKey.pageAnim) + set(value) { + field = value + isScroll = value == 3 + if (App.INSTANCE.getPrefInt(PreferKey.pageAnim) != value) { + App.INSTANCE.putPrefInt(PreferKey.pageAnim, value) + } + } + var isScroll = pageAnim == 3 + val clickTurnPage get() = App.INSTANCE.getPrefBoolean(PreferKey.clickTurnPage, true) + var bodyIndentCount = App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2) + set(value) { + field = value + bodyIndent = " ".repeat(value) + if (App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2) != value) { + App.INSTANCE.putPrefInt(PreferKey.bodyIndent, value) + } + } + var bodyIndent = " ".repeat(bodyIndentCount) var hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) var hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) var textBold: Boolean diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index dd48d6472..d9be6e9bd 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -114,6 +114,7 @@ object Restore { pageAnim = App.INSTANCE.getPrefInt(PreferKey.pageAnim) hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) + bodyIndentCount = App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2) } ChapterProvider.upStyle() ReadBook.loadContent() diff --git a/app/src/main/java/io/legado/app/model/Rss.kt b/app/src/main/java/io/legado/app/model/Rss.kt index c2568f458..b3622b40b 100644 --- a/app/src/main/java/io/legado/app/model/Rss.kt +++ b/app/src/main/java/io/legado/app/model/Rss.kt @@ -35,7 +35,7 @@ object Rss { ): Coroutine { return Coroutine.async(scope, context) { val body = AnalyzeUrl(rssArticle.link, baseUrl = rssArticle.origin) - .getResponseAwait() + .getResponseAwait(rssArticle.origin) .body val analyzeRule = AnalyzeRule() analyzeRule.setContent( diff --git a/app/src/main/java/io/legado/app/model/WebBook.kt b/app/src/main/java/io/legado/app/model/WebBook.kt index bb3f80b8d..5a51b486c 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -37,7 +37,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = sourceUrl, headerMapF = bookSource.getHeaderMap() ) - val res = analyzeUrl.getResponseAwait() + val res = analyzeUrl.getResponseAwait(bookSource.bookSourceUrl) BookList.analyzeBookList( res.body, bookSource, @@ -65,7 +65,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = sourceUrl, headerMapF = bookSource.getHeaderMap() ) - val res = analyzeUrl.getResponseAwait() + val res = analyzeUrl.getResponseAwait(bookSource.bookSourceUrl) BookList.analyzeBookList( res.body, bookSource, @@ -96,7 +96,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = sourceUrl, headerMapF = bookSource.getHeaderMap() ) - analyzeUrl.getResponseAwait().body + analyzeUrl.getResponseAwait(bookSource.bookSourceUrl).body } BookInfo.analyzeBookInfo(book, body, bookSource, book.bookUrl) book @@ -122,7 +122,7 @@ class WebBook(val bookSource: BookSource) { ruleUrl = book.tocUrl, baseUrl = book.bookUrl, headerMapF = bookSource.getHeaderMap() - ).getResponseAwait().body + ).getResponseAwait(bookSource.bookSourceUrl).body } BookChapterList.analyzeChapterList(this, book, body, bookSource, book.tocUrl) } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index f9dbba8ee..f88a5ee85 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -610,7 +610,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { override fun ajax(urlStr: String): String? { return try { val analyzeUrl = AnalyzeUrl(urlStr, null, null, null, baseUrl, book) - val call = analyzeUrl.getResponse() + val call = analyzeUrl.getResponse(urlStr) val response = call.execute() response.body() } catch (e: Exception) { 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 e476eea28..8559351f4 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 @@ -63,7 +63,7 @@ object BookChapterList { ruleUrl = nextUrl, book = book, headerMapF = bookSource.getHeaderMap() - ).getResponseAwait() + ).getResponseAwait(bookSource.bookSourceUrl) .body?.let { nextBody -> chapterData = analyzeChapterList( book, nextUrl, nextBody, tocRule, listRule, bookSource @@ -132,7 +132,8 @@ object BookChapterList { ruleUrl = chapterData.nextUrl, book = book, headerMapF = bookSource.getHeaderMap() - ).getResponseAwait().body ?: throw Exception("${chapterData.nextUrl}, 下载失败") + ).getResponseAwait(bookSource.bookSourceUrl).body + ?: throw Exception("${chapterData.nextUrl}, 下载失败") val nextChapterData = analyzeChapterList( book, chapterData.nextUrl, nextBody, tocRule, listRule, bookSource, false 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 8ca67a6c5..14ea49b25 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 @@ -56,7 +56,7 @@ object BookContent { ruleUrl = nextUrl, book = book, headerMapF = bookSource.getHeaderMap() - ).getResponseAwait() + ).getResponseAwait(bookSource.bookSourceUrl) .body?.let { nextBody -> contentData = analyzeContent( @@ -80,7 +80,7 @@ object BookContent { ruleUrl = item.nextUrl, book = book, headerMapF = bookSource.getHeaderMap() - ).getResponseAwait() + ).getResponseAwait(bookSource.bookSourceUrl) .body?.let { contentData = analyzeContent( diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 40c3c9e94..996eaa25c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -11,7 +11,6 @@ import androidx.fragment.app.DialogFragment import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey -import io.legado.app.help.BookHelp import io.legado.app.help.ReadBookConfig import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.accentColor @@ -118,7 +117,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { title = getString(R.string.text_indent), items = resources.getStringArray(R.array.indent).toList() ) { _, index -> - BookHelp.bodyIndentCount = index + ReadBookConfig.bodyIndentCount = index postEvent(EventBus.UP_CONFIG, true) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 2c3996fd8..33ece04d2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -9,7 +9,6 @@ import io.legado.app.App import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookChapter import io.legado.app.help.AppConfig -import io.legado.app.help.BookHelp import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextLine @@ -34,7 +33,6 @@ object ChapterProvider { var typeface: Typeface = Typeface.SANS_SERIF var titlePaint = TextPaint() var contentPaint = TextPaint() - private var bodyIndent = BookHelp.bodyIndent init { upStyle() @@ -227,6 +225,7 @@ object ChapterProvider { desiredWidth: Float ) { var x = 0f + val bodyIndent = ReadBookConfig.bodyIndent val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length for (i in 0..bodyIndent.lastIndex) { val x1 = x + icw @@ -348,8 +347,6 @@ object ChapterProvider { titlePaint.textSize = (ReadBookConfig.textSize + 2).dp.toFloat() contentPaint.textSize = ReadBookConfig.textSize.dp.toFloat() - bodyIndent = BookHelp.bodyIndent - upSize() }