|
|
@ -18,6 +18,12 @@ import java.util.concurrent.Executors |
|
|
|
import kotlin.math.min |
|
|
|
import kotlin.math.min |
|
|
|
|
|
|
|
|
|
|
|
class CacheBookService : BaseService() { |
|
|
|
class CacheBookService : BaseService() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
var isRun = false |
|
|
|
|
|
|
|
private set |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val threadCount = AppConfig.threadCount |
|
|
|
private val threadCount = AppConfig.threadCount |
|
|
|
private var cachePool = |
|
|
|
private var cachePool = |
|
|
|
Executors.newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher() |
|
|
|
Executors.newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher() |
|
|
@ -39,6 +45,7 @@ class CacheBookService : BaseService() { |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate() { |
|
|
|
override fun onCreate() { |
|
|
|
super.onCreate() |
|
|
|
super.onCreate() |
|
|
|
|
|
|
|
isRun = true |
|
|
|
upNotification(getString(R.string.starting_download)) |
|
|
|
upNotification(getString(R.string.starting_download)) |
|
|
|
launch { |
|
|
|
launch { |
|
|
|
while (isActive) { |
|
|
|
while (isActive) { |
|
|
@ -65,6 +72,7 @@ class CacheBookService : BaseService() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
override fun onDestroy() { |
|
|
|
|
|
|
|
isRun = false |
|
|
|
cachePool.close() |
|
|
|
cachePool.close() |
|
|
|
CacheBook.cacheBookMap.clear() |
|
|
|
CacheBook.cacheBookMap.clear() |
|
|
|
super.onDestroy() |
|
|
|
super.onDestroy() |
|
|
|