From 07796a80c30b2427383df6dc7219b4043500b344 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 30 Sep 2021 14:19:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/AppLog.kt | 2 +- app/src/main/java/io/legado/app/help/ContentProcessor.kt | 2 +- app/src/main/java/io/legado/app/model/BookRead.kt | 2 +- app/src/main/java/io/legado/app/model/CacheBook.kt | 2 +- .../main/java/io/legado/app/receiver/MediaButtonReceiver.kt | 4 ++-- .../main/java/io/legado/app/service/HttpReadAloudService.kt | 2 +- .../java/io/legado/app/ui/document/HandleFileViewModel.kt | 2 +- app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt | 4 +++- app/src/main/java/io/legado/app/ui/main/MainViewModel.kt | 2 +- 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/AppLog.kt b/app/src/main/java/io/legado/app/constant/AppLog.kt index 8a175fb2a..c20e64dd4 100644 --- a/app/src/main/java/io/legado/app/constant/AppLog.kt +++ b/app/src/main/java/io/legado/app/constant/AppLog.kt @@ -5,7 +5,7 @@ object AppLog { val logs = arrayListOf>() @Synchronized - fun addLog(message: String?, throwable: Throwable? = null) { + fun put(message: String?, throwable: Throwable? = null) { message ?: return if (logs.size > 100) { logs.removeLastOrNull() diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 6aa2566c7..19df6b6f7 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -72,7 +72,7 @@ class ContentProcessor private constructor( val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s|\\p{P})+".toRegex() mContent = mContent.replace(titleRegex, "") } catch (e: Exception) { - AppLog.addLog("去除重复标题出错\n${e.localizedMessage}", e) + AppLog.put("去除重复标题出错\n${e.localizedMessage}", e) } //重新添加标题 mContent = chapter.getDisplayTitle() + "\n" + mContent diff --git a/app/src/main/java/io/legado/app/model/BookRead.kt b/app/src/main/java/io/legado/app/model/BookRead.kt index d7b0404e5..8121e3a78 100644 --- a/app/src/main/java/io/legado/app/model/BookRead.kt +++ b/app/src/main/java/io/legado/app/model/BookRead.kt @@ -259,7 +259,7 @@ object BookRead : CoroutineScope by MainScope() { } ?: removeLoading(index) }.onError { removeLoading(index) - AppLog.addLog("加载正文出错\n${it.localizedMessage}") + AppLog.put("加载正文出错\n${it.localizedMessage}") } } } diff --git a/app/src/main/java/io/legado/app/model/CacheBook.kt b/app/src/main/java/io/legado/app/model/CacheBook.kt index 196ae8dba..2b32d2e47 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -173,7 +173,7 @@ object CacheBook { if (errorDownloadMap[index] ?: 0 < 3) { waitDownloadSet.add(index) } else { - AppLog.addLog( + AppLog.put( "下载${book.name}-${chapterTitle}失败\n${error.localizedMessage}", error ) diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 71ae2835e..728b24770 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -42,7 +42,7 @@ class MediaButtonReceiver : BroadcastReceiver() { val keycode: Int = keyEvent.keyCode val action: Int = keyEvent.action if (action == KeyEvent.ACTION_DOWN) { - AppLog.addLog("mediaButton $action") + AppLog.put("mediaButton $action") when (keycode) { KeyEvent.KEYCODE_MEDIA_PREVIOUS -> { if (context.getPrefBoolean("mediaButtonPerNext", false)) { @@ -88,7 +88,7 @@ class MediaButtonReceiver : BroadcastReceiver() { LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) -> postEvent(EventBus.MEDIA_BUTTON, true) else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) { - AppLog.addLog("readAloud start Service") + AppLog.put("readAloud start Service") if (BookRead.book != null) { BookRead.readAloud() } else { diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index dc53d62b7..751c4fb2e 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -264,7 +264,7 @@ class HttpReadAloudService : BaseReadAloudService(), play() return true } - AppLog.addLog("朗读错误,($what, $extra)") + AppLog.put("朗读错误,($what, $extra)") errorNo++ if (errorNo >= 5) { toastOnUi("朗读连续3次错误, 最后一次错误代码($what, $extra)") diff --git a/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt b/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt index 37fb436f8..11b50dfd7 100644 --- a/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt @@ -28,7 +28,7 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application) }.onSuccess { success.invoke(it) }.onError { - AppLog.addLog("上传文件失败\n${it.localizedMessage}", it) + AppLog.put("上传文件失败\n${it.localizedMessage}", it) it.printOnDebug() errorLiveData.postValue(it.localizedMessage) } diff --git a/app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt b/app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt index b7787f557..f7a98e20c 100644 --- a/app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt +++ b/app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt @@ -11,6 +11,7 @@ import androidx.core.view.setPadding import androidx.fragment.app.activityViewModels import io.legado.app.R import io.legado.app.base.BaseDialogFragment +import io.legado.app.constant.AppLog import io.legado.app.data.entities.BaseSource import io.legado.app.databinding.DialogLoginBinding import io.legado.app.lib.theme.primaryColor @@ -129,8 +130,9 @@ class RuleUiLoginDialog : BaseDialogFragment() { dismiss() } } catch (e: Exception) { - e.printOnDebug() + AppLog.put("登录出错\n${e.localizedMessage}", e) toastOnUi("error:${e.localizedMessage}") + e.printOnDebug() } } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 773163d17..b91451a63 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -125,7 +125,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) { appDb.bookChapterDao.insert(*toc.toTypedArray()) addDownload(source, book) }.onError(upTocPool) { - AppLog.addLog("${book.name} 更新目录失败\n${it.localizedMessage}", it) + AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it) it.printOnDebug() }.onCancel(upTocPool) { upTocCancel(book.bookUrl)