Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Dec 27, 2024
1 parent 8ccd050 commit 94ef331
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,15 @@ class AnalyzeUrl(
fun setBody(value: String?) {
body = when {
value.isNullOrBlank() -> null
value.isJsonObject() -> GSON.fromJsonObject<Map<String, Any>>(value)
value.isJsonArray() -> GSON.fromJsonArray<Map<String, Any>>(value)
value.isJsonObject() -> GSON.fromJsonObject<Map<String, Any>>(value).getOrNull()
value.isJsonArray() -> GSON.fromJsonArray<Map<String, Any>>(value).getOrNull()
else -> value
}
}

fun getBody(): String? {
return body?.let {
if (it is String) it else GSON.toJson(it)
it as? String ?: GSON.toJson(it)
}
}

Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/io/legado/app/service/AudioPlayService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.legado.app.constant.NotificationId
import io.legado.app.constant.Status
import io.legado.app.help.MediaHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.exoplayer.ExoPlayerHelper
import io.legado.app.help.glide.ImageLoader
import io.legado.app.model.AudioPlay
Expand Down Expand Up @@ -109,6 +110,7 @@ class AudioPlayService : BaseService(),
private var needResumeOnAudioFocusGain = false
private var position = AudioPlay.book?.durChapterPos ?: 0
private var dsJob: Job? = null
private var upNotificationJob: Coroutine<*>? = null
private var upPlayProgressJob: Job? = null
private var playSpeed: Float = 1f
private var cover: Bitmap =
Expand Down Expand Up @@ -196,6 +198,9 @@ class AudioPlayService : BaseService(),
AudioPlay.status = Status.STOP
postEvent(EventBus.AUDIO_STATE, Status.STOP)
AudioPlay.unregisterService()
upNotificationJob?.invokeOnCompletion {
notificationManager.cancel(NotificationId.AudioPlayService)
}
}

/**
Expand Down Expand Up @@ -602,7 +607,7 @@ class AudioPlayService : BaseService(),
}

private fun upAudioPlayNotification() {
execute {
upNotificationJob = execute {
try {
val notification = createNotification()
notificationManager.notify(NotificationId.AudioPlayService, notification.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import io.legado.app.constant.PreferKey
import io.legado.app.constant.Status
import io.legado.app.help.MediaHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.glide.ImageLoader
import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat
Expand Down Expand Up @@ -123,6 +124,7 @@ abstract class BaseReadAloudService : BaseService(),
private var needResumeOnCallStateIdle = false
private var registeredPhoneStateListener = false
private var dsJob: Job? = null
private var upNotificationJob: Coroutine<*>? = null
private var cover: Bitmap =
BitmapFactory.decodeResource(appCtx.resources, R.drawable.icon_read_book)
var pageChanged = false
Expand Down Expand Up @@ -198,6 +200,9 @@ abstract class BaseReadAloudService : BaseService(),
mediaSessionCompat.release()
ReadBook.uploadProgress()
unregisterPhoneStateListener(phoneStateListener)
upNotificationJob?.invokeOnCompletion {
notificationManager.cancel(NotificationId.ReadAloudService)
}
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Expand Down Expand Up @@ -504,7 +509,7 @@ abstract class BaseReadAloudService : BaseService(),
}

private fun upReadAloudNotification() {
execute {
upNotificationJob = execute {
try {
val notification = createNotification()
notificationManager.notify(NotificationId.ReadAloudService, notification.build())
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/legado/app/utils/LogUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object LogUtils {
}

val logger: Logger by lazy {
Logger.getLogger("Leagdo").apply {
Logger.getLogger("Legado").apply {
fileHandler?.let {
addHandler(it)
}
Expand Down

0 comments on commit 94ef331

Please sign in to comment.