Commit 5c62d9ab authored by Jonas L.'s avatar Jonas L.

Fix visual glitch after loading the content list

parent 2094a617
......@@ -7,7 +7,6 @@ import de.determapp.android.content.database.AppDatabaseInstance
import de.determapp.android.content.database.item.DownloadedLocalNetworkProject
import de.determapp.android.content.database.item.PackageSourceProject
import de.determapp.android.ui.viewer.PackageSource
import java.util.*
class ContentList private constructor(context: Context) {
......@@ -20,41 +19,38 @@ class ContentList private constructor(context: Context) {
downloadedLocalNetworkProjectsLive = database.localNetworkProjectDao().getProjectsLive()
packageSourcesContentLive = database.packageSourceProjectDao().getAll()
data.value = emptyList()
data.addSource(downloadedLocalNetworkProjectsLive) { _ -> update() }
data.addSource(packageSourcesContentLive) { _ -> update() }
}
private fun update() {
val result = ArrayList<ContentListItem>()
val downloadedLocalNetworkProjects = downloadedLocalNetworkProjectsLive.value
val packageSourcesContent = packageSourcesContentLive.value
if (downloadedLocalNetworkProjects != null) {
for (item in downloadedLocalNetworkProjects) {
result.add(ContentListItem(
item.title,
item.projectId,
PackageSource.DownloadedFromLocalNetwork,
localImageFilename = ""
))
}
}
if (downloadedLocalNetworkProjects == null ||
packageSourcesContent == null) {
// not all data ready - wait for all to ignore visual glitches
if (packageSourcesContent != null) {
for (item in packageSourcesContent) {
result.add(ContentListItem(
item.title,
item.projectId,
PackageSource.WebPackageSource,
localImageFilename = item.localImageFilename
))
}
return
}
data.value = Collections.unmodifiableList(result)
data.value =
downloadedLocalNetworkProjects.map { item ->
ContentListItem(
item.title,
item.projectId,
PackageSource.DownloadedFromLocalNetwork,
localImageFilename = ""
)
} +
packageSourcesContent.map { item ->
ContentListItem(
item.title,
item.projectId,
PackageSource.WebPackageSource,
localImageFilename = item.localImageFilename
)
}
}
companion object {
......
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