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. 85
      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
}
}
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.constant.PreferKey
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 java.io.File

@ -15,7 +15,7 @@ import io.legado.app.data.entities.*
import io.legado.app.help.LauncherIconHelp
import io.legado.app.help.ReadBookConfig
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 kotlinx.coroutines.Dispatchers.IO
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.model.WebBook
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.provider.ChapterProvider
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay

@ -131,21 +131,20 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
}
}
fun changeTo(book: Book) {
fun changeTo(newBook: Book) {
execute {
if (inBookshelf) {
bookData.value?.let {
book.group = it.group
book.order = it.order
it.changeSource(newBook)
App.db.bookDao().delete(it)
}
App.db.bookDao().insert(book)
App.db.bookDao().insert(newBook)
}
bookData.postValue(book)
if (book.tocUrl.isEmpty()) {
loadBookInfo(book) { upChangeDurChapterIndex(book, it) }
bookData.postValue(newBook)
if (newBook.tocUrl.isEmpty()) {
loadBookInfo(newBook) { upChangeDurChapterIndex(newBook, it) }
} 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 {
ReadBook.upMsg(null)
ReadBook.book?.let {
book1.group = it.group
book1.order = it.order
it.changeSource(newBook)
App.db.bookDao().delete(it)
}
ReadBook.prevTextChapter = null
@ -160,15 +159,15 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
withContext(Main) {
ReadBook.callBack?.upContent()
}
App.db.bookDao().insert(book1)
ReadBook.book = book1
App.db.bookSourceDao().getBookSource(book1.origin)?.let {
App.db.bookDao().insert(newBook)
ReadBook.book = newBook
App.db.bookSourceDao().getBookSource(newBook.origin)?.let {
ReadBook.webBook = WebBook(it)
}
if (book1.tocUrl.isEmpty()) {
loadBookInfo(book1) { upChangeDurChapterIndex(book1, it) }
if (newBook.tocUrl.isEmpty()) {
loadBookInfo(newBook) { upChangeDurChapterIndex(newBook, it) }
} 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.TextLine
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.getCompatColor
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.ReadTipConfig
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.utils.dp
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.ui.book.read.page.delegate.*
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.screenshot
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.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.provider.ChapterProvider
class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {

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

@ -5,7 +5,7 @@ import android.text.StaticLayout
import io.legado.app.App
import io.legado.app.R
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
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.os.Build
@ -67,19 +67,21 @@ object ChapterProvider {
src = NetworkUtils.getAbsoluteURL(bookChapter.url, src)
}
src?.let {
durY = setTypeImage(
book, src, durY,
textPages, pageLines,
pageLengths, stringBuilder
)
durY =
setTypeImage(
book, src, durY,
textPages, pageLines,
pageLengths, stringBuilder
)
}
} else {
val isTitle = index == 0
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
durY = setTypeText(
text, durY, textPages, pageLines,
pageLengths, stringBuilder, isTitle
)
durY =
setTypeText(
text, durY, textPages, pageLines,
pageLengths, stringBuilder, isTitle
)
}
}
}
@ -126,11 +128,13 @@ object ChapterProvider {
var width = it.width
if (it.width > visibleWidth) {
height = it.height * visibleWidth / it.width
width = visibleWidth
width =
visibleWidth
}
if (height > visibleHeight) {
width = width * visibleHeight / height
height = visibleHeight
height =
visibleHeight
}
if (durY + height > visibleHeight) {
textPages.add(TextPage())
@ -177,7 +181,8 @@ object ChapterProvider {
var durY = if (isTitle) y + titleTopSpacing else y
val textPaint = if (isTitle) titlePaint else contentPaint
val layout = StaticLayout(
text, textPaint, visibleWidth,
text, textPaint,
visibleWidth,
Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true
)
for (lineIndex in 0 until layout.lineCount) {
@ -189,7 +194,12 @@ object ChapterProvider {
if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) {
//第一行
textLine.text = words
addCharsToLineFirst(textLine, words.toStringArray(), textPaint, desiredWidth)
addCharsToLineFirst(
textLine,
words.toStringArray(),
textPaint,
desiredWidth
)
} else if (lineIndex == layout.lineCount - 1) {
//最后一行
textLine.text = "$words\n"
@ -197,11 +207,22 @@ object ChapterProvider {
val x = if (isTitle && ReadBookConfig.titleMode == 1)
(visibleWidth - layout.getLineWidth(lineIndex)) / 2
else 0f
addCharsToLineLast(textLine, words.toStringArray(), textPaint, x)
addCharsToLineLast(
textLine,
words.toStringArray(),
textPaint,
x
)
} else {
//中间行
textLine.text = words
addCharsToLineMiddle(textLine, words.toStringArray(), textPaint, desiredWidth, 0f)
addCharsToLineMiddle(
textLine,
words.toStringArray(),
textPaint,
desiredWidth,
0f
)
}
if (durY + textPaint.textHeight > visibleHeight) {
//当前页面结束,设置各种值
@ -237,7 +258,12 @@ object ChapterProvider {
) {
var x = 0f
if (!ReadBookConfig.textFullJustify) {
addCharsToLineLast(textLine, words, textPaint, x)
addCharsToLineLast(
textLine,
words,
textPaint,
x
)
return
}
val bodyIndent = ReadBookConfig.bodyIndent
@ -252,7 +278,13 @@ object ChapterProvider {
x = x1
}
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
) {
if (!ReadBookConfig.textFullJustify) {
addCharsToLineLast(textLine, words, textPaint, startX)
addCharsToLineLast(
textLine,
words,
textPaint,
startX
)
return
}
val gapCount: Int = words.lastIndex
@ -282,7 +319,10 @@ object ChapterProvider {
)
x = x1
}
exceed(textLine, words)
exceed(
textLine,
words
)
}
/**
@ -305,7 +345,10 @@ object ChapterProvider {
)
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 io.legado.app.App
@ -29,7 +29,9 @@ object ImageProvider {
out.close()
}
} else {
HttpHelper.getBytes(src)
HttpHelper.getBytes(src)?.let {
FileUtils.createFileIfNotExist(vFile.absolutePath).writeBytes(it)
}
}
}
return try {
Loading…
Cancel
Save