mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
483ed9455a
commit
6b5c32a3db
@ -10,6 +10,7 @@ import android.content.res.Configuration
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import com.github.liuyueyi.quick.transfer.constants.TransType
|
import com.github.liuyueyi.quick.transfer.constants.TransType
|
||||||
import com.jeremyliao.liveeventbus.LiveEventBus
|
import com.jeremyliao.liveeventbus.LiveEventBus
|
||||||
|
import com.jeremyliao.liveeventbus.logger.DefaultLogger
|
||||||
import io.legado.app.base.AppContextWrapper
|
import io.legado.app.base.AppContextWrapper
|
||||||
import io.legado.app.constant.AppConst.channelIdDownload
|
import io.legado.app.constant.AppConst.channelIdDownload
|
||||||
import io.legado.app.constant.AppConst.channelIdReadAloud
|
import io.legado.app.constant.AppConst.channelIdReadAloud
|
||||||
@ -40,6 +41,7 @@ import splitties.init.appCtx
|
|||||||
import splitties.systemservices.notificationManager
|
import splitties.systemservices.notificationManager
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
import java.util.logging.Level
|
||||||
|
|
||||||
class App : Application() {
|
class App : Application() {
|
||||||
|
|
||||||
@ -57,6 +59,7 @@ class App : Application() {
|
|||||||
.lifecycleObserverAlwaysActive(true)
|
.lifecycleObserverAlwaysActive(true)
|
||||||
.autoClear(false)
|
.autoClear(false)
|
||||||
.enableLogger(BuildConfig.DEBUG || AppConfig.recordLog)
|
.enableLogger(BuildConfig.DEBUG || AppConfig.recordLog)
|
||||||
|
.setLogger(EventLogger())
|
||||||
applyDayNight(this)
|
applyDayNight(this)
|
||||||
registerActivityLifecycleCallbacks(LifecycleHelp)
|
registerActivityLifecycleCallbacks(LifecycleHelp)
|
||||||
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
|
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
|
||||||
@ -178,4 +181,21 @@ class App : Application() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EventLogger : DefaultLogger() {
|
||||||
|
|
||||||
|
override fun log(level: Level, msg: String) {
|
||||||
|
super.log(level, msg)
|
||||||
|
LogUtils.d(TAG, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun log(level: Level, msg: String, th: Throwable?) {
|
||||||
|
super.log(level, msg, th)
|
||||||
|
LogUtils.d(TAG, "$msg\n${th?.stackTraceToString()}")
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "[LiveEventBus]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,9 @@ abstract class BaseService : LifecycleService() {
|
|||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
LogUtils.d(simpleName, "onStartCommand $intent")
|
LogUtils.d(simpleName) {
|
||||||
|
"onStartCommand $intent ${intent?.toUri(0)}"
|
||||||
|
}
|
||||||
startForegroundNotification()
|
startForegroundNotification()
|
||||||
return super.onStartCommand(intent, flags, startId)
|
return super.onStartCommand(intent, flags, startId)
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,8 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
* 朗读
|
* 朗读
|
||||||
*/
|
*/
|
||||||
fun readAloud(play: Boolean = true, startPos: Int = 0) {
|
fun readAloud(play: Boolean = true, startPos: Int = 0) {
|
||||||
book?.let {
|
book ?: return
|
||||||
|
if (isLayoutAvailable) {
|
||||||
ReadAloud.play(appCtx, play, startPos = startPos)
|
ReadAloud.play(appCtx, play, startPos = startPos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,9 +188,9 @@ data class TextChapter(
|
|||||||
pageSplit: Boolean,
|
pageSplit: Boolean,
|
||||||
): Int {
|
): Int {
|
||||||
val paragraphs = if (pageSplit) {
|
val paragraphs = if (pageSplit) {
|
||||||
pageParagraphs
|
if (isCompleted) pageParagraphs else pageParagraphsInternal
|
||||||
} else {
|
} else {
|
||||||
paragraphs
|
if (isCompleted) paragraphs else pageParagraphsInternal
|
||||||
}
|
}
|
||||||
paragraphs.forEach { paragraph ->
|
paragraphs.forEach { paragraph ->
|
||||||
if (position in paragraph.chapterIndices) {
|
if (position in paragraph.chapterIndices) {
|
||||||
|
@ -25,12 +25,18 @@ object LogUtils {
|
|||||||
logger.log(Level.INFO, "$tag $msg")
|
logger.log(Level.INFO, "$tag $msg")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun d(tag: String, lazyMsg: () -> String) {
|
||||||
|
if (logger.isLoggable(Level.INFO)) {
|
||||||
|
logger.log(Level.INFO, "$tag ${lazyMsg()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun e(tag: String, msg: String) {
|
fun e(tag: String, msg: String) {
|
||||||
logger.log(Level.WARNING, "$tag $msg")
|
logger.log(Level.WARNING, "$tag $msg")
|
||||||
}
|
}
|
||||||
|
|
||||||
private val logger: Logger by lazy {
|
val logger: Logger by lazy {
|
||||||
Logger.getGlobal().apply {
|
Logger.getGlobal().apply {
|
||||||
fileHandler?.let {
|
fileHandler?.let {
|
||||||
addHandler(it)
|
addHandler(it)
|
||||||
|
Loading…
Reference in New Issue
Block a user