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 MAX_THREAD = 6
val SCRIPT_ENGINE: ScriptEngine by lazy {
ScriptEngineManager().getEngineByName("rhino")
}

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

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

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

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

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

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

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

Loading…
Cancel
Save