2025-10-31 15:18:32 +08:00
|
|
|
|
package com.xscm.modulemain
|
|
|
|
|
|
|
2025-12-08 19:08:07 +08:00
|
|
|
|
import android.app.Activity
|
2025-11-04 16:39:10 +08:00
|
|
|
|
import android.content.Context
|
2025-12-08 19:08:07 +08:00
|
|
|
|
import com.blankj.utilcode.util.AppUtils
|
2025-11-11 10:48:20 +08:00
|
|
|
|
import com.blankj.utilcode.util.CrashUtils
|
2025-11-03 14:16:27 +08:00
|
|
|
|
import com.blankj.utilcode.util.LogUtils
|
2025-12-08 19:08:07 +08:00
|
|
|
|
import com.blankj.utilcode.util.Utils
|
2025-10-31 15:18:32 +08:00
|
|
|
|
import com.opensource.svgaplayer.utils.log.SVGALogger
|
2025-11-04 16:39:10 +08:00
|
|
|
|
import com.scwang.smartrefresh.layout.SmartRefreshLayout
|
|
|
|
|
|
import com.scwang.smartrefresh.layout.footer.ClassicsFooter
|
|
|
|
|
|
import com.scwang.smartrefresh.layout.header.ClassicsHeader
|
2025-12-08 19:08:07 +08:00
|
|
|
|
import com.xscm.modulemain.dialog.InviteDialog
|
2025-10-31 15:18:32 +08:00
|
|
|
|
import com.xscm.modulemain.widget.WheatLayoutSingManager
|
|
|
|
|
|
import com.xscm.moduleutil.base.CommonAppContext
|
2025-12-08 19:08:07 +08:00
|
|
|
|
import com.xscm.moduleutil.bean.IndexRecommendRoom
|
|
|
|
|
|
import com.xscm.moduleutil.http.BaseObserver
|
|
|
|
|
|
import com.xscm.moduleutil.http.RetrofitClient
|
|
|
|
|
|
import io.reactivex.disposables.Disposable
|
2025-10-31 15:18:32 +08:00
|
|
|
|
|
2025-11-04 16:39:10 +08:00
|
|
|
|
|
2025-10-31 15:18:32 +08:00
|
|
|
|
open class Application : CommonAppContext() {
|
|
|
|
|
|
|
2025-11-11 10:48:20 +08:00
|
|
|
|
var APP_CONENT = ""
|
|
|
|
|
|
|
|
|
|
|
|
var LOGUTILS_SAVE_PATH = ""
|
|
|
|
|
|
var CRASHUTILS_SAVE_PATH = ""
|
|
|
|
|
|
|
2025-12-05 21:05:01 +08:00
|
|
|
|
var isAgoraStop = false
|
2025-12-08 19:08:07 +08:00
|
|
|
|
var inviteDialog: InviteDialog? = null
|
2025-12-05 21:05:01 +08:00
|
|
|
|
|
2025-11-11 10:48:20 +08:00
|
|
|
|
// 单例实例
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
@Volatile
|
|
|
|
|
|
private lateinit var instance: Application
|
|
|
|
|
|
|
|
|
|
|
|
// 全局获取 Application 实例
|
|
|
|
|
|
fun getInstance(): Application {
|
|
|
|
|
|
return instance
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取 Application Context(避免内存泄漏)
|
|
|
|
|
|
fun getContext(): Context {
|
|
|
|
|
|
return instance.applicationContext
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-31 15:18:32 +08:00
|
|
|
|
override fun onCreate() {
|
|
|
|
|
|
super.onCreate()
|
2025-11-11 10:48:20 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
2025-10-31 15:18:32 +08:00
|
|
|
|
// 初始化并预绘制视图 二卡八列
|
|
|
|
|
|
WheatLayoutSingManager.init(this)
|
2025-11-11 10:48:20 +08:00
|
|
|
|
WheatLayoutSingManager.getInstance().setWheatData(null)
|
2025-10-31 15:18:32 +08:00
|
|
|
|
|
|
|
|
|
|
// 默认情况下,SVGA 内部不会输出任何 log,所以需要手动设置为 true
|
2025-11-03 14:16:27 +08:00
|
|
|
|
SVGALogger.setLogEnabled(false)
|
2025-11-04 16:39:10 +08:00
|
|
|
|
|
2025-11-11 10:48:20 +08:00
|
|
|
|
initLogUtils()
|
|
|
|
|
|
initCrashUtils()
|
|
|
|
|
|
initSmartRefreshLayout()
|
2025-12-09 18:23:54 +08:00
|
|
|
|
if (true)
|
|
|
|
|
|
return
|
2025-12-08 19:08:07 +08:00
|
|
|
|
AppUtils.registerAppStatusChangedListener(object : Utils.OnAppStatusChangedListener {
|
|
|
|
|
|
override fun onForeground(activity: Activity?) {//应用切换到前台
|
|
|
|
|
|
|
|
|
|
|
|
if (!CommonAppContext.getInstance().isPlaying) {
|
|
|
|
|
|
RetrofitClient.getInstance()
|
|
|
|
|
|
.index_recommend_room(object : BaseObserver<IndexRecommendRoom>() {
|
|
|
|
|
|
override fun onSubscribe(d: Disposable) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onNext(t: IndexRecommendRoom) {
|
|
|
|
|
|
if (t != null) {
|
|
|
|
|
|
inviteDialog = activity?.let { InviteDialog(it, t) }
|
|
|
|
|
|
if (inviteDialog?.isShowing == false) {
|
|
|
|
|
|
inviteDialog?.setData(t)
|
|
|
|
|
|
inviteDialog?.show()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onBackground(activity: Activity?) {//应用切换到后台
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
})
|
2025-11-11 10:48:20 +08:00
|
|
|
|
}
|
2025-11-04 16:39:10 +08:00
|
|
|
|
|
2025-11-11 10:48:20 +08:00
|
|
|
|
private fun initLogUtils() {
|
|
|
|
|
|
LogUtils.getConfig()
|
2025-11-12 19:09:21 +08:00
|
|
|
|
.setLogSwitch(true) // 全局开关
|
2025-11-11 10:48:20 +08:00
|
|
|
|
.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() {
|
2025-11-04 16:39:10 +08:00
|
|
|
|
//设置全局的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
|
|
|
|
|
|
}
|
2025-10-31 15:18:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-11 10:48:20 +08:00
|
|
|
|
fun getAppContent(): String {
|
|
|
|
|
|
return APP_CONENT
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-31 15:18:32 +08:00
|
|
|
|
}
|