Merge branch 'master' into master

pull/1135/head
kunfei 3 years ago committed by GitHub
commit 3905e7ae19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  2. 2
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  3. 2
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt
  6. 4
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt

@ -6,8 +6,33 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.toastOnUi
import splitties.init.appCtx
import java.lang.ref.WeakReference
class ContentProcessor(private val bookName: String, private val bookOrigin: String) {
class ContentProcessor private constructor(
private val bookName: String,
private val bookOrigin: String
) {
companion object {
private val processors = hashMapOf<String, WeakReference<ContentProcessor>>()
fun get(bookName: String, bookOrigin: String): ContentProcessor {
val processorWr = processors[bookName + bookOrigin]
var processor: ContentProcessor? = processorWr?.get()
if (processor == null) {
processor = ContentProcessor(bookName, bookOrigin)
processors[bookName + bookOrigin] = WeakReference(processor)
}
return processor
}
fun upReplaceRules() {
processors.forEach {
it.value.get()?.upReplaceRules()
}
}
}
private var replaceRules = arrayListOf<ReplaceRule>()

@ -46,7 +46,7 @@ object ReadBook {
fun resetData(book: Book) {
this.book = book
contentProcessor = ContentProcessor(book.name, book.origin)
contentProcessor = ContentProcessor.get(book.name, book.origin)
readRecord.bookName = book.name
readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0
durChapterIndex = book.durChapterIndex

@ -8,6 +8,7 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
import io.legado.app.help.AppConfig
import io.legado.app.help.ContentProcessor
import io.legado.app.help.SourceHelp
import io.legado.app.help.http.newCall
import io.legado.app.help.http.okHttpClient
@ -67,6 +68,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
}
}
SourceHelp.insertBookSource(*selectSource.toTypedArray())
ContentProcessor.upReplaceRules()
}.onFinally {
finally.invoke()
}

@ -122,7 +122,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
private fun getAllContents(book: Book, append: (text: String) -> Unit) {
val useReplace = AppConfig.exportUseReplace
val contentProcessor = ContentProcessor(book.name, book.origin)
val contentProcessor = ContentProcessor.get(book.name, book.origin)
append(
"${book.name}\n${
context.getString(
@ -386,7 +386,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
private fun setEpubContent(contentModel: String, book: Book, epubBook: EpubBook) {
//正文
val useReplace = AppConfig.exportUseReplace
val contentProcessor = ContentProcessor(book.name, book.origin)
val contentProcessor = ContentProcessor.get(book.name, book.origin)
appDb.bookChapterDao.getChapterList(book.bookUrl).forEachIndexed { index, chapter ->
BookHelp.getContent(book, chapter).let { content ->
var content1 = fixPic(epubBook, book, content ?: "null", chapter)

@ -18,7 +18,7 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
execute {
book = appDb.bookDao.getBook(bookUrl)
book?.let {
contentProcessor = ContentProcessor(it.name, it.origin)
contentProcessor = ContentProcessor.get(it.name, it.origin)
}
}.onSuccess {
success.invoke()

@ -21,12 +21,12 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityReplaceRuleBinding
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.ContentProcessor
import io.legado.app.help.IntentDataHelp
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.service.help.ReadBook
import io.legado.app.ui.association.ImportReplaceRuleActivity
import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.document.FilePickerParam
@ -294,7 +294,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
override fun onDestroy() {
super.onDestroy()
Coroutine.async { ReadBook.contentProcessor?.upReplaceRules() }
Coroutine.async { ContentProcessor.upReplaceRules() }
}
override fun upCountView() {

Loading…
Cancel
Save