Commit 1681a658 authored by Jonas L.'s avatar Jonas L.

Add detection of changed content at local network

parent 0bdc012b
......@@ -16,29 +16,27 @@ object ContentDiscovery {
private val readServerPackageListExecutor = Executors.newCachedThreadPool()
private val plainData = object : LiveData<List<DiscoveredLocalNetworkContent>>() {
private val currentServers = HashSet<String>()
private val currentServers = HashSet<DiscoveredLocalNetworkServer>()
private val serverObserver: Observer<List<DiscoveredLocalNetworkServer>> = Observer { discoveredLocalServers ->
val currentServersToRemove = HashSet(currentServers)
if (discoveredLocalServers != null) {
for (serverEntry in discoveredLocalServers) {
val server = serverEntry.location
if (currentServersToRemove.remove(server)) {
if (currentServersToRemove.remove(serverEntry)) {
// server is already known
} else {
// it's a new server
currentServers.add(server)
currentServers.add(serverEntry)
// start discovery of content at it
readServerPackageListExecutor.execute {
try {
val content = ServerContentReader.getContents(server)
val content = ServerContentReader.getContents(serverEntry.location)
handler.post {
// skip if server is considered gone
if (!currentServers.contains(server)) {
if (currentServers.find { it.location == serverEntry.location } == null) {
return@post
}
......@@ -55,7 +53,7 @@ object ContentDiscovery {
}
} catch (ex: Exception) {
if (BuildConfig.DEBUG) {
Log.w(LOG_TAG, "error reading content list of$server", ex)
Log.w(LOG_TAG, "error reading content list of ${serverEntry.location}", ex)
}
}
}
......@@ -70,7 +68,7 @@ object ContentDiscovery {
if (oldData != null) {
for (oldEntry in oldData) {
if (currentServersToRemove.contains(oldEntry.location)) {
if (currentServersToRemove.find { it.location == oldEntry.location } != null) {
// remove it
} else {
// keep it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment