阅读界面菜单添加图片样式选择,针对每本书籍

pull/885/head^2
gedoor 4 years ago
parent 4102b12efd
commit 491fc5e05e
  1. 16
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 32
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  3. 11
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  4. 11
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  5. 8
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  6. 5
      app/src/main/res/menu/book_read.xml
  7. 1
      app/src/main/res/values-zh-rHK/strings.xml
  8. 1
      app/src/main/res/values-zh-rTW/strings.xml
  9. 1
      app/src/main/res/values-zh/strings.xml
  10. 1
      app/src/main/res/values/strings.xml

@ -146,6 +146,14 @@ data class Book(
config().pageAnim = pageAnim config().pageAnim = pageAnim
} }
fun getImageStyle(): String? {
return config().imageStyle
}
fun setImageStyle(imageStyle: String?) {
config().imageStyle = imageStyle
}
fun getDelParagraph(): Int { fun getDelParagraph(): Int {
return config().delParagraph return config().delParagraph
} }
@ -228,15 +236,19 @@ data class Book(
const val hTag = 2L const val hTag = 2L
const val rubyTag = 4L const val rubyTag = 4L
const val imgTag = 8L const val imgTag = 8L
const val imgStyleDefault = "DEFAULT"
const val imgStyleFull = "FULL"
const val imgStyleText = "TEXT"
} }
@Parcelize @Parcelize
data class ReadConfig( data class ReadConfig(
var pageAnim: Int = -1, var pageAnim: Int = -1,
var reSegment: Boolean = false, var reSegment: Boolean = false,
var useReplaceRule: Boolean = AppConfig.replaceEnableDefault, // 正文使用净化替换规则 var imageStyle: String? = null,
var useReplaceRule: Boolean = AppConfig.replaceEnableDefault,// 正文使用净化替换规则
var delParagraph: Int = 0,//去除段首 var delParagraph: Int = 0,//去除段首
var delTag: Long = 0L//去除标签 var delTag: Long = 0L,//去除标签
) : Parcelable ) : Parcelable
class Converters { class Converters {

@ -47,15 +47,8 @@ object BookChapterList {
} }
var chapterData = var chapterData =
analyzeChapterList( analyzeChapterList(
scope, scope, book, baseUrl, redirectUrl, body,
book, tocRule, listRule, bookSource, log = true
baseUrl,
redirectUrl,
body,
tocRule,
listRule,
bookSource,
log = true
) )
chapterData.chapterList?.let { chapterData.chapterList?.let {
chapterList.addAll(it) chapterList.addAll(it)
@ -75,14 +68,8 @@ object BookChapterList {
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
).getStrResponse(bookSource.bookSourceUrl).body?.let { nextBody -> ).getStrResponse(bookSource.bookSourceUrl).body?.let { nextBody ->
chapterData = analyzeChapterList( chapterData = analyzeChapterList(
this, this, book, nextUrl, nextUrl,
book, nextBody, tocRule, listRule, bookSource
nextUrl,
nextUrl,
nextBody,
tocRule,
listRule,
bookSource
) )
nextUrl = chapterData.nextUrl.firstOrNull() ?: "" nextUrl = chapterData.nextUrl.firstOrNull() ?: ""
chapterData.chapterList?.let { chapterData.chapterList?.let {
@ -144,15 +131,8 @@ object BookChapterList {
).getStrResponse(bookSource.bookSourceUrl).body ).getStrResponse(bookSource.bookSourceUrl).body
?: throw Exception("${chapterData.nextUrl}, 下载失败") ?: throw Exception("${chapterData.nextUrl}, 下载失败")
val nextChapterData = analyzeChapterList( val nextChapterData = analyzeChapterList(
this, this, book, chapterData.nextUrl, chapterData.nextUrl,
book, nextBody, tocRule, listRule, bookSource, false
chapterData.nextUrl,
chapterData.nextUrl,
nextBody,
tocRule,
listRule,
bookSource,
false
) )
synchronized(chapterDataList) { synchronized(chapterDataList) {
val isFinished = addChapterListIsFinish( val isFinished = addChapterListIsFinish(

@ -71,6 +71,9 @@ object ReadBook {
appDb.bookSourceDao.getBookSource(book.origin)?.let { appDb.bookSourceDao.getBookSource(book.origin)?.let {
bookSource = it bookSource = it
webBook = WebBook(it) webBook = WebBook(it)
if (book.getImageStyle().isNullOrBlank()) {
book.setImageStyle(it.getContentRule().imageStyle)
}
} ?: let { } ?: let {
bookSource = null bookSource = null
webBook = null webBook = null
@ -413,7 +416,7 @@ object ReadBook {
durChapterIndex -> { durChapterIndex -> {
curTextChapter = curTextChapter =
ChapterProvider.getTextChapter( ChapterProvider.getTextChapter(
book, chapter, contents, chapterSize, imageStyle book, chapter, contents, chapterSize
) )
if (upContent) callBack?.upContent(resetPageOffset = resetPageOffset) if (upContent) callBack?.upContent(resetPageOffset = resetPageOffset)
callBack?.upView() callBack?.upView()
@ -423,14 +426,14 @@ object ReadBook {
durChapterIndex - 1 -> { durChapterIndex - 1 -> {
prevTextChapter = prevTextChapter =
ChapterProvider.getTextChapter( ChapterProvider.getTextChapter(
book, chapter, contents, chapterSize, imageStyle book, chapter, contents, chapterSize
) )
if (upContent) callBack?.upContent(-1, resetPageOffset) if (upContent) callBack?.upContent(-1, resetPageOffset)
} }
durChapterIndex + 1 -> { durChapterIndex + 1 -> {
nextTextChapter = nextTextChapter =
ChapterProvider.getTextChapter( ChapterProvider.getTextChapter(
book, chapter, contents, chapterSize, imageStyle book, chapter, contents, chapterSize
) )
if (upContent) callBack?.upContent(1, resetPageOffset) if (upContent) callBack?.upContent(1, resetPageOffset)
} }
@ -444,8 +447,6 @@ object ReadBook {
} }
} }
private val imageStyle get() = webBook?.bookSource?.ruleContent?.imageStyle
fun pageAnim(): Int { fun pageAnim(): Int {
book?.let { book?.let {
return if (it.getPageAnim() < 0) return if (it.getPageAnim() < 0)

@ -27,6 +27,7 @@ import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ReadTipConfig import io.legado.app.help.ReadTipConfig
import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Backup
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.receiver.TimeBatteryReceiver import io.legado.app.receiver.TimeBatteryReceiver
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
@ -253,6 +254,16 @@ class ReadBookActivity : ReadBookBaseActivity(),
viewModel.reverseContent(it) viewModel.reverseContent(it)
} }
R.id.menu_set_charset -> showCharsetConfig() R.id.menu_set_charset -> showCharsetConfig()
R.id.menu_image_style -> {
val imgStyles =
arrayListOf(Book.imgStyleDefault, Book.imgStyleFull, Book.imgStyleText)
selector(
R.string.image_style,
imgStyles
) { _, index ->
ReadBook.book?.setImageStyle(imgStyles[index])
}
}
R.id.menu_get_progress -> ReadBook.book?.let { R.id.menu_get_progress -> ReadBook.book?.let {
viewModel.syncBookProgress(it) { progress -> viewModel.syncBookProgress(it) { progress ->
sureSyncProgress(progress) sureSyncProgress(progress)

@ -81,7 +81,6 @@ object ChapterProvider {
bookChapter: BookChapter, bookChapter: BookChapter,
contents: List<String>, contents: List<String>,
chapterSize: Int, chapterSize: Int,
imageStyle: String?,
): TextChapter { ): TextChapter {
val textPages = arrayListOf<TextPage>() val textPages = arrayListOf<TextPage>()
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
@ -94,7 +93,7 @@ object ChapterProvider {
if (!book.isEpub()) { if (!book.isEpub()) {
val src = NetworkUtils.getAbsoluteURL(bookChapter.url, it) val src = NetworkUtils.getAbsoluteURL(bookChapter.url, it)
durY = setTypeImage( durY = setTypeImage(
book, bookChapter, src, durY, textPages, imageStyle book, bookChapter, src, durY, textPages, book.getImageStyle()
) )
} }
} }
@ -142,9 +141,12 @@ object ChapterProvider {
var height = it.height var height = it.height
var width = it.width var width = it.width
when (imageStyle?.toUpperCase(Locale.ROOT)) { when (imageStyle?.toUpperCase(Locale.ROOT)) {
"FULL" -> { Book.imgStyleFull -> {
width = visibleWidth width = visibleWidth
height = it.height * visibleWidth / it.width height = it.height * visibleWidth / it.width
}
Book.imgStyleText -> {
} }
else -> { else -> {
if (it.width > visibleWidth) { if (it.width > visibleWidth) {

@ -92,6 +92,11 @@
android:checked="false" android:checked="false"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_image_style"
android:title="@string/image_style"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_update_toc" android:id="@+id/menu_update_toc"
android:title="@string/update_toc" android:title="@string/update_toc"

@ -808,5 +808,6 @@
<string name="debug">调试</string> <string name="debug">调试</string>
<string name="crash_log">崩溃日志</string> <string name="crash_log">崩溃日志</string>
<string name="use_zh_layout">使用自定义中文分行</string> <string name="use_zh_layout">使用自定义中文分行</string>
<string name="image_style">图片样式</string>
</resources> </resources>

@ -810,5 +810,6 @@
<string name="export_to_web_dav">匯出到WebDav</string> <string name="export_to_web_dav">匯出到WebDav</string>
<string name="reverse_content">反转内容</string> <string name="reverse_content">反转内容</string>
<string name="debug">调试</string> <string name="debug">调试</string>
<string name="image_style">图片样式</string>
</resources> </resources>

@ -812,5 +812,6 @@
<string name="debug">调试</string> <string name="debug">调试</string>
<string name="crash_log">崩溃日志</string> <string name="crash_log">崩溃日志</string>
<string name="use_zh_layout">使用自定义中文分行</string> <string name="use_zh_layout">使用自定义中文分行</string>
<string name="image_style">图片样式</string>
</resources> </resources>

@ -815,5 +815,6 @@
<string name="debug">调试</string> <string name="debug">调试</string>
<string name="crash_log">崩溃日志</string> <string name="crash_log">崩溃日志</string>
<string name="use_zh_layout">使用自定义中文分行</string> <string name="use_zh_layout">使用自定义中文分行</string>
<string name="image_style">图片样式</string>
</resources> </resources>

Loading…
Cancel
Save