Update download attachment, show expiration relative time

This commit is contained in:
Andrew Cope 2022-02-27 18:15:08 -05:00
parent 9f53188f71
commit 385bce2ea7
3 changed files with 27 additions and 32 deletions

View file

@ -56,8 +56,21 @@ class NtfyAttachment: Codable {
return !contentUrl.isEmpty
}
func downloadedString() -> String {
return self.isDownloaded() ? "Downloaded" : "Not downloaded"
}
func isExpired() -> Bool {
return TimeInterval(self.expires) < NSDate().timeIntervalSince1970
}
func expiresString() -> String {
return "Expires \(self.expires)"
if (self.isExpired()) {
return "Expired"
}
let date = NSDate(timeIntervalSince1970: TimeInterval(self.expires))
let formatter = RelativeDateTimeFormatter()
return "Expires \(formatter.localizedString(for: date as Date, relativeTo: Date()))"
}
func download() {

View file

@ -15,29 +15,6 @@ struct NotificationAttachmentView: View {
@State private var isAttachmentOpen = false
var body: some View {
if attachment.isDownloaded() {
if let imageUrl = UIImage(contentsOfFile: attachment.contentUrl) {
let image = Image(uiImage: imageUrl)
.resizable()
.scaledToFit()
ZStack {
image
}
.onTapGesture {
isAttachmentOpen.toggle()
}
.fullScreenCover(isPresented: $isAttachmentOpen, onDismiss: {
// Dismiss logic here
}, content: {
VStack {
image
}
.onTapGesture {
isAttachmentOpen.toggle()
}
})
}
} else {
HStack {
// TODO: Replace paperclip here with mimetype icon
Image(systemName: "paperclip")
@ -48,6 +25,11 @@ struct NotificationAttachmentView: View {
Text(attachment.sizeString())
.font(.footnote)
.foregroundColor(.gray)
if (attachment.isDownloaded()) {
Text("Downloaded")
.font(.footnote)
.foregroundColor(.gray)
} else {
Text("Not downloaded")
.font(.footnote)
.foregroundColor(.gray)

View file

@ -50,7 +50,7 @@ struct NotificationRow: View {
.padding(.all, 4)
.onTapGesture {
if let attachment = notification.attachment {
if !attachment.isDownloaded() {
if !attachment.isDownloaded() && !attachment.isExpired() {
attachment.download()
}
}