Fix port, begin upload UI
This commit is contained in:
@@ -230,8 +230,8 @@ class GridViewController: UIViewController {
|
||||
}
|
||||
|
||||
private func downloadImage(cap id: Int, tile: Int) {
|
||||
app.database.downloadMainImage(for: id) { success in
|
||||
guard success else {
|
||||
app.database.downloadImage(for: id) { img in
|
||||
guard img != nil else {
|
||||
return
|
||||
}
|
||||
guard let view = self.installedTiles[tile] else {
|
||||
|
@@ -96,33 +96,28 @@ class ImageSelector: UIViewController {
|
||||
private func downloadImages() {
|
||||
images = [UIImage?](repeating: nil, count: cap.count)
|
||||
log("\(cap.count) images for cap \(cap.id)")
|
||||
if let image = app.storage.image(for: cap.id) {
|
||||
self.images[0] = image
|
||||
self.collection.reloadItems(at: [IndexPath(row: 0, section: 0)])
|
||||
} else {
|
||||
app.database.downloadMainImage(for: cap.id) { success in
|
||||
guard success, let image = app.storage.image(for: self.cap.id) else {
|
||||
return
|
||||
}
|
||||
self.images[0] = image
|
||||
DispatchQueue.main.async {
|
||||
self.collection.reloadItems(at: [IndexPath(row: 0, section: 0)])
|
||||
for version in 0..<cap.count {
|
||||
if let image = app.storage.image(for: cap.id, version: version) {
|
||||
log("Image \(version) already downloaded")
|
||||
set(image, for: version)
|
||||
} else {
|
||||
log("Downloading image \(version)")
|
||||
app.database.downloadImage(for: cap.id, version: version) { image in
|
||||
self.set(image, for: version)
|
||||
if image != nil {
|
||||
self.log("Downloaded version \(version)")
|
||||
} else {
|
||||
self.log("Failed to download image \(version)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
guard cap.count > 0 else {
|
||||
return
|
||||
}
|
||||
for number in 1..<cap.count {
|
||||
app.database.downloadImage(for: cap.id, version: number) { success in
|
||||
guard success, let image = app.storage.image(for: self.cap.id, version: number) else {
|
||||
return
|
||||
}
|
||||
self.images[number] = image
|
||||
DispatchQueue.main.async {
|
||||
self.collection.reloadItems(at: [IndexPath(row: number, section: 0)])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func set(_ image: UIImage?, for version: Int) {
|
||||
self.images[version] = image
|
||||
DispatchQueue.main.async {
|
||||
self.collection.reloadItems(at: [IndexPath(row: version, section: 0)])
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user