mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -110,10 +110,13 @@ interface BookSourceDao {
|
||||
)
|
||||
fun getEnabledByGroup(group: String): List<BookSource>
|
||||
|
||||
@Query("select * from book_sources where enabled = 1 and bookSourceType = :type")
|
||||
@Query("select * from book_sources where bookUrlPattern != 'NONE' and bookSourceType = :type")
|
||||
fun getEnabledByType(type: Int): List<BookSource>
|
||||
|
||||
@get:Query("select * from book_sources where enabled = 1 and trim(bookUrlPattern) <> '' order by enabled desc, customOrder")
|
||||
@Query("select * from book_sources where enabled = 1 and bookSourceUrl = :baseUrl")
|
||||
fun getBookSourceAddBook(baseUrl: String): BookSource?
|
||||
|
||||
@get:Query("select * from book_sources where enabled = 1 and trim(bookUrlPattern) <> '' and trim(bookUrlPattern) <> 'NONE' order by enabled desc, customOrder")
|
||||
val hasBookUrlPattern: List<BookSource>
|
||||
|
||||
@get:Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = ''")
|
||||
|
||||
@@ -12,8 +12,25 @@ import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.help.DefaultData
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.BitmapUtils
|
||||
import io.legado.app.utils.FileUtils
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.compress.ZipUtils
|
||||
import io.legado.app.utils.createFolderReplace
|
||||
import io.legado.app.utils.externalCache
|
||||
import io.legado.app.utils.externalFiles
|
||||
import io.legado.app.utils.fromJsonArray
|
||||
import io.legado.app.utils.fromJsonObject
|
||||
import io.legado.app.utils.getCompatColor
|
||||
import io.legado.app.utils.getFile
|
||||
import io.legado.app.utils.getMeanColor
|
||||
import io.legado.app.utils.getPrefBoolean
|
||||
import io.legado.app.utils.getPrefInt
|
||||
import io.legado.app.utils.hexString
|
||||
import io.legado.app.utils.printOnDebug
|
||||
import io.legado.app.utils.putPrefBoolean
|
||||
import io.legado.app.utils.putPrefInt
|
||||
import io.legado.app.utils.resizeAndRecycle
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.withContext
|
||||
import splitties.init.appCtx
|
||||
@@ -394,7 +411,6 @@ object ReadBookConfig {
|
||||
zipFile.writeBytes(byteArray)
|
||||
val configDir = appCtx.externalCache.getFile("readConfig")
|
||||
configDir.createFolderReplace()
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
ZipUtils.unZipToPath(zipFile, configDir)
|
||||
val configFile = configDir.getFile(configFileName)
|
||||
val config: Config = GSON.fromJsonObject<Config>(configFile.readText()).getOrThrow()
|
||||
|
||||
@@ -259,7 +259,6 @@ open class WebDav(
|
||||
* @param savedPath 本地的完整路径,包括最后的文件名
|
||||
* @param replaceExisting 是否替换本地的同名文件
|
||||
*/
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
@Throws(WebDavException::class)
|
||||
suspend fun downloadTo(savedPath: String, replaceExisting: Boolean) {
|
||||
val file = File(savedPath)
|
||||
|
||||
@@ -123,7 +123,7 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe
|
||||
}
|
||||
}
|
||||
}
|
||||
appDb.bookSourceDao.getBookSource(baseUrl)?.let { source ->
|
||||
appDb.bookSourceDao.getBookSourceAddBook(baseUrl)?.let { source ->
|
||||
getBookInfo(bookUrl, source)?.let { book ->
|
||||
return@execute book
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ class OnLineImportViewModel(app: Application) : BaseAssociationViewModel(app) {
|
||||
|
||||
fun getBytes(url: String, success: (bytes: ByteArray) -> Unit) {
|
||||
execute {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
okHttpClient.newCallResponseBody {
|
||||
if (url.endsWith("#requestWithoutUA")) {
|
||||
url(url.substringBeforeLast("#requestWithoutUA"))
|
||||
@@ -88,7 +87,6 @@ class OnLineImportViewModel(app: Application) : BaseAssociationViewModel(app) {
|
||||
when (rs.contentType()) {
|
||||
"application/zip".toMediaType(),
|
||||
"application/octet-stream".toMediaType() -> {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
importReadConfig(rs.bytes(), finally)
|
||||
}
|
||||
else -> {
|
||||
|
||||
@@ -123,7 +123,6 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
private suspend fun export(doc: DocumentFile, book: Book) {
|
||||
val filename = book.getExportFileName("txt")
|
||||
DocumentUtils.delete(doc, filename)
|
||||
@@ -288,7 +287,6 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
private suspend fun exportEpub(doc: DocumentFile, book: Book) {
|
||||
val filename = book.getExportFileName("epub")
|
||||
DocumentUtils.delete(doc, filename)
|
||||
|
||||
@@ -232,7 +232,6 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
||||
})
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
private fun exportConfig(uri: Uri) {
|
||||
val exportFileName = if (ReadBookConfig.config.name.isBlank()) {
|
||||
configFileName
|
||||
@@ -324,7 +323,6 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
||||
|
||||
private fun importNetConfig(url: String) {
|
||||
execute {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
okHttpClient.newCallResponseBody {
|
||||
url(url)
|
||||
}.bytes().let {
|
||||
@@ -337,7 +335,6 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
||||
|
||||
private fun importConfig(uri: Uri) {
|
||||
execute {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
importConfig(uri.readBytes(requireContext()))
|
||||
}.onError {
|
||||
it.printOnDebug()
|
||||
@@ -345,7 +342,6 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext", "BlockingMethodInNonBlockingContext")
|
||||
private fun importConfig(byteArray: ByteArray) {
|
||||
execute {
|
||||
ReadBookConfig.import(byteArray).getOrThrow()
|
||||
|
||||
@@ -88,7 +88,6 @@ object ImageProvider {
|
||||
if (book.isEpub) {
|
||||
EpubFile.getImage(book, src)?.use { input ->
|
||||
val newFile = FileUtils.createFileIfNotExist(vFile.absolutePath)
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
FileOutputStream(newFile).use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
@@ -96,7 +95,6 @@ object ImageProvider {
|
||||
} else if (book.isPdf) {
|
||||
PdfFile.getImage(book, src)?.use { input ->
|
||||
val newFile = FileUtils.createFileIfNotExist(vFile.absolutePath)
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
FileOutputStream(newFile).use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
@@ -170,7 +168,6 @@ object ImageProvider {
|
||||
}
|
||||
return null
|
||||
}
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
return kotlin.runCatching {
|
||||
val bitmap = BitmapUtils.decodeBitmap(vFile.absolutePath, width, height)
|
||||
?: SvgUtils.createBitmap(vFile.absolutePath, width, height)
|
||||
|
||||
@@ -15,9 +15,14 @@ import io.legado.app.help.IntentData
|
||||
import io.legado.app.help.http.newCallResponseBody
|
||||
import io.legado.app.help.http.okHttpClient
|
||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.DocumentUtils
|
||||
import io.legado.app.utils.FileUtils
|
||||
import io.legado.app.utils.isContentScheme
|
||||
import io.legado.app.utils.printOnDebug
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import io.legado.app.utils.writeBytes
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
|
||||
class WebViewModel(application: Application) : BaseViewModel(application) {
|
||||
var baseUrl: String = ""
|
||||
@@ -75,7 +80,6 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
private suspend fun webData2bitmap(data: String): ByteArray? {
|
||||
return if (URLUtil.isValidUrl(data)) {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
okHttpClient.newCallResponseBody {
|
||||
url(data)
|
||||
}.bytes()
|
||||
|
||||
@@ -12,12 +12,24 @@ import io.legado.app.help.http.newCallResponseBody
|
||||
import io.legado.app.help.http.okHttpClient
|
||||
import io.legado.app.help.http.text
|
||||
import io.legado.app.model.webBook.WebBook
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.FileUtils
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.NetworkUtils
|
||||
import io.legado.app.utils.fromJsonArray
|
||||
import io.legado.app.utils.isAbsUrl
|
||||
import io.legado.app.utils.isJsonArray
|
||||
import io.legado.app.utils.printOnDebug
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.isActive
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.OutputStreamWriter
|
||||
import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
import kotlin.collections.forEach
|
||||
import kotlin.collections.hashMapOf
|
||||
import kotlin.collections.set
|
||||
|
||||
class BookshelfViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
@@ -33,7 +45,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
|
||||
if (bookUrl.isEmpty()) continue
|
||||
if (appDb.bookDao.getBook(bookUrl) != null) continue
|
||||
val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue
|
||||
var source = appDb.bookSourceDao.getBookSource(baseUrl)
|
||||
var source = appDb.bookSourceDao.getBookSourceAddBook(baseUrl)
|
||||
if (source == null) {
|
||||
hasBookUrlPattern.forEach { bookSource ->
|
||||
if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) {
|
||||
@@ -75,7 +87,6 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
|
||||
val path = "${context.filesDir}/books.json"
|
||||
FileUtils.delete(path)
|
||||
val file = FileUtils.createFileWithReplace(path)
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
FileOutputStream(file).use { out ->
|
||||
val writer = JsonWriter(OutputStreamWriter(out, "UTF-8"))
|
||||
writer.setIndent(" ")
|
||||
|
||||
@@ -19,11 +19,15 @@ import io.legado.app.help.http.newCallResponseBody
|
||||
import io.legado.app.help.http.okHttpClient
|
||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||
import io.legado.app.model.rss.Rss
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.DocumentUtils
|
||||
import io.legado.app.utils.FileUtils
|
||||
import io.legado.app.utils.isContentScheme
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import io.legado.app.utils.writeBytes
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import splitties.init.appCtx
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
|
||||
|
||||
class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
||||
@@ -156,7 +160,6 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
private suspend fun webData2bitmap(data: String): ByteArray? {
|
||||
return if (URLUtil.isValidUrl(data)) {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
okHttpClient.newCallResponseBody {
|
||||
url(data)
|
||||
}.bytes()
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.io.*
|
||||
import java.util.zip.*
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
@Suppress("unused", "BlockingMethodInNonBlockingContext", "MemberVisibilityCanBePrivate")
|
||||
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||
object ZipUtils {
|
||||
|
||||
fun zipString(text: String): ByteArray {
|
||||
|
||||
Reference in New Issue
Block a user