Offline mode
This commit is contained in:
parent
bb78132f68
commit
0efce9be96
Binary file not shown.
@ -97,8 +97,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||||
app.database?.uploadRemainingCaps()
|
app.database?.uploadRemainingData()
|
||||||
app.database?.uploadRemainingImages()
|
|
||||||
|
|
||||||
guard shouldLaunchCamera else { return }
|
guard shouldLaunchCamera else { return }
|
||||||
shouldLaunchCamera = false
|
shouldLaunchCamera = false
|
||||||
|
@ -170,7 +170,7 @@
|
|||||||
<navigationItem key="navigationItem" title="Caps" id="qe9-JJ-Ei4">
|
<navigationItem key="navigationItem" title="Caps" id="qe9-JJ-Ei4">
|
||||||
<barButtonItem key="leftBarButtonItem" title="Item" image="arrow.clockwise.icloud" catalog="system" id="SDv-mW-eqq">
|
<barButtonItem key="leftBarButtonItem" title="Item" image="arrow.clockwise.icloud" catalog="system" id="SDv-mW-eqq">
|
||||||
<connections>
|
<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>
|
</connections>
|
||||||
</barButtonItem>
|
</barButtonItem>
|
||||||
<barButtonItem key="rightBarButtonItem" title="Item" image="circle.grid.hex" catalog="system" id="Bii-kx-Exm">
|
<barButtonItem key="rightBarButtonItem" title="Item" image="circle.grid.hex" catalog="system" id="Bii-kx-Exm">
|
||||||
|
@ -300,7 +300,7 @@ final class Database {
|
|||||||
guard update("name", for: cap, setter: Cap.columnName <- name, Cap.columnUploaded <- false) else {
|
guard update("name", for: cap, setter: Cap.columnName <- name, Cap.columnUploaded <- false) else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
uploadRemainingCaps()
|
uploadRemainingData()
|
||||||
return true
|
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
|
let uploads = self.pendingCapUploads
|
||||||
guard uploads.count > 0 else {
|
guard uploads.count > 0 else {
|
||||||
log("No pending cap uploads")
|
log("No pending cap uploads")
|
||||||
|
uploadRemainingImages()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log("\(uploads.count) cap uploads pending")
|
log("\(uploads.count) cap uploads pending")
|
||||||
|
|
||||||
|
var remaining = uploads.count
|
||||||
for cap in uploads {
|
for cap in uploads {
|
||||||
upload.upload(name: cap.name, for: cap.id) { success in
|
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)")
|
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
|
let uploads = pendingImageUploads
|
||||||
guard uploads.count > 0 else {
|
guard uploads.count > 0 else {
|
||||||
log("No pending image uploads")
|
log("No pending image uploads")
|
||||||
|
@ -336,7 +336,14 @@ class TableView: UITableViewController {
|
|||||||
private func showOfflineDialog() {
|
private func showOfflineDialog() {
|
||||||
let offline = app.database.isInOfflineMode
|
let offline = app.database.isInOfflineMode
|
||||||
if offline {
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user