设备(1)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user