103 lines
3.3 KiB
Kotlin
103 lines
3.3 KiB
Kotlin
package com.xscm.modulemain
|
||
|
||
import android.content.Context
|
||
import com.blankj.utilcode.util.CrashUtils
|
||
import com.blankj.utilcode.util.LogUtils
|
||
import com.opensource.svgaplayer.utils.log.SVGALogger
|
||
import com.scwang.smartrefresh.layout.SmartRefreshLayout
|
||
import com.scwang.smartrefresh.layout.footer.ClassicsFooter
|
||
import com.scwang.smartrefresh.layout.header.ClassicsHeader
|
||
import com.xscm.modulemain.widget.WheatLayoutSingManager
|
||
import com.xscm.moduleutil.base.CommonAppContext
|
||
|
||
|
||
open class Application : CommonAppContext() {
|
||
|
||
var APP_CONENT = ""
|
||
|
||
var LOGUTILS_SAVE_PATH = ""
|
||
var CRASHUTILS_SAVE_PATH = ""
|
||
|
||
// 单例实例
|
||
companion object {
|
||
@Volatile
|
||
private lateinit var instance: Application
|
||
|
||
// 全局获取 Application 实例
|
||
fun getInstance(): Application {
|
||
return instance
|
||
}
|
||
|
||
// 获取 Application Context(避免内存泄漏)
|
||
fun getContext(): Context {
|
||
return instance.applicationContext
|
||
}
|
||
}
|
||
|
||
override fun onCreate() {
|
||
super.onCreate()
|
||
LOGUTILS_SAVE_PATH = getExternalFilesDir("APP_CONTENT/APP_LOG")?.absolutePath.toString()
|
||
CRASHUTILS_SAVE_PATH = getExternalFilesDir("APP_CONTENT/APP_CRASH")?.absolutePath.toString()
|
||
getExternalFilesDir("")
|
||
APP_CONENT = getExternalFilesDir("APP_CONTENT")?.absolutePath.toString()
|
||
// 初始化单例实例
|
||
instance = this
|
||
|
||
// 初始化并预绘制视图 二卡八列
|
||
WheatLayoutSingManager.init(this)
|
||
WheatLayoutSingManager.getInstance().setWheatData(null)
|
||
|
||
// 默认情况下,SVGA 内部不会输出任何 log,所以需要手动设置为 true
|
||
SVGALogger.setLogEnabled(false)
|
||
|
||
initLogUtils()
|
||
initCrashUtils()
|
||
initSmartRefreshLayout()
|
||
}
|
||
|
||
private fun initLogUtils() {
|
||
LogUtils.getConfig()
|
||
.setLogSwitch(true) // 全局开关
|
||
.setLog2FileSwitch(true) // 必须设为 true!
|
||
.setDir(LOGUTILS_SAVE_PATH) // 设置有效路径
|
||
.setFileFilter(LogUtils.V); // 允许所有级别
|
||
}
|
||
|
||
|
||
private fun initCrashUtils() {
|
||
CrashUtils.init(CRASHUTILS_SAVE_PATH, object : CrashUtils.OnCrashListener {
|
||
override fun onCrash(crashInfo: CrashUtils.CrashInfo?) {
|
||
LogUtils.e("crash", crashInfo.toString())
|
||
}
|
||
})
|
||
}
|
||
|
||
|
||
private fun initSmartRefreshLayout() {
|
||
//设置全局的Header构建器
|
||
SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, _ ->
|
||
val header = ClassicsHeader(context)
|
||
header.setDrawableSize(20f)
|
||
// header.setFinishDuration(0)
|
||
header.setTextSizeTitle(12f)
|
||
header.setTextSizeTime(10f)
|
||
header
|
||
}
|
||
|
||
//设置全局的Footer构建器
|
||
SmartRefreshLayout.setDefaultRefreshFooterCreator { context, _ ->
|
||
val classicsFooter = ClassicsFooter(context)
|
||
classicsFooter.setDrawableSize(20f)
|
||
// classicsFooter.setFinishDuration(0)
|
||
classicsFooter.setTextSizeTitle(12f)
|
||
//指定为经典Footer,默认是 BallPulseFooter
|
||
classicsFooter
|
||
}
|
||
}
|
||
|
||
fun getAppContent(): String {
|
||
return APP_CONENT
|
||
}
|
||
|
||
|
||
} |