设备(1)

This commit is contained in:
2026-05-18 17:39:30 +08:00
parent a9fb39cfde
commit 45828c7e9b
23 changed files with 895 additions and 67 deletions

View File

@@ -0,0 +1,92 @@
package com.example.defenseapplication.utils
import android.app.Activity
import java.lang.ref.WeakReference
import java.util.Stack
object ActivityManager {
private val activityStack = Stack<WeakReference<Activity>>()
fun addActivity(activity: Activity) {
activityStack.push(WeakReference(activity))
}
fun removeActivity(activity: Activity) {
activityStack.removeIf { it.get() == activity }
}
fun finishActivity(activity: Activity) {
activity.finish()
removeActivity(activity)
}
fun finishAllActivities() {
while (activityStack.isNotEmpty()) {
val activityRef = activityStack.pop()
activityRef.get()?.finish()
}
activityStack.clear()
}
fun finishToActivity(cls: Class<*>) {
val tempStack = Stack<WeakReference<Activity>>()
while (activityStack.isNotEmpty()) {
val activityRef = activityStack.pop()
val activity = activityRef.get()
if (activity != null && activity.javaClass == cls) {
tempStack.push(activityRef)
break
} else if (activity != null) {
activity.finish()
}
}
while (tempStack.isNotEmpty()) {
activityStack.push(tempStack.pop())
}
}
fun finishExceptHome() {
val tempStack = Stack<WeakReference<Activity>>()
var foundHome = false
while (activityStack.isNotEmpty()) {
val activityRef = activityStack.pop()
val activity = activityRef.get()
if (activity != null) {
val className = activity.javaClass.simpleName
if (className == "HomeActivity" || className == "MainActivity") {
tempStack.push(activityRef)
foundHome = true
break
} else {
activity.finish()
}
}
}
if (!foundHome) {
while (tempStack.isNotEmpty()) {
activityStack.push(tempStack.pop())
}
} else {
while (tempStack.isNotEmpty()) {
activityStack.push(tempStack.pop())
}
}
}
fun getCurrentActivity(): Activity? {
if (activityStack.isEmpty()) {
return null
}
return activityStack.peek().get()
}
fun getActivityCount(): Int {
return activityStack.size
}
}

View File

@@ -62,6 +62,19 @@ interface ApiService {
@GET("/app/appMessage/list")
suspend fun getMessage(): GetCodeBean<List<MessageGroup>>
/**
* 获取设备信息
*/
@PUT("/app/updateDeviceInfo")
suspend fun updateDeviceInfo(@Body deviceBean: DeviceBean): GetCodeBean<DeviceBean>
/**
* 获取设备信息
*/
@GET("/app/deviceInfo/{id}")
suspend fun getDeviceInfo(@retrofit2.http.Path("id") id: String): GetCodeBean<DeviceBean>
}

View File

@@ -0,0 +1,30 @@
package com.example.defenseapplication.utils
object DeviceIdEvent {
private val listeners = mutableListOf<DeviceIdListener>()
private var currentDeviceId: String? = null
interface DeviceIdListener {
fun onDeviceIdChanged(deviceId: String)
}
fun addListener(listener: DeviceIdListener) {
if (!listeners.contains(listener)) {
listeners.add(listener)
currentDeviceId?.let { listener.onDeviceIdChanged(it) }
}
}
fun removeListener(listener: DeviceIdListener) {
listeners.remove(listener)
}
fun setDeviceId(deviceId: String) {
currentDeviceId = deviceId
listeners.forEach { it.onDeviceIdChanged(deviceId) }
}
fun getDeviceId(): String? {
return currentDeviceId
}
}