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

pull/885/head^2
gedoor 4 years ago
parent 4102b12efd
commit 491fc5e05e
  1. 14
      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
}
fun getImageStyle(): String? {
return config().imageStyle
}
fun setImageStyle(imageStyle: String?) {
config().imageStyle = imageStyle
}
fun getDelParagraph(): Int {
return config().delParagraph
}
@ -228,15 +236,19 @@ data class Book(
const val hTag = 2L
const val rubyTag = 4L
const val imgTag = 8L
const val imgStyleDefault = "DEFAULT"
const val imgStyleFull = "FULL"
const val imgStyleText = "TEXT"
}
@Parcelize
data class ReadConfig(
var pageAnim: Int = -1,
var reSegment: Boolean = false,
var imageStyle: String? = null,
var useReplaceRule: Boolean = AppConfig.replaceEnableDefault,// 正文使用净化替换规则
var delParagraph: Int = 0,//去除段首
var delTag: Long = 0L//去除标签
var delTag: Long = 0L,//去除标签
) : Parcelable
class Converters {

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

@ -71,6 +71,9 @@ object ReadBook {
appDb.bookSourceDao.getBookSource(book.origin)?.let {
bookSource = it
webBook = WebBook(it)
if (book.getImageStyle().isNullOrBlank()) {
book.setImageStyle(it.getContentRule().imageStyle)
}
} ?: let {
bookSource = null
webBook = null
@ -413,7 +416,7 @@ object ReadBook {
durChapterIndex -> {
curTextChapter =
ChapterProvider.getTextChapter(
book, chapter, contents, chapterSize, imageStyle
book, chapter, contents, chapterSize
)
if (upContent) callBack?.upContent(resetPageOffset = resetPageOffset)
callBack?.upView()
@ -423,14 +426,14 @@ object ReadBook {
durChapterIndex - 1 -> {
prevTextChapter =
ChapterProvider.getTextChapter(
book, chapter, contents, chapterSize, imageStyle
book, chapter, contents, chapterSize
)
if (upContent) callBack?.upContent(-1, resetPageOffset)
}
durChapterIndex + 1 -> {
nextTextChapter =
ChapterProvider.getTextChapter(
book, chapter, contents, chapterSize, imageStyle
book, chapter, contents, chapterSize
)
if (upContent) callBack?.upContent(1, resetPageOffset)
}
@ -444,8 +447,6 @@ object ReadBook {
}
}
private val imageStyle get() = webBook?.bookSource?.ruleContent?.imageStyle
fun pageAnim(): Int {
book?.let {
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.storage.Backup
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.receiver.TimeBatteryReceiver
import io.legado.app.service.BaseReadAloudService
@ -253,6 +254,16 @@ class ReadBookActivity : ReadBookBaseActivity(),
viewModel.reverseContent(it)
}
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 {
viewModel.syncBookProgress(it) { progress ->
sureSyncProgress(progress)

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

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

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

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

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

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

Loading…
Cancel
Save