mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
9025af3897
commit
14321a8e49
@ -3,7 +3,6 @@ package io.legado.app.service
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.ArraySet
|
import android.util.ArraySet
|
||||||
@ -11,8 +10,6 @@ import androidx.core.app.NotificationCompat
|
|||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.request.target.CustomTarget
|
|
||||||
import com.bumptech.glide.request.transition.Transition
|
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseService
|
import io.legado.app.base.BaseService
|
||||||
import io.legado.app.constant.AppConst
|
import io.legado.app.constant.AppConst
|
||||||
@ -36,7 +33,6 @@ import io.legado.app.ui.book.cache.CacheActivity
|
|||||||
import io.legado.app.utils.DocumentUtils
|
import io.legado.app.utils.DocumentUtils
|
||||||
import io.legado.app.utils.FileUtils
|
import io.legado.app.utils.FileUtils
|
||||||
import io.legado.app.utils.HtmlFormatter
|
import io.legado.app.utils.HtmlFormatter
|
||||||
import io.legado.app.utils.LogUtils
|
|
||||||
import io.legado.app.utils.MD5Utils
|
import io.legado.app.utils.MD5Utils
|
||||||
import io.legado.app.utils.NetworkUtils
|
import io.legado.app.utils.NetworkUtils
|
||||||
import io.legado.app.utils.activityPendingIntent
|
import io.legado.app.utils.activityPendingIntent
|
||||||
@ -419,7 +415,6 @@ class ExportBookService : BaseService() {
|
|||||||
private suspend fun exportEPUB(path: String, book: Book) {
|
private suspend fun exportEPUB(path: String, book: Book) {
|
||||||
exportMsg.remove(book.bookUrl)
|
exportMsg.remove(book.bookUrl)
|
||||||
postEvent(EventBus.EXPORT_BOOK, book.bookUrl)
|
postEvent(EventBus.EXPORT_BOOK, book.bookUrl)
|
||||||
LogUtils.d("ExportBookService", "exportEPUB start ${book.name} $path")
|
|
||||||
if (path.isContentScheme()) {
|
if (path.isContentScheme()) {
|
||||||
val uri = Uri.parse(path)
|
val uri = Uri.parse(path)
|
||||||
val doc = DocumentFile.fromTreeUri(this@ExportBookService, uri)
|
val doc = DocumentFile.fromTreeUri(this@ExportBookService, uri)
|
||||||
@ -428,7 +423,6 @@ class ExportBookService : BaseService() {
|
|||||||
} else {
|
} else {
|
||||||
exportEpub(File(path).createFolderIfNotExist(), book)
|
exportEpub(File(path).createFolderIfNotExist(), book)
|
||||||
}
|
}
|
||||||
LogUtils.d("ExportBookService", "exportEPUB finish")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun exportEpub(doc: DocumentFile, book: Book) {
|
private suspend fun exportEpub(doc: DocumentFile, book: Book) {
|
||||||
@ -607,40 +601,20 @@ class ExportBookService : BaseService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setCover(book: Book, epubBook: EpubBook) {
|
private fun setCover(book: Book, epubBook: EpubBook) {
|
||||||
LogUtils.d(
|
kotlin.runCatching {
|
||||||
"ExportBookService",
|
val bitmap = Glide.with(this)
|
||||||
"${epubBook.metadata.firstTitle} setCover"
|
.asBitmap()
|
||||||
)
|
.load(book.getDisplayCover())
|
||||||
LogUtils.d("ExportBookService", "cover url ${book.getDisplayCover()}")
|
.submit()
|
||||||
Glide.with(this)
|
.get()
|
||||||
.asBitmap()
|
val byteArray = ByteArrayOutputStream().use {
|
||||||
.load(book.getDisplayCover())
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, it)
|
||||||
.into(object : CustomTarget<Bitmap>() {
|
it.toByteArray()
|
||||||
override fun onResourceReady(
|
}
|
||||||
resource: Bitmap,
|
epubBook.coverImage = Resource(byteArray, "Images/cover.jpg")
|
||||||
transition: Transition<in Bitmap>?
|
}.onFailure {
|
||||||
) {
|
AppLog.put("获取书籍封面出错\n${it.localizedMessage}", it)
|
||||||
val stream = ByteArrayOutputStream()
|
}
|
||||||
resource.compress(Bitmap.CompressFormat.JPEG, 100, stream)
|
|
||||||
val byteArray: ByteArray = stream.toByteArray()
|
|
||||||
stream.close()
|
|
||||||
epubBook.coverImage = Resource(byteArray, "Images/cover.jpg")
|
|
||||||
LogUtils.d(
|
|
||||||
"ExportBookService",
|
|
||||||
"${epubBook.metadata.firstTitle} setCover success"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLoadFailed(errorDrawable: Drawable?) {
|
|
||||||
LogUtils.d(
|
|
||||||
"ExportBookService",
|
|
||||||
"${epubBook.metadata.firstTitle} setCover fail"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLoadCleared(placeholder: Drawable?) {
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun setEpubContent(
|
private suspend fun setEpubContent(
|
||||||
|
Loading…
Reference in New Issue
Block a user