pull/1303/head
gedoor 3 years ago
parent da907755c4
commit d5d62820ac
  1. 2
      app/src/main/java/io/legado/app/constant/AppConst.kt
  2. 4
      app/src/main/java/io/legado/app/model/webBook/SearchModel.kt
  3. 2
      app/src/main/java/io/legado/app/service/CacheBookService.kt
  4. 2
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt
  6. 4
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  7. 10
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  8. 6
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -20,6 +20,8 @@ object AppConst {
const val UA_NAME = "User-Agent" const val UA_NAME = "User-Agent"
const val MAX_THREAD = 6
val SCRIPT_ENGINE: ScriptEngine by lazy { val SCRIPT_ENGINE: ScriptEngine by lazy {
ScriptEngineManager().getEngineByName("rhino") ScriptEngineManager().getEngineByName("rhino")
} }

@ -1,5 +1,6 @@
package io.legado.app.model.webBook package io.legado.app.model.webBook
import io.legado.app.constant.AppConst
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
@ -31,7 +32,8 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
private fun initSearchPool() { private fun initSearchPool() {
searchPool?.close() searchPool?.close()
searchPool = Executors.newFixedThreadPool(min(threadCount, 8)).asCoroutineDispatcher() searchPool = Executors
.newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher()
} }
fun search(searchId: Long, key: String) { fun search(searchId: Long, key: String) {

@ -21,7 +21,7 @@ import kotlin.math.min
class CacheBookService : BaseService() { class CacheBookService : BaseService() {
private val threadCount = AppConfig.threadCount private val threadCount = AppConfig.threadCount
private var cachePool = private var cachePool =
Executors.newFixedThreadPool(min(threadCount, 8)).asCoroutineDispatcher() Executors.newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher()
private var downloadJob: Job? = null private var downloadJob: Job? = null
private var notificationContent = appCtx.getString(R.string.starting_download) private var notificationContent = appCtx.getString(R.string.starting_download)

@ -26,7 +26,7 @@ import kotlin.math.min
class CheckSourceService : BaseService() { class CheckSourceService : BaseService() {
private var threadCount = AppConfig.threadCount private var threadCount = AppConfig.threadCount
private var searchCoroutine = private var searchCoroutine =
Executors.newFixedThreadPool(min(threadCount, 8)).asCoroutineDispatcher() Executors.newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher()
private var tasks = CompositeCoroutine() private var tasks = CompositeCoroutine()
private val allIds = ArrayList<String>() private val allIds = ArrayList<String>()
private val checkedIds = ArrayList<String>() private val checkedIds = ArrayList<String>()

@ -5,6 +5,7 @@ import android.os.Bundle
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
@ -45,7 +46,8 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
} }
private fun initSearchPool() { private fun initSearchPool() {
searchPool = Executors.newFixedThreadPool(min(threadCount,8)).asCoroutineDispatcher() searchPool = Executors
.newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher()
searchIndex = -1 searchIndex = -1
} }

@ -5,6 +5,7 @@ import android.os.Bundle
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
@ -53,7 +54,8 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
} }
private fun initSearchPool() { private fun initSearchPool() {
searchPool = Executors.newFixedThreadPool(min(threadCount,8)).asCoroutineDispatcher() searchPool = Executors
.newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher()
searchIndex = -1 searchIndex = -1
} }

@ -20,7 +20,6 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ActivityBookSourceBinding import io.legado.app.databinding.ActivityBookSourceBinding
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.AppConfig
import io.legado.app.help.LocalConfig import io.legado.app.help.LocalConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
@ -41,7 +40,6 @@ import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
import kotlin.math.min
class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(), class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(),
PopupMenu.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener,
@ -484,8 +482,12 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
delay(300L) delay(300L)
} }
}.collect { }.collect {
adapter.notifyItemRangeChanged(firstIndex, lastIndex + 1, bundleOf(Pair("checkSourceMessage", null))) adapter.notifyItemRangeChanged(
if (!Debug.isChecking || (refreshCount > (600 * (lastIndex + 1 - firstIndex) / min(AppConfig.threadCount,8)))) { firstIndex,
lastIndex + 1,
bundleOf(Pair("checkSourceMessage", null))
)
if (!Debug.isChecking) {
Debug.finishChecking() Debug.finishChecking()
this.cancel() this.cancel()
} }

@ -2,6 +2,7 @@ package io.legado.app.ui.main
import android.app.Application import android.app.Application
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppConst
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.appDb import io.legado.app.data.appDb
@ -21,7 +22,7 @@ import kotlin.math.min
class MainViewModel(application: Application) : BaseViewModel(application) { class MainViewModel(application: Application) : BaseViewModel(application) {
private var threadCount = AppConfig.threadCount private var threadCount = AppConfig.threadCount
private var upTocPool = private var upTocPool =
Executors.newFixedThreadPool(min(threadCount, 8)).asCoroutineDispatcher() Executors.newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher()
val updateList = CopyOnWriteArraySet<String>() val updateList = CopyOnWriteArraySet<String>()
private val bookMap = ConcurrentHashMap<String, Book>() private val bookMap = ConcurrentHashMap<String, Book>()
@ -36,7 +37,8 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun upPool() { fun upPool() {
threadCount = AppConfig.threadCount threadCount = AppConfig.threadCount
upTocPool.close() upTocPool.close()
upTocPool = Executors.newFixedThreadPool(min(threadCount, 8)).asCoroutineDispatcher() upTocPool = Executors
.newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher()
} }
fun upAllBookToc() { fun upAllBookToc() {

Loading…
Cancel
Save