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-12 11:40:44 +08:00
|
|
|
|
import android.text.TextUtils
|
2025-12-11 21:05:04 +08:00
|
|
|
|
import android.view.View
|
|
|
|
|
|
import com.blankj.utilcode.util.ActivityUtils
|
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-12 10:32:35 +08:00
|
|
|
|
import com.xscm.modulemain.activity.room.activity.RoomActivity
|
2025-12-08 19:08:07 +08:00
|
|
|
|
import com.xscm.modulemain.dialog.InviteDialog
|
2025-12-11 21:05:04 +08:00
|
|
|
|
import com.xscm.modulemain.manager.RoomManager
|
|
|
|
|
|
import com.xscm.modulemain.utils.TimerManager
|
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
|
2025-12-11 21:05:04 +08:00
|
|
|
|
import com.xscm.moduleutil.bean.RoomMessageEvent
|
|
|
|
|
|
import com.xscm.moduleutil.dialog.ConfirmDialog
|
2025-12-08 19:08:07 +08:00
|
|
|
|
import com.xscm.moduleutil.http.BaseObserver
|
|
|
|
|
|
import com.xscm.moduleutil.http.RetrofitClient
|
2025-12-11 21:05:04 +08:00
|
|
|
|
import com.xscm.moduleutil.listener.MessageListenerSingleton
|
|
|
|
|
|
import com.xscm.moduleutil.utils.CustomMsgCode
|
2025-12-08 19:08:07 +08:00
|
|
|
|
import io.reactivex.disposables.Disposable
|
2025-12-11 21:05:04 +08:00
|
|
|
|
import org.json.JSONObject
|
|
|
|
|
|
import java.util.concurrent.TimeUnit
|
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-12 11:40:44 +08:00
|
|
|
|
var currDialogActivity: Activity? = 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-12-12 16:02:42 +08:00
|
|
|
|
APP_CONENT = getExternalFilesDir("APP_CONTENT")?.absolutePath.toString()
|
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()
|
|
|
|
|
|
// 初始化单例实例
|
|
|
|
|
|
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-10 09:50:18 +08:00
|
|
|
|
|
2025-12-11 21:05:04 +08:00
|
|
|
|
initImMsg()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun initImMsg() {
|
|
|
|
|
|
MessageListenerSingleton.getInstance().setOnMsgTaskListener { event ->
|
|
|
|
|
|
when (event.msgType) {
|
|
|
|
|
|
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM -> {
|
|
|
|
|
|
TimerManager.cancelTimer(CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM_TIMER_ID)
|
2025-12-12 11:40:44 +08:00
|
|
|
|
try {
|
|
|
|
|
|
val json = JSONObject(event.text.text)
|
|
|
|
|
|
if (!json.isNull("status")) {
|
|
|
|
|
|
event.text.status = json.getString("status")
|
2025-12-11 21:05:04 +08:00
|
|
|
|
}
|
2025-12-12 11:40:44 +08:00
|
|
|
|
if (TextUtils.isEmpty(event.text.status))
|
|
|
|
|
|
return@setOnMsgTaskListener
|
|
|
|
|
|
when (event.text.status) {
|
|
|
|
|
|
"1" -> {//1:邀请
|
|
|
|
|
|
if (!json.isNull("room_id"))
|
|
|
|
|
|
event.text.room_id = json.getString("room_id")
|
|
|
|
|
|
if (event?.text?.room_id.isNullOrEmpty())
|
|
|
|
|
|
return@setOnMsgTaskListener
|
|
|
|
|
|
customDialog(
|
|
|
|
|
|
event.text.room_id,
|
|
|
|
|
|
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM_MSG,
|
|
|
|
|
|
5,
|
|
|
|
|
|
1,
|
|
|
|
|
|
event.text
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
"2" -> {//2:拒绝
|
|
|
|
|
|
customDialog(
|
|
|
|
|
|
"",
|
|
|
|
|
|
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM_MSG_REFUSE,
|
|
|
|
|
|
5,
|
|
|
|
|
|
3,
|
|
|
|
|
|
null,
|
|
|
|
|
|
"",
|
|
|
|
|
|
"知道了"
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
2025-12-11 21:05:04 +08:00
|
|
|
|
}
|
2025-12-12 11:40:44 +08:00
|
|
|
|
}catch (E: Exception){
|
|
|
|
|
|
LogUtils.e("Exception",E.message.toString())
|
2025-12-11 21:05:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun customDialog(
|
|
|
|
|
|
roomId: String,
|
|
|
|
|
|
message: String,
|
|
|
|
|
|
downCount: Int,
|
|
|
|
|
|
status: Int = 1,
|
|
|
|
|
|
event: RoomMessageEvent.T?,
|
|
|
|
|
|
confirm: String = "同意",
|
|
|
|
|
|
cancel: String = "拒绝",
|
|
|
|
|
|
) {
|
|
|
|
|
|
// 创建并显示确认对话框
|
|
|
|
|
|
ConfirmDialog(
|
|
|
|
|
|
ActivityUtils.getTopActivity(),
|
|
|
|
|
|
"提示",
|
|
|
|
|
|
message,
|
|
|
|
|
|
confirm,
|
|
|
|
|
|
cancel,
|
|
|
|
|
|
{ v: View? ->
|
|
|
|
|
|
when (status) {
|
|
|
|
|
|
1 -> {
|
2025-12-12 11:40:44 +08:00
|
|
|
|
if (!TextUtils.isEmpty(CommonAppContext.getInstance().playId)
|
|
|
|
|
|
&& roomId == CommonAppContext.getInstance().playId
|
|
|
|
|
|
&& ActivityUtils.getTopActivity() is RoomActivity
|
|
|
|
|
|
) {
|
2025-12-12 10:32:35 +08:00
|
|
|
|
return@ConfirmDialog
|
2025-12-12 11:40:44 +08:00
|
|
|
|
}
|
2025-12-12 10:32:35 +08:00
|
|
|
|
|
2025-12-12 11:40:44 +08:00
|
|
|
|
if (ActivityUtils.getTopActivity() is RoomActivity) {
|
2025-12-12 10:32:35 +08:00
|
|
|
|
(ActivityUtils.getTopActivity() as RoomActivity).refreshRoomInfo(roomId)
|
2025-12-11 21:05:04 +08:00
|
|
|
|
return@ConfirmDialog
|
2025-12-12 10:32:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-11 21:05:04 +08:00
|
|
|
|
RoomManager.getInstance()
|
|
|
|
|
|
.fetchRoomDataAndEnter(ActivityUtils.getTopActivity(), roomId, "", "")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{ v: View? ->
|
|
|
|
|
|
when (status) {
|
|
|
|
|
|
1 -> {
|
|
|
|
|
|
val text = RoomMessageEvent.T()
|
|
|
|
|
|
val json = JSONObject()
|
|
|
|
|
|
json.put("status", "2")
|
2025-12-12 10:32:35 +08:00
|
|
|
|
json.put("room_id", roomId)
|
2025-12-11 21:05:04 +08:00
|
|
|
|
text.text = json.toString()
|
|
|
|
|
|
MessageListenerSingleton.getInstance().sendCustomC2CMessage(
|
|
|
|
|
|
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM,
|
|
|
|
|
|
event?.fromUserInfo?.user_id.toString(),
|
|
|
|
|
|
text
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}, true, downCount
|
|
|
|
|
|
).show()
|
|
|
|
|
|
}
|
2025-12-10 14:54:06 +08:00
|
|
|
|
|
2025-12-11 21:05:04 +08:00
|
|
|
|
fun inviteApprenticeTaskTimer() {
|
|
|
|
|
|
TimerManager.scheduleTimer(
|
|
|
|
|
|
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM_TIMER_ID,
|
2025-12-12 11:40:44 +08:00
|
|
|
|
20,
|
2025-12-11 21:05:04 +08:00
|
|
|
|
TimeUnit.SECONDS,
|
|
|
|
|
|
onTimeUp = {
|
|
|
|
|
|
customDialog(
|
|
|
|
|
|
"",
|
|
|
|
|
|
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM_MSG_REFUSE,
|
|
|
|
|
|
5,
|
|
|
|
|
|
3,
|
|
|
|
|
|
null,
|
2025-12-12 10:32:35 +08:00
|
|
|
|
"",
|
|
|
|
|
|
"知道了"
|
2025-12-11 21:05:04 +08:00
|
|
|
|
)
|
|
|
|
|
|
})
|
2025-12-10 14:54:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun bgToForeground() {
|
2025-12-08 19:08:07 +08:00
|
|
|
|
AppUtils.registerAppStatusChangedListener(object : Utils.OnAppStatusChangedListener {
|
|
|
|
|
|
override fun onForeground(activity: Activity?) {//应用切换到前台
|
2025-12-10 14:54:06 +08:00
|
|
|
|
if (!CommonAppContext.getInstance().isPlaying) {
|
2025-12-08 19:08:07 +08:00
|
|
|
|
RetrofitClient.getInstance()
|
|
|
|
|
|
.index_recommend_room(object : BaseObserver<IndexRecommendRoom>() {
|
|
|
|
|
|
override fun onSubscribe(d: Disposable) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onNext(t: IndexRecommendRoom) {
|
2025-12-11 21:04:25 +08:00
|
|
|
|
LogUtils.e(t)
|
2025-12-10 11:15:32 +08:00
|
|
|
|
if (!t.room_id.isNullOrEmpty()) {
|
2025-12-11 21:05:04 +08:00
|
|
|
|
showInviteDialog(activity, t)
|
2025-12-08 19:08:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onBackground(activity: Activity?) {//应用切换到后台
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
})
|
2025-11-11 10:48:20 +08:00
|
|
|
|
}
|
2025-11-04 16:39:10 +08:00
|
|
|
|
|
2025-12-11 21:05:04 +08:00
|
|
|
|
fun showInviteDialog(activity: Activity?, t: IndexRecommendRoom) {
|
2025-12-12 09:17:05 +08:00
|
|
|
|
if (activity != null && activity == currDialogActivity && inviteDialog != null) {
|
|
|
|
|
|
inviteDialog?.setData(t)
|
|
|
|
|
|
return
|
2025-12-10 15:30:34 +08:00
|
|
|
|
}
|
2025-12-12 09:17:05 +08:00
|
|
|
|
inviteDialog?.dismiss()
|
|
|
|
|
|
inviteDialog = null
|
|
|
|
|
|
|
|
|
|
|
|
inviteDialog = activity?.let { InviteDialog(it, t) }
|
2025-12-10 15:30:34 +08:00
|
|
|
|
inviteDialog?.setData(t)
|
2025-12-12 09:17:05 +08:00
|
|
|
|
currDialogActivity = activity
|
2025-12-10 15:30:34 +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
|
|
|
|
}
|