This commit is contained in:
Horis
2025-04-28 21:43:28 +08:00
parent f3aad3c4af
commit 1d3dfd2da1
4 changed files with 10 additions and 9 deletions
@@ -127,17 +127,18 @@ class AudioPlayService : BaseService(),
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
doDs() doDs()
execute { execute {
@Suppress("BlockingMethodInNonBlockingContext")
ImageLoader ImageLoader
.loadBitmap(this@AudioPlayService, AudioPlay.book?.getDisplayCover()) .loadBitmap(this@AudioPlayService, AudioPlay.book?.getDisplayCover())
.submit() .submit()
.get() .get()
}.onSuccess { }.onSuccess {
if (it.width > 16 && it.height > 16) {
cover = it cover = it
upMediaMetadata() upMediaMetadata()
upAudioPlayNotification() upAudioPlayNotification()
} }
} }
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
intent?.action?.let { action -> intent?.action?.let { action ->
@@ -156,16 +156,17 @@ abstract class BaseReadAloudService : BaseService(),
toastOnUi("朗读定时 ${AppConfig.ttsTimer} 分钟") toastOnUi("朗读定时 ${AppConfig.ttsTimer} 分钟")
} }
execute { execute {
@Suppress("BlockingMethodInNonBlockingContext")
ImageLoader ImageLoader
.loadBitmap(this@BaseReadAloudService, ReadBook.book?.getDisplayCover()) .loadBitmap(this@BaseReadAloudService, ReadBook.book?.getDisplayCover())
.submit() .submit()
.get() .get()
}.onSuccess { }.onSuccess {
if (it.width > 16 && it.height > 16) {
cover = it cover = it
upReadAloudNotification() upReadAloudNotification()
} }
} }
}
fun observeLiveBus() { fun observeLiveBus() {
observeEvent<Bundle>(EventBus.READ_ALOUD_PLAY) { observeEvent<Bundle>(EventBus.READ_ALOUD_PLAY) {
@@ -500,7 +500,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
/** /**
* 保存图片 * 保存图片
*/ */
@Suppress("BlockingMethodInNonBlockingContext")
fun saveImage(src: String?, uri: Uri) { fun saveImage(src: String?, uri: Uri) {
src ?: return src ?: return
val book = ReadBook.book ?: return val book = ReadBook.book ?: return
@@ -156,7 +156,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
private fun importBookshelfByJson(json: String, groupId: Long) { private fun importBookshelfByJson(json: String, groupId: Long) {
execute { execute {
val bookSourceParts = appDb.bookSourceDao.allEnabledPart val bookSourceParts = appDb.bookSourceDao.allEnabledPart
val semaphore = Semaphore(AppConfig.threadCount + 1) val semaphore = Semaphore(AppConfig.threadCount)
GSON.fromJsonArray<Map<String, String?>>(json).getOrThrow().forEach { bookInfo -> GSON.fromJsonArray<Map<String, String?>>(json).getOrThrow().forEach { bookInfo ->
val name = bookInfo["name"] ?: "" val name = bookInfo["name"] ?: ""
val author = bookInfo["author"] ?: "" val author = bookInfo["author"] ?: ""