Merge pull request #3747 from omnivore-app/fix/ios-swipe-to-archive

Fix swipe to archive not triggering a list update
This commit is contained in:
Jackson Harper
2024-03-29 11:16:10 +08:00
committed by GitHub
5 changed files with 71 additions and 12 deletions

View File

@ -250,8 +250,7 @@ enum LoadingBarStyle {
}
func setLinkArchived(dataService: DataService, objectID: NSManagedObjectID, archived: Bool) {
dataService.archiveLink(objectID: objectID, archived: archived)
snackbar(archived ? "Link archived" : "Link unarchived")
archiveLibraryItemAction(dataService: dataService, objectID: objectID, archived: archived)
}
func removeLibraryItem(dataService: DataService, objectID: NSManagedObjectID) {

View File

@ -25,7 +25,8 @@
func checkPushNotificationsStatus() {
UNUserNotificationCenter.current().getNotificationSettings { settings in
DispatchQueue.main.async {
self.desiredNotificationsEnabled = settings.alertSetting == UNNotificationSetting.enabled
let desired = UserDefaults.standard.bool(forKey: UserDefaultKey.notificationsEnabled.rawValue)
self.desiredNotificationsEnabled = desired && settings.alertSetting == UNNotificationSetting.enabled
}
}
}

View File

@ -7,18 +7,20 @@ import Utils
import Views
func removeLibraryItemAction(dataService: DataService, objectID: NSManagedObjectID) {
var localPdf: String? = nil
dataService.viewContext.performAndWait {
if let item = dataService.viewContext.object(with: objectID) as? Models.LibraryItem {
item.state = "DELETED"
try? dataService.viewContext.save()
// Delete local PDF file if it exists
if let localPdf = item.localPDF, let localPdfURL = PDFUtils.localPdfURL(filename: localPdf) {
try? FileManager.default.removeItem(at: localPdfURL)
}
localPdf = item.localPDF
}
}
if let localPdf = localPdf, let localPdfURL = PDFUtils.localPdfURL(filename: localPdf) {
try? FileManager.default.removeItem(at: localPdfURL)
}
let syncTask = Task.detached(priority: .background) {
do {
try await Task.sleep(nanoseconds: 4_000_000_000)
@ -44,3 +46,43 @@ func removeLibraryItemAction(dataService: DataService, objectID: NSManagedObject
}
}, dismissAfter: 2000)
}
func archiveLibraryItemAction(dataService: DataService, objectID: NSManagedObjectID, archived: Bool) {
var localPdf: String? = nil
dataService.viewContext.performAndWait {
if let item = dataService.viewContext.object(with: objectID) as? Models.LibraryItem {
item.isArchived = archived
try? dataService.viewContext.save()
localPdf = item.localPDF
}
}
// Delete local PDF file if it exists
if let localPdf = localPdf, let localPdfURL = PDFUtils.localPdfURL(filename: localPdf) {
try? FileManager.default.removeItem(at: localPdfURL)
}
let syncTask = Task.detached(priority: .background) {
do {
try await Task.sleep(nanoseconds: 4_000_000_000)
let canceled = Task.isCancelled
if !canceled {
dataService.archiveLink(objectID: objectID, archived: archived)
}
} catch {
print("error running task: ", error)
}
print("checking if task is canceled: ", Task.isCancelled)
}
Snackbar.show(message: "Item archived", undoAction: {
print("canceling task", syncTask)
syncTask.cancel()
dataService.viewContext.performAndWait {
if let item = dataService.viewContext.object(with: objectID) as? Models.LibraryItem {
item.state = "SUCCEEDED"
try? dataService.viewContext.save()
}
}
}, dismissAfter: 2000)
}

View File

@ -405,10 +405,14 @@ struct WebReaderContainerView: View {
anchorIndex: Int(item.readingProgressAnchor),
force: false
)
Task {
await audioController.preload(itemIDs: [item.unwrappedID])
}
viewModel.trackReadEvent(item: item)
// Wait 1.5s while loading the reader before attempting to preload the speech file
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1500)) {
Task {
await audioController.preload(itemIDs: [item.unwrappedID])
}
}
}
.confirmationDialog(linkToOpen?.absoluteString ?? "", isPresented: $displayLinkSheet,
titleVisibility: .visible) {

View File

@ -18,6 +18,7 @@ import Views
guard let objectID = try? await dataService.loadItemContentUsingRequestID(username: username,
requestID: requestID)
else {
errorMessage = "Item is no longer available"
return
}
item = dataService.viewContext.object(with: objectID) as? Models.LibraryItem
@ -71,7 +72,19 @@ public struct WebReaderLoadingContainer: View {
.onAppear { viewModel.trackReadEvent() }
}
} else if let errorMessage = viewModel.errorMessage {
Text(errorMessage)
NavigationView {
VStack(spacing: 15) {
Text(errorMessage)
Button(action: {
dismiss()
}, label: {
Text("Dismiss")
})
}
}
#if os(iOS)
.navigationViewStyle(.stack)
#endif
} else {
ProgressView()
.task {