pull/1336/head
gedoor 3 years ago
parent b5e8f29cf9
commit 486333dcbd
  1. 3
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 4
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  3. 3
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  4. 8
      app/src/main/java/io/legado/app/service/CacheBookService.kt

@ -35,8 +35,7 @@ abstract class BaseActivity<VB : ViewBinding>(
private val toolBarTheme: Theme = Theme.Auto, private val toolBarTheme: Theme = Theme.Auto,
private val transparent: Boolean = false, private val transparent: Boolean = false,
private val imageBg: Boolean = true private val imageBg: Boolean = true
) : AppCompatActivity(), ) : AppCompatActivity(), CoroutineScope by MainScope() {
CoroutineScope by MainScope() {
protected abstract val binding: VB protected abstract val binding: VB

@ -44,9 +44,13 @@ class AudioPlayService : BaseService(),
companion object { companion object {
var isRun = false var isRun = false
private set
var pause = false var pause = false
private set
var timeMinute: Int = 0 var timeMinute: Int = 0
private set
var url: String = "" var url: String = ""
private set
} }
private val audioManager: AudioManager by lazy { private val audioManager: AudioManager by lazy {

@ -33,8 +33,11 @@ abstract class BaseReadAloudService : BaseService(),
companion object { companion object {
var isRun = false var isRun = false
private set
var timeMinute: Int = 0 var timeMinute: Int = 0
private set
var pause = true var pause = true
private set
fun isPlay(): Boolean { fun isPlay(): Boolean {
return isRun && !pause return isRun && !pause

@ -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()

Loading…
Cancel
Save