Update download attachment, show expiration relative time
This commit is contained in:
parent
9f53188f71
commit
385bce2ea7
3 changed files with 27 additions and 32 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -15,39 +15,21 @@ 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")
|
||||
VStack(alignment: .leading) {
|
||||
Text(attachment.name)
|
||||
HStack {
|
||||
// TODO: Replace paperclip here with mimetype icon
|
||||
Image(systemName: "paperclip")
|
||||
VStack(alignment: .leading) {
|
||||
Text(attachment.name)
|
||||
.font(.footnote)
|
||||
HStack {
|
||||
Text(attachment.sizeString())
|
||||
.font(.footnote)
|
||||
HStack {
|
||||
Text(attachment.sizeString())
|
||||
.foregroundColor(.gray)
|
||||
if (attachment.isDownloaded()) {
|
||||
Text("Downloaded")
|
||||
.font(.footnote)
|
||||
.foregroundColor(.gray)
|
||||
} else {
|
||||
Text("Not downloaded")
|
||||
.font(.footnote)
|
||||
.foregroundColor(.gray)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue