pull/1352/head
gedoor 3 years ago
parent 9e1ed46a22
commit 07796a80c3
  1. 2
      app/src/main/java/io/legado/app/constant/AppLog.kt
  2. 2
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  3. 2
      app/src/main/java/io/legado/app/model/BookRead.kt
  4. 2
      app/src/main/java/io/legado/app/model/CacheBook.kt
  5. 4
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  6. 2
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  7. 2
      app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt
  8. 4
      app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt
  9. 2
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -5,7 +5,7 @@ object AppLog {
val logs = arrayListOf<Triple<Long, String, Throwable?>>() val logs = arrayListOf<Triple<Long, String, Throwable?>>()
@Synchronized @Synchronized
fun addLog(message: String?, throwable: Throwable? = null) { fun put(message: String?, throwable: Throwable? = null) {
message ?: return message ?: return
if (logs.size > 100) { if (logs.size > 100) {
logs.removeLastOrNull() logs.removeLastOrNull()

@ -72,7 +72,7 @@ class ContentProcessor private constructor(
val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s|\\p{P})+".toRegex() val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s|\\p{P})+".toRegex()
mContent = mContent.replace(titleRegex, "") mContent = mContent.replace(titleRegex, "")
} catch (e: Exception) { } catch (e: Exception) {
AppLog.addLog("去除重复标题出错\n${e.localizedMessage}", e) AppLog.put("去除重复标题出错\n${e.localizedMessage}", e)
} }
//重新添加标题 //重新添加标题
mContent = chapter.getDisplayTitle() + "\n" + mContent mContent = chapter.getDisplayTitle() + "\n" + mContent

@ -259,7 +259,7 @@ object BookRead : CoroutineScope by MainScope() {
} ?: removeLoading(index) } ?: removeLoading(index)
}.onError { }.onError {
removeLoading(index) removeLoading(index)
AppLog.addLog("加载正文出错\n${it.localizedMessage}") AppLog.put("加载正文出错\n${it.localizedMessage}")
} }
} }
} }

@ -173,7 +173,7 @@ object CacheBook {
if (errorDownloadMap[index] ?: 0 < 3) { if (errorDownloadMap[index] ?: 0 < 3) {
waitDownloadSet.add(index) waitDownloadSet.add(index)
} else { } else {
AppLog.addLog( AppLog.put(
"下载${book.name}-${chapterTitle}失败\n${error.localizedMessage}", "下载${book.name}-${chapterTitle}失败\n${error.localizedMessage}",
error error
) )

@ -42,7 +42,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
val keycode: Int = keyEvent.keyCode val keycode: Int = keyEvent.keyCode
val action: Int = keyEvent.action val action: Int = keyEvent.action
if (action == KeyEvent.ACTION_DOWN) { if (action == KeyEvent.ACTION_DOWN) {
AppLog.addLog("mediaButton $action") AppLog.put("mediaButton $action")
when (keycode) { when (keycode) {
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> { KeyEvent.KEYCODE_MEDIA_PREVIOUS -> {
if (context.getPrefBoolean("mediaButtonPerNext", false)) { if (context.getPrefBoolean("mediaButtonPerNext", false)) {
@ -88,7 +88,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) -> LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true) postEvent(EventBus.MEDIA_BUTTON, true)
else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) { else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) {
AppLog.addLog("readAloud start Service") AppLog.put("readAloud start Service")
if (BookRead.book != null) { if (BookRead.book != null) {
BookRead.readAloud() BookRead.readAloud()
} else { } else {

@ -264,7 +264,7 @@ class HttpReadAloudService : BaseReadAloudService(),
play() play()
return true return true
} }
AppLog.addLog("朗读错误,($what, $extra)") AppLog.put("朗读错误,($what, $extra)")
errorNo++ errorNo++
if (errorNo >= 5) { if (errorNo >= 5) {
toastOnUi("朗读连续3次错误, 最后一次错误代码($what, $extra)") toastOnUi("朗读连续3次错误, 最后一次错误代码($what, $extra)")

@ -28,7 +28,7 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application)
}.onSuccess { }.onSuccess {
success.invoke(it) success.invoke(it)
}.onError { }.onError {
AppLog.addLog("上传文件失败\n${it.localizedMessage}", it) AppLog.put("上传文件失败\n${it.localizedMessage}", it)
it.printOnDebug() it.printOnDebug()
errorLiveData.postValue(it.localizedMessage) errorLiveData.postValue(it.localizedMessage)
} }

@ -11,6 +11,7 @@ import androidx.core.view.setPadding
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.AppLog
import io.legado.app.data.entities.BaseSource import io.legado.app.data.entities.BaseSource
import io.legado.app.databinding.DialogLoginBinding import io.legado.app.databinding.DialogLoginBinding
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
@ -129,8 +130,9 @@ class RuleUiLoginDialog : BaseDialogFragment() {
dismiss() dismiss()
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printOnDebug() AppLog.put("登录出错\n${e.localizedMessage}", e)
toastOnUi("error:${e.localizedMessage}") toastOnUi("error:${e.localizedMessage}")
e.printOnDebug()
} }
} }
} }

@ -125,7 +125,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
appDb.bookChapterDao.insert(*toc.toTypedArray()) appDb.bookChapterDao.insert(*toc.toTypedArray())
addDownload(source, book) addDownload(source, book)
}.onError(upTocPool) { }.onError(upTocPool) {
AppLog.addLog("${book.name} 更新目录失败\n${it.localizedMessage}", it) AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it)
it.printOnDebug() it.printOnDebug()
}.onCancel(upTocPool) { }.onCancel(upTocPool) {
upTocCancel(book.bookUrl) upTocCancel(book.bookUrl)

Loading…
Cancel
Save