Commit 95d00966 authored by Jonas L.'s avatar Jonas L.

Adjust server discovery for new determapp-tools version

parent 489bcc82
......@@ -11,7 +11,7 @@ import java.util.*
import java.util.concurrent.Executors
object ContentDiscovery {
private val LOG_TAG = "ContentDiscovery"
private const val LOG_TAG = "ContentDiscovery"
private val handler = Handler(Looper.getMainLooper())
private val readServerPackageListExecutor = Executors.newCachedThreadPool()
......@@ -34,7 +34,7 @@ object ContentDiscovery {
// start discovery of content at it
readServerPackageListExecutor.execute {
try {
val contents = ServerContentReader.getContents(server)
val content = ServerContentReader.getContents(server)
handler.post {
// skip if server is considered gone
......@@ -49,7 +49,7 @@ object ContentDiscovery {
newData.addAll(currentData)
}
newData.addAll(contents)
newData.add(content)
setValue(Collections.unmodifiableList(newData))
}
......@@ -70,7 +70,7 @@ object ContentDiscovery {
if (oldData != null) {
for (oldEntry in oldData) {
if (currentServersToRemove.contains(oldEntry.serverLocation)) {
if (currentServersToRemove.contains(oldEntry.location)) {
// remove it
} else {
// keep it
......
......@@ -3,7 +3,7 @@ package de.determapp.android.localnetwork
import de.determapp.android.util.Validator
data class DiscoveredLocalNetworkServer (val location: String, val lastTimeSeen: Long)
data class DiscoveredLocalNetworkContent (val serverLocation: String, val location: String, val projectId: String, val title: String, val hash: String) {
data class DiscoveredLocalNetworkContent (val location: String, val projectId: String, val title: String, val hash: String) {
init {
Validator.assertIdValid(projectId)
}
......
......@@ -7,21 +7,17 @@ import okhttp3.Request
import java.util.*
object ServerContentReader {
fun getContents(serverLocation: String): List<DiscoveredLocalNetworkContent> {
fun getContents(serverLocation: String): DiscoveredLocalNetworkContent {
val response = Http.uncachedClient.newCall(
Request.Builder()
.url(
HttpUrl.parse(serverLocation)!!
.resolve("./determapp_viewer_server_packages_v1.json")!!
.resolve("./determapp_viewer_server_package_v2.json")!!
)
.build()
).execute()
val reader = JsonReader(response.body()!!.charStream())
val result = ArrayList<DiscoveredLocalNetworkContent>()
reader.beginArray()
while (reader.hasNext()) {
JsonReader(response.body()!!.charStream()).use { reader ->
var packageId: String? = null
var hash: String? = null
var title: String? = null
......@@ -38,17 +34,12 @@ object ServerContentReader {
reader.endObject()
// add to the list
result.add(DiscoveredLocalNetworkContent(
serverLocation = serverLocation,
location = HttpUrl.parse(serverLocation)!!.resolve("./$packageId/")!!.toString(),
return DiscoveredLocalNetworkContent(
location = serverLocation,
projectId = packageId!!,
title = title!!,
hash = hash!!
))
)
}
reader.endArray()
reader.close()
return Collections.unmodifiableList(result)
}
}
......@@ -51,40 +51,38 @@ class ReceiveContentList private constructor(context: Context) {
}
// sort network data
val hostToContents = network.groupBy { it.serverLocation }
val hostToContent = network.associateBy { it.location }
// add items
hostToContents.entries.forEach {
hostToContent.entries.forEach {
(serverLocation, serverContent) ->
result.add(HostHeader(serverLocation))
for (networkContent in serverContent) {
val localPackage = downloadedLocalPackageByPackageId[networkContent.projectId]
val type: ContentItemType
if (localPackage == null) {
type = ContentItemType.Download
} else if (!TextUtils.equals(localPackage.hash, networkContent.hash)) {
type = ContentItemType.Update
} else {
type = ContentItemType.None
}
val isQueued = queuedProjectsForDownload != null && queuedProjectsForDownload.contains(networkContent.projectId)
val isCurrentlyDownloaded = downloadProgress != null && downloadProgress.projectId == networkContent.projectId
result.add(ContentItem(
networkContent.location,
networkContent.projectId,
networkContent.hash,
networkContent.title,
type,
isQueued || isCurrentlyDownloaded,
if (isCurrentlyDownloaded) downloadProgress!!.progress else null
))
val localPackage = downloadedLocalPackageByPackageId[serverContent.projectId]
val type: ContentItemType
if (localPackage == null) {
type = ContentItemType.Download
} else if (!TextUtils.equals(localPackage.hash, serverContent.hash)) {
type = ContentItemType.Update
} else {
type = ContentItemType.None
}
val isQueued = queuedProjectsForDownload != null && queuedProjectsForDownload.contains(serverContent.projectId)
val isCurrentlyDownloaded = downloadProgress != null && downloadProgress.projectId == serverContent.projectId
result.add(ContentItem(
serverContent.location,
serverContent.projectId,
serverContent.hash,
serverContent.title,
type,
isQueued || isCurrentlyDownloaded,
if (isCurrentlyDownloaded) downloadProgress!!.progress else null
))
}
}
......
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