Merge remote-tracking branch 'origin/master'

pull/2675/head
kunfei 2 years ago
commit daf18e45db
  1. 6
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  2. 6
      app/src/main/java/io/legado/app/model/localBook/EpubFile.kt
  3. 18
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  4. 6
      app/src/main/java/io/legado/app/model/localBook/PdfFile.kt
  5. 6
      app/src/main/java/io/legado/app/model/localBook/UmdFile.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@ -13,10 +13,12 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.*
import io.legado.app.help.DirectLinkUpload
import io.legado.app.help.LauncherIconHelp
import io.legado.app.help.book.isLocal
import io.legado.app.help.book.upType
import io.legado.app.help.config.LocalConfig
import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.config.ThemeConfig
import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
@ -69,6 +71,10 @@ object Restore {
it.forEach { book ->
book.upType()
}
it.filter { book -> book.isLocal }
.forEach { book ->
book.coverUrl = LocalBook.getCoverPath(book)
}
appDb.bookDao.insert(*it.toTypedArray())
}
fileToListT<Bookmark>(path, "bookmark.json")?.let {

@ -85,11 +85,7 @@ class EpubFile(var book: Book) {
try {
epubBook?.let {
if (book.coverUrl.isNullOrEmpty()) {
book.coverUrl = FileUtils.getPath(
appCtx.externalFiles,
"covers",
"${MD5Utils.md5Encode16(book.bookUrl)}.jpg"
)
book.coverUrl = LocalBook.getCoverPath(book)
}
if (!File(book.coverUrl!!).exists()) {
/*部分书籍DRM处理后,封面获取异常,待优化*/

@ -123,6 +123,18 @@ object LocalBook {
}.getOrElse { content }
}
fun getCoverPath(book: Book): String {
return getCoverPath(book.bookUrl)
}
private fun getCoverPath(bookUrl: String): String {
return FileUtils.getPath(
appCtx.externalFiles,
"covers",
"${MD5Utils.md5Encode16(bookUrl)}.jpg"
)
}
/**
* 下载在线的文件并自动导入到阅读txt umd epub)
* 压缩文件请先提示用户解压
@ -162,11 +174,7 @@ object LocalBook {
name = nameAuthor.first,
author = nameAuthor.second,
originName = fileName,
coverUrl = FileUtils.getPath(
appCtx.externalFiles,
"covers",
"${MD5Utils.md5Encode16(bookUrl)}.jpg"
),
coverUrl = getCoverPath(bookUrl),
latestChapterTime = updateTime,
order = appDb.bookDao.minOrder - 1
)

@ -75,11 +75,7 @@ class PdfFile(var book: Book) {
try {
pdfRenderer?.let { renderer ->
if (book.coverUrl.isNullOrEmpty()) {
book.coverUrl = FileUtils.getPath(
appCtx.externalFiles,
"covers",
"${MD5Utils.md5Encode16(book.bookUrl)}.jpg"
)
book.coverUrl = LocalBook.getCoverPath(book)
}
if (!File(book.coverUrl!!).exists()) {

@ -64,11 +64,7 @@ class UmdFile(var book: Book) {
try {
umdBook?.let {
if (book.coverUrl.isNullOrEmpty()) {
book.coverUrl = FileUtils.getPath(
appCtx.externalFiles,
"covers",
"${MD5Utils.md5Encode16(book.bookUrl)}.jpg"
)
book.coverUrl = LocalBook.getCoverPath(book)
}
if (!File(book.coverUrl!!).exists()) {
FileUtils.writeBytes(book.coverUrl!!, it.cover.coverData)

@ -80,7 +80,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
upCoverByRule(book)
bookSource = if (book.isLocal) null else
appDb.bookSourceDao.getBookSource(book.origin)
if (book.tocUrl.isEmpty()) {
if (book.tocUrl.isEmpty() && !book.isLocal) {
loadBookInfo(book)
} else if (isImportBookOnLine) {
chapterListData.postValue(emptyList())

Loading…
Cancel
Save