mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
234dc7a8fa
commit
e4c7de185c
@ -3,6 +3,7 @@ package io.legado.app.model
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.core.content.ContextCompat
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.constant.IntentAction
|
||||
import io.legado.app.data.appDb
|
||||
@ -50,7 +51,7 @@ object ReadAloud {
|
||||
intent.putExtra("play", play)
|
||||
intent.putExtra("pageIndex", pageIndex)
|
||||
intent.putExtra("startPos", startPos)
|
||||
context.startService(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
|
||||
fun playByEventBus(
|
||||
@ -70,7 +71,7 @@ object ReadAloud {
|
||||
if (BaseReadAloudService.isRun) {
|
||||
val intent = Intent(context, aloudClass)
|
||||
intent.action = IntentAction.pause
|
||||
context.startService(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +79,7 @@ object ReadAloud {
|
||||
if (BaseReadAloudService.isRun) {
|
||||
val intent = Intent(context, aloudClass)
|
||||
intent.action = IntentAction.resume
|
||||
context.startService(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +87,7 @@ object ReadAloud {
|
||||
if (BaseReadAloudService.isRun) {
|
||||
val intent = Intent(context, aloudClass)
|
||||
intent.action = IntentAction.stop
|
||||
context.startService(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +95,7 @@ object ReadAloud {
|
||||
if (BaseReadAloudService.isRun) {
|
||||
val intent = Intent(context, aloudClass)
|
||||
intent.action = IntentAction.prevParagraph
|
||||
context.startService(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,7 +103,7 @@ object ReadAloud {
|
||||
if (BaseReadAloudService.isRun) {
|
||||
val intent = Intent(context, aloudClass)
|
||||
intent.action = IntentAction.nextParagraph
|
||||
context.startService(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +111,7 @@ object ReadAloud {
|
||||
if (BaseReadAloudService.isRun) {
|
||||
val intent = Intent(context, aloudClass)
|
||||
intent.action = IntentAction.upTtsSpeechRate
|
||||
context.startService(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +120,7 @@ object ReadAloud {
|
||||
val intent = Intent(context, aloudClass)
|
||||
intent.action = IntentAction.setTimer
|
||||
intent.putExtra("minute", minute)
|
||||
context.startService(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ 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.AppLog
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.constant.PreferKey
|
||||
@ -90,6 +91,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
searchCallback = null
|
||||
}
|
||||
}.map {
|
||||
kotlin.runCatching {
|
||||
searchBooks.sortedWith { o1, o2 ->
|
||||
val o1bs = SourceConfig.getBookScore(o1.origin, o1.name, o1.author)
|
||||
val o2bs = SourceConfig.getBookScore(o2.origin, o2.name, o2.author)
|
||||
@ -102,11 +104,17 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
when {
|
||||
o1ss - o2ss > 0 -> -1
|
||||
o1ss - o2ss < 0 -> 1
|
||||
else -> o1.originOrder - o2.originOrder
|
||||
else -> {
|
||||
val n = o1.originOrder - o2.originOrder
|
||||
if (n == 0) -1 else n
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
AppLog.put("换源排序出错\n${it.localizedMessage}", it)
|
||||
}.getOrDefault(searchBooks)
|
||||
}.flowOn(IO)
|
||||
|
||||
@Volatile
|
||||
|
@ -43,7 +43,7 @@ inline fun <reified A : Activity> Context.startActivity(configIntent: Intent.()
|
||||
}
|
||||
|
||||
inline fun <reified T : Service> Context.startService(configIntent: Intent.() -> Unit = {}) {
|
||||
startService(Intent(this, T::class.java).apply(configIntent))
|
||||
ContextCompat.startForegroundService(this, Intent(this, T::class.java).apply(configIntent))
|
||||
}
|
||||
|
||||
inline fun <reified T : Service> Context.stopService() {
|
||||
|
Loading…
Reference in New Issue
Block a user