Offline mode

This commit is contained in:
Christoph Hagen 2020-08-19 19:25:17 +02:00
parent bb78132f68
commit 0efce9be96
5 changed files with 30 additions and 11 deletions

View File

@ -97,8 +97,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
func applicationDidBecomeActive(_ application: UIApplication) {
app.database?.uploadRemainingCaps()
app.database?.uploadRemainingImages()
app.database?.uploadRemainingData()
guard shouldLaunchCamera else { return }
shouldLaunchCamera = false

View File

@ -170,7 +170,7 @@
<navigationItem key="navigationItem" title="Caps" id="qe9-JJ-Ei4">
<barButtonItem key="leftBarButtonItem" title="Item" image="arrow.clockwise.icloud" catalog="system" id="SDv-mW-eqq">
<connections>
<action selector="updateInfo:" destination="2ro-5c-16N" id="DgZ-Jh-0hR"/>
<action selector="updateInfo:forEvent:" destination="2ro-5c-16N" id="MDf-gM-ErC"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" title="Item" image="circle.grid.hex" catalog="system" id="Bii-kx-Exm">

View File

@ -300,7 +300,7 @@ final class Database {
guard update("name", for: cap, setter: Cap.columnName <- name, Cap.columnUploaded <- false) else {
return false
}
uploadRemainingCaps()
uploadRemainingData()
return true
}
@ -659,27 +659,40 @@ final class Database {
}
}
func uploadRemainingCaps() {
func uploadRemainingData() {
guard !isInOfflineMode else {
log("Not uploading pending data due to offline mode")
return
}
let uploads = self.pendingCapUploads
guard uploads.count > 0 else {
log("No pending cap uploads")
uploadRemainingImages()
return
}
log("\(uploads.count) cap uploads pending")
var remaining = uploads.count
for cap in uploads {
upload.upload(name: cap.name, for: cap.id) { success in
guard success else {
if success {
self.log("Uploaded cap \(cap.id)")
self.update(uploaded: true, for: cap.id)
} else {
self.log("Failed to upload cap \(cap.id)")
return
}
self.log("Uploaded cap \(cap.id)")
self.update(uploaded: true, for: cap.id)
remaining -= 1
if remaining == 0 {
DispatchQueue.main.async {
self.uploadRemainingImages()
}
}
}
}
}
func uploadRemainingImages() {
private func uploadRemainingImages() {
let uploads = pendingImageUploads
guard uploads.count > 0 else {
log("No pending image uploads")

View File

@ -336,7 +336,14 @@ class TableView: UITableViewController {
private func showOfflineDialog() {
let offline = app.database.isInOfflineMode
if offline {
print("Marking as online")
app.database.isInOfflineMode = false
app.database.uploadRemainingData()
self.showAlert("Offline mode was disabled", title: "Online")
} else {
print("Marking as offline")
app.database.isInOfflineMode = true
self.showAlert("Offline mode was enabled", title: "Offline")
}
}