mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Better cancelation of offline audio downloads, menu cleanup
This commit is contained in:
parent
3e4f9409df
commit
ab64e56ab4
6 changed files with 40 additions and 14 deletions
|
|
@ -279,7 +279,7 @@ import Views
|
|||
}
|
||||
Button(
|
||||
action: { viewModel.itemUnderTitleEdit = item },
|
||||
label: { Label("Edit Metadata", systemImage: "textbox") }
|
||||
label: { Label("Edit Info", systemImage: "info.circle") }
|
||||
)
|
||||
Button(
|
||||
action: { viewModel.itemUnderLabelEdit = item },
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ import Views
|
|||
// TODO: add highlights view button
|
||||
Button(
|
||||
action: { viewModel.itemUnderTitleEdit = item },
|
||||
label: { Label("Edit Metadata", systemImage: "textbox") }
|
||||
label: { Label("Edit Info", systemImage: "info.circle") }
|
||||
)
|
||||
Button(
|
||||
action: { viewModel.itemUnderLabelEdit = item },
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ struct LinkItemDetailView: View {
|
|||
Group {
|
||||
Button(
|
||||
action: { showTitleEdit = true },
|
||||
label: { Label("Edit Metadata", systemImage: "textbox") }
|
||||
label: { Label("Edit Info", systemImage: "info.circle") }
|
||||
)
|
||||
Button(
|
||||
action: { viewModel.handleArchiveAction(dataService: dataService) },
|
||||
|
|
|
|||
|
|
@ -164,6 +164,17 @@ struct WebReaderContainerView: View {
|
|||
}.foregroundColor(.appGrayTextContrast)
|
||||
}
|
||||
|
||||
func audioMenuItem() -> some View {
|
||||
Button(
|
||||
action: {
|
||||
viewModel.downloadAudio(audioController: audioController, item: item)
|
||||
},
|
||||
label: {
|
||||
Label(viewModel.isDownloadingAudio ? "Downloading Audio" : "Download Audio", systemImage: "icloud.and.arrow.down")
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func menuItems(for item: LinkedItem) -> some View {
|
||||
let hasLabels = item.labels?.count == 0
|
||||
let hasHighlights = (item.highlights?.count ?? 0) > 0
|
||||
|
|
@ -176,7 +187,7 @@ struct WebReaderContainerView: View {
|
|||
}
|
||||
Button(
|
||||
action: { showTitleEdit = true },
|
||||
label: { Label("Edit Metadata", systemImage: "textbox") }
|
||||
label: { Label("Edit Info", systemImage: "info.circle") }
|
||||
)
|
||||
Button(
|
||||
action: editLabels,
|
||||
|
|
@ -199,12 +210,8 @@ struct WebReaderContainerView: View {
|
|||
},
|
||||
label: { Label("Reset Read Location", systemImage: "arrow.counterclockwise.circle") }
|
||||
)
|
||||
Button(
|
||||
action: {
|
||||
viewModel.downloadAudio(audioController: audioController, item: item)
|
||||
},
|
||||
label: { Label("Download Audio", systemImage: "icloud.and.arrow.down") }
|
||||
)
|
||||
audioMenuItem()
|
||||
|
||||
if viewModel.hasOriginalUrl(item) {
|
||||
Button(
|
||||
action: share,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@ struct SafariWebLink: Identifiable {
|
|||
@MainActor final class WebReaderViewModel: ObservableObject {
|
||||
@Published var articleContent: ArticleContent?
|
||||
@Published var errorMessage: String?
|
||||
@Published var isDownloadingAudio: Bool = false
|
||||
@Published var audioDownloadTask: Task<Void, Error>?
|
||||
|
||||
deinit {
|
||||
print("deinit WebReaderViewModel")
|
||||
}
|
||||
|
||||
func hasOriginalUrl(_ item: LinkedItem) -> Bool {
|
||||
if let pageURLString = item.pageURLString, let host = URL(string: pageURLString)?.host {
|
||||
|
|
@ -25,9 +31,22 @@ struct SafariWebLink: Identifiable {
|
|||
|
||||
func downloadAudio(audioController: AudioController, item: LinkedItem) {
|
||||
Snackbar.show(message: "Downloading Offline Audio")
|
||||
Task {
|
||||
let downloaded = await audioController.downloadForOffline(itemID: item.unwrappedID)
|
||||
Snackbar.show(message: downloaded ? "Audio file downloaded" : "Error downloading audio")
|
||||
isDownloadingAudio = true
|
||||
|
||||
if let audioDownloadTask = audioDownloadTask {
|
||||
audioDownloadTask.cancel()
|
||||
}
|
||||
|
||||
let itemID = item.unwrappedID
|
||||
audioDownloadTask = Task.detached(priority: .background) {
|
||||
let canceled = Task.isCancelled
|
||||
let downloaded = await audioController.downloadForOffline(itemID: itemID)
|
||||
DispatchQueue.main.async {
|
||||
self.isDownloadingAudio = false
|
||||
if !canceled {
|
||||
Snackbar.show(message: downloaded ? "Audio file downloaded" : "Error downloading audio")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public struct GridCard: View {
|
|||
}
|
||||
Button(
|
||||
action: { menuActionHandler(.editTitle) },
|
||||
label: { Label("Edit Metadata", systemImage: "textbox") }
|
||||
label: { Label("Edit Info", systemImage: "info.circle") }
|
||||
)
|
||||
Button(
|
||||
action: { menuActionHandler(.editLabels) },
|
||||
|
|
|
|||
Loading…
Reference in a new issue