113 lines
2.9 KiB
Java
113 lines
2.9 KiB
Java
package com.xscm.moduleutil.base;
|
||
|
||
import android.app.Activity;
|
||
|
||
import com.xscm.moduleutil.bean.room.RoomInfoResp;
|
||
|
||
import java.lang.ref.WeakReference;
|
||
/**
|
||
*@author qx
|
||
*@data 2025/9/20
|
||
*@description: 应用状态管理的单例类
|
||
*/
|
||
// 在 common 模块中
|
||
public class AppStateManager implements AppStateListener {
|
||
private static AppStateManager instance;
|
||
private boolean isAppInBackground = true;
|
||
private boolean shouldShowSplash = true;
|
||
private WeakReference<Activity> roomActivityRef;
|
||
private boolean isFloatingWindowVisible = false;
|
||
private boolean isRoomActivityMinimized = false;
|
||
private AppStateManager() {
|
||
// 私有构造函数
|
||
}
|
||
|
||
public static synchronized AppStateManager getInstance() {
|
||
if (instance == null) {
|
||
instance = new AppStateManager();
|
||
}
|
||
return instance;
|
||
}
|
||
|
||
@Override
|
||
public boolean shouldShowSplash() {
|
||
return shouldShowSplash;
|
||
}
|
||
|
||
@Override
|
||
public void setShouldShowSplash(boolean shouldShow) {
|
||
this.shouldShowSplash = shouldShow;
|
||
}
|
||
|
||
@Override
|
||
public boolean isAppInBackground() {
|
||
return isAppInBackground;
|
||
}
|
||
|
||
@Override
|
||
public void setAppInBackground(boolean inBackground) {
|
||
this.isAppInBackground = inBackground;
|
||
}
|
||
|
||
@Override
|
||
public void onRoomActivityCreated(Activity roomActivity) {
|
||
roomActivityRef = new WeakReference<>(roomActivity);
|
||
}
|
||
|
||
@Override
|
||
public void onRoomActivityDestroyed() {
|
||
roomActivityRef = null;
|
||
}
|
||
|
||
@Override
|
||
public boolean isRoomActivityActive() {
|
||
Activity activity = getRoomActivity();
|
||
return activity != null && !activity.isFinishing();
|
||
}
|
||
|
||
private Activity getRoomActivity() {
|
||
return roomActivityRef != null ? roomActivityRef.get() : null;
|
||
}
|
||
|
||
@Override
|
||
public void setFloatingWindowVisible(boolean visible) {
|
||
this.isFloatingWindowVisible = visible;
|
||
}
|
||
|
||
@Override
|
||
public boolean isFloatingWindowVisible() {
|
||
return isFloatingWindowVisible;
|
||
}
|
||
|
||
@Override
|
||
public void onAppForeground() {
|
||
// 应用进入前台时的处理
|
||
setAppInBackground(false);
|
||
}
|
||
|
||
@Override
|
||
public void onAppBackground() {
|
||
// 应用进入后台时的处理
|
||
setAppInBackground(true);
|
||
}
|
||
|
||
// 新增方法:设置RoomActivity为最小化状态
|
||
public void setRoomActivityMinimized(boolean minimized) {
|
||
this.isRoomActivityMinimized = minimized;
|
||
}
|
||
|
||
// 新增方法:检查RoomActivity是否处于最小化状态
|
||
public boolean isRoomActivityMinimized() {
|
||
return isRoomActivityMinimized;
|
||
}
|
||
private RoomInfoResp roomInfoResp;
|
||
public void setRoomInfo(RoomInfoResp roomInfoResp) {
|
||
// 处理RoomInfoResp对象
|
||
this.roomInfoResp = roomInfoResp;
|
||
}
|
||
|
||
public RoomInfoResp getRoomInfo() {
|
||
return roomInfoResp;
|
||
}
|
||
}
|