优化
This commit is contained in:
@@ -28,6 +28,7 @@ import io.legado.app.help.RuleBigDataHelp
|
|||||||
import io.legado.app.help.book.BookHelp
|
import io.legado.app.help.book.BookHelp
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.help.config.ThemeConfig.applyDayNight
|
import io.legado.app.help.config.ThemeConfig.applyDayNight
|
||||||
|
import io.legado.app.help.config.ThemeConfig.initNightMode
|
||||||
import io.legado.app.help.coroutine.Coroutine
|
import io.legado.app.help.coroutine.Coroutine
|
||||||
import io.legado.app.help.http.Cronet
|
import io.legado.app.help.http.Cronet
|
||||||
import io.legado.app.help.http.ObsoleteUrlFactory
|
import io.legado.app.help.http.ObsoleteUrlFactory
|
||||||
@@ -55,27 +56,27 @@ class App : Application() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
CrashHandler(this)
|
CrashHandler(this)
|
||||||
LogUtils.init(this)
|
|
||||||
LogUtils.d("App", "onCreate")
|
|
||||||
if (isDebuggable) {
|
if (isDebuggable) {
|
||||||
ThreadUtils.setThreadAssertsDisabledForTesting(true)
|
ThreadUtils.setThreadAssertsDisabledForTesting(true)
|
||||||
}
|
}
|
||||||
oldConfig = Configuration(resources.configuration)
|
oldConfig = Configuration(resources.configuration)
|
||||||
//预下载Cronet so
|
initNightMode()
|
||||||
Cronet.preDownload()
|
|
||||||
createNotificationChannels()
|
|
||||||
LiveEventBus.config()
|
|
||||||
.lifecycleObserverAlwaysActive(true)
|
|
||||||
.autoClear(false)
|
|
||||||
.enableLogger(BuildConfig.DEBUG || AppConfig.recordLog)
|
|
||||||
.setLogger(EventLogger())
|
|
||||||
applyDayNight(this)
|
|
||||||
registerActivityLifecycleCallbacks(LifecycleHelp)
|
registerActivityLifecycleCallbacks(LifecycleHelp)
|
||||||
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
|
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
|
||||||
DefaultData.upVersion()
|
|
||||||
AppFreezeMonitor.init(this)
|
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
|
LogUtils.init(this@App)
|
||||||
|
LogUtils.d("App", "onCreate")
|
||||||
LogUtils.logDeviceInfo()
|
LogUtils.logDeviceInfo()
|
||||||
|
//预下载Cronet so
|
||||||
|
Cronet.preDownload()
|
||||||
|
createNotificationChannels()
|
||||||
|
LiveEventBus.config()
|
||||||
|
.lifecycleObserverAlwaysActive(true)
|
||||||
|
.autoClear(false)
|
||||||
|
.enableLogger(BuildConfig.DEBUG || AppConfig.recordLog)
|
||||||
|
.setLogger(EventLogger())
|
||||||
|
DefaultData.upVersion()
|
||||||
|
AppFreezeMonitor.init(this@App)
|
||||||
URL.setURLStreamHandlerFactory(ObsoleteUrlFactory(okHttpClient))
|
URL.setURLStreamHandlerFactory(ObsoleteUrlFactory(okHttpClient))
|
||||||
launch { installGmsTlsProvider(appCtx) }
|
launch { installGmsTlsProvider(appCtx) }
|
||||||
RhinoScriptEngine
|
RhinoScriptEngine
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ object ThemeConfig {
|
|||||||
postEvent(EventBus.RECREATE, "")
|
postEvent(EventBus.RECREATE, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initNightMode() {
|
fun initNightMode() {
|
||||||
val targetMode =
|
val targetMode =
|
||||||
if (AppConfig.isNightTheme) {
|
if (AppConfig.isNightTheme) {
|
||||||
AppCompatDelegate.MODE_NIGHT_YES
|
AppCompatDelegate.MODE_NIGHT_YES
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import io.legado.app.BuildConfig
|
|||||||
import io.legado.app.constant.AppConst
|
import io.legado.app.constant.AppConst
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
|
import io.legado.app.help.globalExecutor
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
@@ -26,7 +27,9 @@ object LogUtils {
|
|||||||
val logTimeFormat by lazy { SimpleDateFormat(TIME_PATTERN) }
|
val logTimeFormat by lazy { SimpleDateFormat(TIME_PATTERN) }
|
||||||
|
|
||||||
fun init(context: Context) {
|
fun init(context: Context) {
|
||||||
fileHandler = createFileHandler(context)
|
fileHandler = createFileHandler(context)?.also {
|
||||||
|
logger.addHandler(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -46,11 +49,7 @@ object LogUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val logger: Logger by lazy {
|
val logger: Logger by lazy {
|
||||||
Logger.getLogger("Legado").apply {
|
Logger.getLogger("Legado")
|
||||||
fileHandler?.let {
|
|
||||||
addHandler(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var fileHandler: FileHandler? = null
|
private var fileHandler: FileHandler? = null
|
||||||
@@ -59,10 +58,12 @@ object LogUtils {
|
|||||||
try {
|
try {
|
||||||
val root = context.externalCacheDir ?: return null
|
val root = context.externalCacheDir ?: return null
|
||||||
val logFolder = FileUtils.createFolderIfNotExist(root, "logs")
|
val logFolder = FileUtils.createFolderIfNotExist(root, "logs")
|
||||||
val expiredTime = System.currentTimeMillis() - 7.days.inWholeMilliseconds
|
globalExecutor.execute {
|
||||||
logFolder.listFiles()?.forEach {
|
val expiredTime = System.currentTimeMillis() - 7.days.inWholeMilliseconds
|
||||||
if (it.lastModified() < expiredTime || it.name.endsWith(".lck")) {
|
logFolder.listFiles()?.forEach {
|
||||||
it.delete()
|
if (it.lastModified() < expiredTime || it.name.endsWith(".lck")) {
|
||||||
|
it.delete()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val date = getCurrentDateStr(TIME_PATTERN)
|
val date = getCurrentDateStr(TIME_PATTERN)
|
||||||
|
|||||||
Reference in New Issue
Block a user