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.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import io.legado.app.constant.EventBus
|
import io.legado.app.constant.EventBus
|
||||||
import io.legado.app.constant.IntentAction
|
import io.legado.app.constant.IntentAction
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
@ -50,7 +51,7 @@ object ReadAloud {
|
|||||||
intent.putExtra("play", play)
|
intent.putExtra("play", play)
|
||||||
intent.putExtra("pageIndex", pageIndex)
|
intent.putExtra("pageIndex", pageIndex)
|
||||||
intent.putExtra("startPos", startPos)
|
intent.putExtra("startPos", startPos)
|
||||||
context.startService(intent)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playByEventBus(
|
fun playByEventBus(
|
||||||
@ -70,7 +71,7 @@ object ReadAloud {
|
|||||||
if (BaseReadAloudService.isRun) {
|
if (BaseReadAloudService.isRun) {
|
||||||
val intent = Intent(context, aloudClass)
|
val intent = Intent(context, aloudClass)
|
||||||
intent.action = IntentAction.pause
|
intent.action = IntentAction.pause
|
||||||
context.startService(intent)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ object ReadAloud {
|
|||||||
if (BaseReadAloudService.isRun) {
|
if (BaseReadAloudService.isRun) {
|
||||||
val intent = Intent(context, aloudClass)
|
val intent = Intent(context, aloudClass)
|
||||||
intent.action = IntentAction.resume
|
intent.action = IntentAction.resume
|
||||||
context.startService(intent)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ object ReadAloud {
|
|||||||
if (BaseReadAloudService.isRun) {
|
if (BaseReadAloudService.isRun) {
|
||||||
val intent = Intent(context, aloudClass)
|
val intent = Intent(context, aloudClass)
|
||||||
intent.action = IntentAction.stop
|
intent.action = IntentAction.stop
|
||||||
context.startService(intent)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ object ReadAloud {
|
|||||||
if (BaseReadAloudService.isRun) {
|
if (BaseReadAloudService.isRun) {
|
||||||
val intent = Intent(context, aloudClass)
|
val intent = Intent(context, aloudClass)
|
||||||
intent.action = IntentAction.prevParagraph
|
intent.action = IntentAction.prevParagraph
|
||||||
context.startService(intent)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ object ReadAloud {
|
|||||||
if (BaseReadAloudService.isRun) {
|
if (BaseReadAloudService.isRun) {
|
||||||
val intent = Intent(context, aloudClass)
|
val intent = Intent(context, aloudClass)
|
||||||
intent.action = IntentAction.nextParagraph
|
intent.action = IntentAction.nextParagraph
|
||||||
context.startService(intent)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ object ReadAloud {
|
|||||||
if (BaseReadAloudService.isRun) {
|
if (BaseReadAloudService.isRun) {
|
||||||
val intent = Intent(context, aloudClass)
|
val intent = Intent(context, aloudClass)
|
||||||
intent.action = IntentAction.upTtsSpeechRate
|
intent.action = IntentAction.upTtsSpeechRate
|
||||||
context.startService(intent)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +120,7 @@ object ReadAloud {
|
|||||||
val intent = Intent(context, aloudClass)
|
val intent = Intent(context, aloudClass)
|
||||||
intent.action = IntentAction.setTimer
|
intent.action = IntentAction.setTimer
|
||||||
intent.putExtra("minute", minute)
|
intent.putExtra("minute", minute)
|
||||||
context.startService(intent)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import io.legado.app.base.BaseViewModel
|
import io.legado.app.base.BaseViewModel
|
||||||
import io.legado.app.constant.AppConst
|
import io.legado.app.constant.AppConst
|
||||||
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.constant.AppPattern
|
import io.legado.app.constant.AppPattern
|
||||||
import io.legado.app.constant.EventBus
|
import io.legado.app.constant.EventBus
|
||||||
import io.legado.app.constant.PreferKey
|
import io.legado.app.constant.PreferKey
|
||||||
@ -90,23 +91,30 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
|||||||
searchCallback = null
|
searchCallback = null
|
||||||
}
|
}
|
||||||
}.map {
|
}.map {
|
||||||
searchBooks.sortedWith { o1, o2 ->
|
kotlin.runCatching {
|
||||||
val o1bs = SourceConfig.getBookScore(o1.origin, o1.name, o1.author)
|
searchBooks.sortedWith { o1, o2 ->
|
||||||
val o2bs = SourceConfig.getBookScore(o2.origin, o2.name, o2.author)
|
val o1bs = SourceConfig.getBookScore(o1.origin, o1.name, o1.author)
|
||||||
when {
|
val o2bs = SourceConfig.getBookScore(o2.origin, o2.name, o2.author)
|
||||||
o1bs - o2bs > 0 -> -1
|
when {
|
||||||
o1bs - o2bs < 0 -> 1
|
o1bs - o2bs > 0 -> -1
|
||||||
else -> {
|
o1bs - o2bs < 0 -> 1
|
||||||
val o1ss = SourceConfig.getSourceScore(o1.origin)
|
else -> {
|
||||||
val o2ss = SourceConfig.getSourceScore(o2.origin)
|
val o1ss = SourceConfig.getSourceScore(o1.origin)
|
||||||
when {
|
val o2ss = SourceConfig.getSourceScore(o2.origin)
|
||||||
o1ss - o2ss > 0 -> -1
|
when {
|
||||||
o1ss - o2ss < 0 -> 1
|
o1ss - o2ss > 0 -> -1
|
||||||
else -> o1.originOrder - o2.originOrder
|
o1ss - o2ss < 0 -> 1
|
||||||
|
else -> {
|
||||||
|
val n = o1.originOrder - o2.originOrder
|
||||||
|
if (n == 0) -1 else n
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}.onFailure {
|
||||||
|
AppLog.put("换源排序出错\n${it.localizedMessage}", it)
|
||||||
|
}.getOrDefault(searchBooks)
|
||||||
}.flowOn(IO)
|
}.flowOn(IO)
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
|
@ -43,7 +43,7 @@ inline fun <reified A : Activity> Context.startActivity(configIntent: Intent.()
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified T : Service> Context.startService(configIntent: Intent.() -> Unit = {}) {
|
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() {
|
inline fun <reified T : Service> Context.stopService() {
|
||||||
|
Loading…
Reference in New Issue
Block a user