Add client count badge

This commit is contained in:
Mygod
2018-05-09 17:38:49 -07:00
parent d7c5dd18a5
commit dad9bc19e3
13 changed files with 227 additions and 104 deletions

View File

@@ -25,8 +25,7 @@ class IpNeighbourMonitor private constructor() : Runnable {
instance = monitor
monitor.flush()
} else {
synchronized(monitor.neighbours) { callback.onIpNeighbourAvailable(monitor.neighbours) }
callback.postIpNeighbourAvailable()
callback.onIpNeighbourAvailable(synchronized(monitor.neighbours) { monitor.neighbours.values.toList() })
}
}
fun unregisterCallback(callback: Callback) {
@@ -37,8 +36,7 @@ class IpNeighbourMonitor private constructor() : Runnable {
}
interface Callback {
fun onIpNeighbourAvailable(neighbours: Map<String, IpNeighbour>)
fun postIpNeighbourAvailable()
fun onIpNeighbourAvailable(neighbours: List<IpNeighbour>)
}
private val handler = Handler()
@@ -112,11 +110,11 @@ class IpNeighbourMonitor private constructor() : Runnable {
private fun postUpdateLocked() {
if (updatePosted || instance != this) return
handler.post {
synchronized(neighbours) {
for (callback in callbacks) callback.onIpNeighbourAvailable(neighbours)
val neighbours = synchronized(neighbours) {
updatePosted = false
neighbours.values.toList()
}
for (callback in callbacks) callback.postIpNeighbourAvailable()
for (callback in callbacks) callback.onIpNeighbourAvailable(neighbours)
}
updatePosted = true
}