epub 显示图片,未完善

pull/274/head
gedoor 4 years ago
parent 4fcb77e16f
commit 1f6d9b36cb
  1. 7
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 2
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  3. 2
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  4. 2
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  5. 15
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  6. 17
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  8. 1
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  9. 1
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  10. 2
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt
  11. 4
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt
  12. 2
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt
  13. 71
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  14. 6
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -133,4 +133,11 @@ data class Book(
this.tocHtml = this@Book.tocHtml this.tocHtml = this@Book.tocHtml
} }
} }
fun changeSource(newBook: Book) {
newBook.group = group
newBook.order = order
newBook.customCoverUrl = customCoverUrl
newBook.canUpdate = canUpdate
}
} }

@ -9,7 +9,7 @@ import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.utils.* import io.legado.app.utils.*
import java.io.File import java.io.File

@ -15,7 +15,7 @@ import io.legado.app.data.entities.*
import io.legado.app.help.LauncherIconHelp import io.legado.app.help.LauncherIconHelp
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main

@ -13,8 +13,8 @@ import io.legado.app.help.IntentDataHelp
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.page.ChapterProvider
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.ui.book.read.page.provider.ChapterProvider
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay

@ -131,21 +131,20 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun changeTo(book: Book) { fun changeTo(newBook: Book) {
execute { execute {
if (inBookshelf) { if (inBookshelf) {
bookData.value?.let { bookData.value?.let {
book.group = it.group it.changeSource(newBook)
book.order = it.order
App.db.bookDao().delete(it) App.db.bookDao().delete(it)
} }
App.db.bookDao().insert(book) App.db.bookDao().insert(newBook)
} }
bookData.postValue(book) bookData.postValue(newBook)
if (book.tocUrl.isEmpty()) { if (newBook.tocUrl.isEmpty()) {
loadBookInfo(book) { upChangeDurChapterIndex(book, it) } loadBookInfo(newBook) { upChangeDurChapterIndex(newBook, it) }
} else { } else {
loadChapter(book) { upChangeDurChapterIndex(book, it) } loadChapter(newBook) { upChangeDurChapterIndex(newBook, it) }
} }
} }
} }

@ -146,12 +146,11 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun changeTo(book1: Book) { fun changeTo(newBook: Book) {
execute { execute {
ReadBook.upMsg(null) ReadBook.upMsg(null)
ReadBook.book?.let { ReadBook.book?.let {
book1.group = it.group it.changeSource(newBook)
book1.order = it.order
App.db.bookDao().delete(it) App.db.bookDao().delete(it)
} }
ReadBook.prevTextChapter = null ReadBook.prevTextChapter = null
@ -160,15 +159,15 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
withContext(Main) { withContext(Main) {
ReadBook.callBack?.upContent() ReadBook.callBack?.upContent()
} }
App.db.bookDao().insert(book1) App.db.bookDao().insert(newBook)
ReadBook.book = book1 ReadBook.book = newBook
App.db.bookSourceDao().getBookSource(book1.origin)?.let { App.db.bookSourceDao().getBookSource(newBook.origin)?.let {
ReadBook.webBook = WebBook(it) ReadBook.webBook = WebBook(it)
} }
if (book1.tocUrl.isEmpty()) { if (newBook.tocUrl.isEmpty()) {
loadBookInfo(book1) { upChangeDurChapterIndex(book1, it) } loadBookInfo(newBook) { upChangeDurChapterIndex(newBook, it) }
} else { } else {
loadChapterList(book1) { upChangeDurChapterIndex(book1, it) } loadChapterList(newBook) { upChangeDurChapterIndex(newBook, it) }
} }
} }
} }

@ -14,6 +14,8 @@ import io.legado.app.service.help.ReadBook
import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextChar
import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextLine
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.activity import io.legado.app.utils.activity
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean

@ -12,6 +12,7 @@ import io.legado.app.constant.AppConst.timeFormat
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ReadTipConfig import io.legado.app.help.ReadTipConfig
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.widget.BatteryView import io.legado.app.ui.widget.BatteryView
import io.legado.app.utils.dp import io.legado.app.utils.dp
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor

@ -13,6 +13,7 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
import io.legado.app.ui.book.read.page.delegate.* import io.legado.app.ui.book.read.page.delegate.*
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.utils.activity import io.legado.app.utils.activity
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
import kotlinx.android.synthetic.main.activity_book_read.view.* import kotlinx.android.synthetic.main.activity_book_read.view.*

@ -2,8 +2,8 @@ package io.legado.app.ui.book.read.page.delegate
import android.view.MotionEvent import android.view.MotionEvent
import android.view.VelocityTracker import android.view.VelocityTracker
import io.legado.app.ui.book.read.page.ChapterProvider
import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.PageView
import io.legado.app.ui.book.read.page.provider.ChapterProvider
class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {

@ -1,8 +1,8 @@
package io.legado.app.ui.book.read.page.entities package io.legado.app.ui.book.read.page.entities
import android.text.TextPaint import android.text.TextPaint
import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.book.read.page.ChapterProvider.textHeight import io.legado.app.ui.book.read.page.provider.ChapterProvider.textHeight
data class TextLine( data class TextLine(
var text: String = "", var text: String = "",

@ -5,7 +5,7 @@ import android.text.StaticLayout
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import java.text.DecimalFormat import java.text.DecimalFormat
data class TextPage( data class TextPage(

@ -1,4 +1,4 @@
package io.legado.app.ui.book.read.page package io.legado.app.ui.book.read.page.provider
import android.graphics.Typeface import android.graphics.Typeface
import android.os.Build import android.os.Build
@ -67,7 +67,8 @@ object ChapterProvider {
src = NetworkUtils.getAbsoluteURL(bookChapter.url, src) src = NetworkUtils.getAbsoluteURL(bookChapter.url, src)
} }
src?.let { src?.let {
durY = setTypeImage( durY =
setTypeImage(
book, src, durY, book, src, durY,
textPages, pageLines, textPages, pageLines,
pageLengths, stringBuilder pageLengths, stringBuilder
@ -76,7 +77,8 @@ object ChapterProvider {
} else { } else {
val isTitle = index == 0 val isTitle = index == 0
if (!(isTitle && ReadBookConfig.titleMode == 2)) { if (!(isTitle && ReadBookConfig.titleMode == 2)) {
durY = setTypeText( durY =
setTypeText(
text, durY, textPages, pageLines, text, durY, textPages, pageLines,
pageLengths, stringBuilder, isTitle pageLengths, stringBuilder, isTitle
) )
@ -126,11 +128,13 @@ object ChapterProvider {
var width = it.width var width = it.width
if (it.width > visibleWidth) { if (it.width > visibleWidth) {
height = it.height * visibleWidth / it.width height = it.height * visibleWidth / it.width
width = visibleWidth width =
visibleWidth
} }
if (height > visibleHeight) { if (height > visibleHeight) {
width = width * visibleHeight / height width = width * visibleHeight / height
height = visibleHeight height =
visibleHeight
} }
if (durY + height > visibleHeight) { if (durY + height > visibleHeight) {
textPages.add(TextPage()) textPages.add(TextPage())
@ -177,7 +181,8 @@ object ChapterProvider {
var durY = if (isTitle) y + titleTopSpacing else y var durY = if (isTitle) y + titleTopSpacing else y
val textPaint = if (isTitle) titlePaint else contentPaint val textPaint = if (isTitle) titlePaint else contentPaint
val layout = StaticLayout( val layout = StaticLayout(
text, textPaint, visibleWidth, text, textPaint,
visibleWidth,
Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true
) )
for (lineIndex in 0 until layout.lineCount) { for (lineIndex in 0 until layout.lineCount) {
@ -189,7 +194,12 @@ object ChapterProvider {
if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) { if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) {
//第一行 //第一行
textLine.text = words textLine.text = words
addCharsToLineFirst(textLine, words.toStringArray(), textPaint, desiredWidth) addCharsToLineFirst(
textLine,
words.toStringArray(),
textPaint,
desiredWidth
)
} else if (lineIndex == layout.lineCount - 1) { } else if (lineIndex == layout.lineCount - 1) {
//最后一行 //最后一行
textLine.text = "$words\n" textLine.text = "$words\n"
@ -197,11 +207,22 @@ object ChapterProvider {
val x = if (isTitle && ReadBookConfig.titleMode == 1) val x = if (isTitle && ReadBookConfig.titleMode == 1)
(visibleWidth - layout.getLineWidth(lineIndex)) / 2 (visibleWidth - layout.getLineWidth(lineIndex)) / 2
else 0f else 0f
addCharsToLineLast(textLine, words.toStringArray(), textPaint, x) addCharsToLineLast(
textLine,
words.toStringArray(),
textPaint,
x
)
} else { } else {
//中间行 //中间行
textLine.text = words textLine.text = words
addCharsToLineMiddle(textLine, words.toStringArray(), textPaint, desiredWidth, 0f) addCharsToLineMiddle(
textLine,
words.toStringArray(),
textPaint,
desiredWidth,
0f
)
} }
if (durY + textPaint.textHeight > visibleHeight) { if (durY + textPaint.textHeight > visibleHeight) {
//当前页面结束,设置各种值 //当前页面结束,设置各种值
@ -237,7 +258,12 @@ object ChapterProvider {
) { ) {
var x = 0f var x = 0f
if (!ReadBookConfig.textFullJustify) { if (!ReadBookConfig.textFullJustify) {
addCharsToLineLast(textLine, words, textPaint, x) addCharsToLineLast(
textLine,
words,
textPaint,
x
)
return return
} }
val bodyIndent = ReadBookConfig.bodyIndent val bodyIndent = ReadBookConfig.bodyIndent
@ -252,7 +278,13 @@ object ChapterProvider {
x = x1 x = x1
} }
val words1 = words.copyOfRange(bodyIndent.length, words.size) val words1 = words.copyOfRange(bodyIndent.length, words.size)
addCharsToLineMiddle(textLine, words1, textPaint, desiredWidth, x) addCharsToLineMiddle(
textLine,
words1,
textPaint,
desiredWidth,
x
)
} }
/** /**
@ -266,7 +298,12 @@ object ChapterProvider {
startX: Float startX: Float
) { ) {
if (!ReadBookConfig.textFullJustify) { if (!ReadBookConfig.textFullJustify) {
addCharsToLineLast(textLine, words, textPaint, startX) addCharsToLineLast(
textLine,
words,
textPaint,
startX
)
return return
} }
val gapCount: Int = words.lastIndex val gapCount: Int = words.lastIndex
@ -282,7 +319,10 @@ object ChapterProvider {
) )
x = x1 x = x1
} }
exceed(textLine, words) exceed(
textLine,
words
)
} }
/** /**
@ -305,7 +345,10 @@ object ChapterProvider {
) )
x = x1 x = x1
} }
exceed(textLine, words) exceed(
textLine,
words
)
} }
/** /**

@ -1,4 +1,4 @@
package io.legado.app.ui.book.read.page package io.legado.app.ui.book.read.page.provider
import android.graphics.Bitmap import android.graphics.Bitmap
import io.legado.app.App import io.legado.app.App
@ -29,7 +29,9 @@ object ImageProvider {
out.close() out.close()
} }
} else { } else {
HttpHelper.getBytes(src) HttpHelper.getBytes(src)?.let {
FileUtils.createFileIfNotExist(vFile.absolutePath).writeBytes(it)
}
} }
} }
return try { return try {
Loading…
Cancel
Save