30 lines
793 B
Kotlin
30 lines
793 B
Kotlin
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
|
|
}
|
|
} |