pull/78/head
kunfei 5 years ago
parent 5c9438f3e1
commit bf2504b61c
  1. 2
      app/src/main/java/io/legado/app/help/PrefExtensions.kt
  2. 4
      app/src/main/java/io/legado/app/service/DownloadService.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt
  4. 4
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt

@ -9,4 +9,4 @@ val Context.isShowRSS: Boolean
get() = getPrefBoolean("showRss", true) get() = getPrefBoolean("showRss", true)
val Context.threadCount: Int val Context.threadCount: Int
get() = getPrefInt("threadCount", 6) get() = getPrefInt("threadCount", 16)

@ -12,6 +12,7 @@ import io.legado.app.constant.Bus
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.threadCount
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -19,7 +20,8 @@ import kotlinx.coroutines.asCoroutineDispatcher
import java.util.concurrent.Executors import java.util.concurrent.Executors
class DownloadService : BaseService() { class DownloadService : BaseService() {
private var searchPool = Executors.newFixedThreadPool(16).asCoroutineDispatcher() private var searchPool =
Executors.newFixedThreadPool(App.INSTANCE.threadCount).asCoroutineDispatcher()
private var tasks: ArrayList<Coroutine<*>> = arrayListOf() private var tasks: ArrayList<Coroutine<*>> = arrayListOf()
private val handler = Handler() private val handler = Handler()
private var runnable: Runnable = Runnable { upDownload() } private var runnable: Runnable = Runnable { upDownload() }

@ -7,6 +7,7 @@ import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.SearchKeyword import io.legado.app.data.entities.SearchKeyword
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.threadCount
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
@ -16,7 +17,8 @@ import kotlinx.coroutines.launch
import java.util.concurrent.Executors import java.util.concurrent.Executors
class SearchViewModel(application: Application) : BaseViewModel(application) { class SearchViewModel(application: Application) : BaseViewModel(application) {
private var searchPool = Executors.newFixedThreadPool(16).asCoroutineDispatcher() private var searchPool =
Executors.newFixedThreadPool(context.threadCount).asCoroutineDispatcher()
private var task: Coroutine<*>? = null private var task: Coroutine<*>? = null
var callBack: CallBack? = null var callBack: CallBack? = null
var searchKey: String = "" var searchKey: String = ""

@ -9,6 +9,7 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.threadCount
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
@ -18,7 +19,8 @@ import org.jetbrains.anko.debug
import java.util.concurrent.Executors import java.util.concurrent.Executors
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
private var searchPool = Executors.newFixedThreadPool(16).asCoroutineDispatcher() private var searchPool =
Executors.newFixedThreadPool(context.threadCount).asCoroutineDispatcher()
var callBack: CallBack? = null var callBack: CallBack? = null
val searchStateData = MutableLiveData<Boolean>() val searchStateData = MutableLiveData<Boolean>()
var name: String = "" var name: String = ""

Loading…
Cancel
Save