diff --git a/enzevalos_iphone.xcodeproj/project.pbxproj b/enzevalos_iphone.xcodeproj/project.pbxproj index 289d962ff2265b46eb083e719870198134ed7fa6..a3d9344e778315962297e9941c102d4b7ca8910a 100644 --- a/enzevalos_iphone.xcodeproj/project.pbxproj +++ b/enzevalos_iphone.xcodeproj/project.pbxproj @@ -86,7 +86,7 @@ 477120AE254C28F900B28C64 /* TabSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477120AD254C28F900B28C64 /* TabSupport.swift */; }; 477120BC254C401E00B28C64 /* AddressRecord+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477120BB254C401E00B28C64 /* AddressRecord+CoreDataProperties.swift */; }; 477120C2254C676000B28C64 /* ContactView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477120C1254C676000B28C64 /* ContactView.swift */; }; - 477120CD254C76AE00B28C64 /* FolderOverView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477120CC254C76AE00B28C64 /* FolderOverView.swift */; }; + 477120CD254C76AE00B28C64 /* FolderListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477120CC254C76AE00B28C64 /* FolderListView.swift */; }; 4774DD7322CFFD0E00BD8CF6 /* AliceMultiIDs (439EE43C) – Public.asc in Resources */ = {isa = PBXBuildFile; fileRef = 4774DD7222CFFD0E00BD8CF6 /* AliceMultiIDs (439EE43C) – Public.asc */; }; 4774DD7522D0015F00BD8CF6 /* multiIDs.eml in Resources */ = {isa = PBXBuildFile; fileRef = 4774DD7422D0015F00BD8CF6 /* multiIDs.eml */; }; 4774DD7B22D3F5D100BD8CF6 /* multiIDs2.eml in Resources */ = {isa = PBXBuildFile; fileRef = 4774DD7A22D3F5D100BD8CF6 /* multiIDs2.eml */; }; @@ -195,7 +195,7 @@ 47F867E02052B47C00AA832F /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 47F867DF2052B47C00AA832F /* Security.framework */; }; 47F867E22052B48E00AA832F /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 47F867E12052B48E00AA832F /* libz.tbd */; }; 47F867E42052B49800AA832F /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 47F867E32052B49800AA832F /* libbz2.tbd */; }; - 47FA8EA8254C7E5B006883D0 /* FolderRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FA8EA7254C7E5B006883D0 /* FolderRow.swift */; }; + 47FA8EA8254C7E5B006883D0 /* FolderRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FA8EA7254C7E5B006883D0 /* FolderRowView.swift */; }; 47FA8EAC254D77DE006883D0 /* MailListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FA8EAB254D77DE006883D0 /* MailListView.swift */; }; 47FA8EC3254D9E01006883D0 /* RecipientFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FA8EC2254D9E01006883D0 /* RecipientFieldModel.swift */; }; 47FAE30E2524AA97005A1BCB /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 47FAE30C2524AA97005A1BCB /* DataModel.xcdatamodeld */; }; @@ -477,7 +477,7 @@ 477120AD254C28F900B28C64 /* TabSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabSupport.swift; sourceTree = "<group>"; }; 477120BB254C401E00B28C64 /* AddressRecord+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AddressRecord+CoreDataProperties.swift"; sourceTree = "<group>"; }; 477120C1254C676000B28C64 /* ContactView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactView.swift; sourceTree = "<group>"; }; - 477120CC254C76AE00B28C64 /* FolderOverView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderOverView.swift; sourceTree = "<group>"; }; + 477120CC254C76AE00B28C64 /* FolderListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderListView.swift; sourceTree = "<group>"; }; 4774DD7222CFFD0E00BD8CF6 /* AliceMultiIDs (439EE43C) – Public.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "AliceMultiIDs (439EE43C) – Public.asc"; sourceTree = "<group>"; }; 4774DD7422D0015F00BD8CF6 /* multiIDs.eml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = multiIDs.eml; sourceTree = "<group>"; }; 4774DD7A22D3F5D100BD8CF6 /* multiIDs2.eml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = multiIDs2.eml; sourceTree = "<group>"; }; @@ -573,7 +573,7 @@ 47F867DF2052B47C00AA832F /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; 47F867E12052B48E00AA832F /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 47F867E32052B49800AA832F /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; }; - 47FA8EA7254C7E5B006883D0 /* FolderRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderRow.swift; sourceTree = "<group>"; }; + 47FA8EA7254C7E5B006883D0 /* FolderRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderRowView.swift; sourceTree = "<group>"; }; 47FA8EAB254D77DE006883D0 /* MailListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailListView.swift; sourceTree = "<group>"; }; 47FA8EC2254D9E01006883D0 /* RecipientFieldModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipientFieldModel.swift; sourceTree = "<group>"; }; 47FAE30D2524AA97005A1BCB /* DataModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = DataModel.xcdatamodel; sourceTree = "<group>"; }; @@ -1050,8 +1050,8 @@ 477120CB254C766F00B28C64 /* FolderView */ = { isa = PBXGroup; children = ( - 477120CC254C76AE00B28C64 /* FolderOverView.swift */, - 47FA8EA7254C7E5B006883D0 /* FolderRow.swift */, + 477120CC254C76AE00B28C64 /* FolderListView.swift */, + 47FA8EA7254C7E5B006883D0 /* FolderRowView.swift */, ); path = FolderView; sourceTree = "<group>"; @@ -1968,7 +1968,7 @@ 3EC35F2420037651008BDF95 /* InvitationHelper.swift in Sources */, 47C112C22531D72E00621A07 /* PublicKeyRecord.swift in Sources */, 3FB75DCD25FFD37400919925 /* RecipientListView.swift in Sources */, - 477120CD254C76AE00B28C64 /* FolderOverView.swift in Sources */, + 477120CD254C76AE00B28C64 /* FolderListView.swift in Sources */, 4733B202252B142C00AB5600 /* Properties.swift in Sources */, 47FAE3492524FB58005A1BCB /* AddressRecord.swift in Sources */, 4775D7AA243F0E260052F2CC /* SimulatorData.swift in Sources */, @@ -1996,7 +1996,7 @@ 47BCAF70259F9E390008FE4B /* PasswordAlert.swift in Sources */, 477120C2254C676000B28C64 /* ContactView.swift in Sources */, 47EABF09241A9C8700774A93 /* AuthenticationModel.swift in Sources */, - 47FA8EA8254C7E5B006883D0 /* FolderRow.swift in Sources */, + 47FA8EA8254C7E5B006883D0 /* FolderRowView.swift in Sources */, A1EB05881D956879008659C1 /* ContactHandler.swift in Sources */, 47EABF2D2423C65F00774A93 /* AuthenticationView.swift in Sources */, 47BCAF68259F48840008FE4B /* TempKeyRow.swift in Sources */, diff --git a/enzevalos_iphone/SwiftUI/DisplayProtocols.swift b/enzevalos_iphone/SwiftUI/DisplayProtocols.swift index 65b5181471b5854798b82dd4749c6ff078ccf6f1..59ddc9046b574349d7eea04fd18bcb1f365904cc 100644 --- a/enzevalos_iphone/SwiftUI/DisplayProtocols.swift +++ b/enzevalos_iphone/SwiftUI/DisplayProtocols.swift @@ -76,19 +76,15 @@ enum ContactSecurityRating { var name: LocalizedStringKey { switch self { - case .Trustworthy: - return "ContactView.Rating.Trustworthy" - case .Forgable: - return "ContactView.Rating.Forgable" + case .Trustworthy: return "ContactView.Rating.Trustworthy" + case .Forgable: return "ContactView.Rating.Forgable" } } var color: Color { switch self { - case .Trustworthy: - return Color(ThemeManager.encryptedVerifiedMessageColor()) - case .Forgable: - return Color(ThemeManager.unencryptedMessageColor()) + case .Trustworthy: return Color(ThemeManager.encryptedVerifiedMessageColor()) + case .Forgable: return Color(ThemeManager.unencryptedMessageColor()) } } } @@ -100,10 +96,8 @@ protocol DisplayKey { var lastSeen: Date? { get } var type: CryptoScheme { get } var isPreferedKey: Bool { get } - var signedMailsCounter: Int { get } var sentMailsCounter: Int { get } - } protocol DisplayFolder { @@ -250,7 +244,6 @@ extension DisplayMail { } } - var dialog: DialogStruct { get { // TODO: Do we add new public key stuff? @@ -414,7 +407,6 @@ extension DisplayMail { case (.ValidedEncryptedWithCurrentKey, .NoSignature): return .EncNoSignature case (.ValidedEncryptedWithCurrentKey, .NoPublicKey): return .EncButMissingPublicKeyToVerify } - } diff --git a/enzevalos_iphone/SwiftUI/FolderView/FolderListView.swift b/enzevalos_iphone/SwiftUI/FolderView/FolderListView.swift new file mode 100644 index 0000000000000000000000000000000000000000..aabf01383b0a8350da744ef84cbd2723e137636b --- /dev/null +++ b/enzevalos_iphone/SwiftUI/FolderView/FolderListView.swift @@ -0,0 +1,54 @@ +// +// FolderOverView.swift +// enzevalos_iphone +// +// Created by Oliver Wiese on 30.10.20. +// Modified by Chris Offner & Claire Bräuer in March 2021. +// Copyright © 2020 fu-berlin. All rights reserved. +// + +import SwiftUI + +/// A view that lists all email folders and lets the user navigate to them. +struct FolderListView: View { + @Environment(\.managedObjectContext) var managedObjectContext + @FetchRequest(fetchRequest: FolderRecord.FetchRequest) + private var folders: FetchedResults<FolderRecord> + @State private var nameOfChosenFolder: String? + + var body: some View { + NavigationView { + List(folders, id: \.self) { f in + let name = formatName(f.name) + + NavigationLink(destination: InboxView(folderPath: f.path ?? name, name: name) + .environment(\.managedObjectContext, + PersistentDataProvider + .dataProvider + .persistentContainer + .viewContext), + tag: f.name, + selection: $nameOfChosenFolder, + label: { FolderRowView(folder: f) }) + } + .navigationBarTitle("Folders", displayMode: .large) + } + .onAppear { nameOfChosenFolder = "INBOX" } + } + + /// Capitalizes first letter, lowercases all subsequent letters of string. + /// + /// - Parameter name: String to be formatted + /// - Returns: Formatted string + private func formatName(_ name: String) -> String { + name.prefix(1).capitalized + name.dropFirst().lowercased() + } +} + +// Preview +struct FolderOverView_Previews: PreviewProvider { + static var previews: some View { + FolderListView() + } +} + diff --git a/enzevalos_iphone/SwiftUI/FolderView/FolderOverView.swift b/enzevalos_iphone/SwiftUI/FolderView/FolderOverView.swift deleted file mode 100644 index 2842f8ae43a3b7c7665a2667442f3b1ac4b2abc8..0000000000000000000000000000000000000000 --- a/enzevalos_iphone/SwiftUI/FolderView/FolderOverView.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// FolderOverView.swift -// enzevalos_iphone -// -// Created by Oliver Wiese on 30.10.20. -// Copyright © 2020 fu-berlin. All rights reserved. -// - -import SwiftUI - -struct FolderOverView: View { - @Environment(\.managedObjectContext) var managedObjectContext - @FetchRequest(fetchRequest: FolderRecord.FetchRequest) - var folders: FetchedResults<FolderRecord> - - - var body: some View { - List (folders, id: \.self){ f in - NavigationLink( - destination: MailListView(folderPath: f.path ?? f.name, folderName: f.name) - .environment(\.managedObjectContext, PersistentDataProvider.dataProvider.persistentContainer.viewContext) - ) { - FolderRow(folder: f) - } - } - .onAppear(perform: { - LetterboxModel.instance.mailHandler.allFolders({e in print("All folders: \(String(describing: e))")}) - }) - .navigationBarTitle("Folders", displayMode: .large) - } -} - -struct FolderOverView_Previews: PreviewProvider { - - static var previews: some View { - FolderOverView() - } -} - diff --git a/enzevalos_iphone/SwiftUI/FolderView/FolderRow.swift b/enzevalos_iphone/SwiftUI/FolderView/FolderRowView.swift similarity index 78% rename from enzevalos_iphone/SwiftUI/FolderView/FolderRow.swift rename to enzevalos_iphone/SwiftUI/FolderView/FolderRowView.swift index 406ab81d9026ef42a809bdb8d8a62f146f5b5f7d..557b31f70a9e0dccdd1b693ddc780d36f133cbc4 100644 --- a/enzevalos_iphone/SwiftUI/FolderView/FolderRow.swift +++ b/enzevalos_iphone/SwiftUI/FolderView/FolderRowView.swift @@ -8,14 +8,13 @@ import SwiftUI -struct FolderRow: View { +struct FolderRowView: View { //TODO: increase padding for each delimiter? -> Subfolder level? public var folder: DisplayFolder var body: some View { HStack { - folder.icon - .foregroundColor(.blue) + folder.icon.foregroundColor(.accentColor) Text(folder.name) Spacer() Text("\(folder.mails)") @@ -26,6 +25,6 @@ struct FolderRow: View { struct FolderRow_Previews: PreviewProvider { static var previews: some View { - FolderRow(folder: ProxyFolder(name: "Inbox")) + FolderRowView(folder: ProxyFolder(name: "Inbox")) } } diff --git a/enzevalos_iphone/SwiftUI/Inbox/InboxView.swift b/enzevalos_iphone/SwiftUI/Inbox/InboxView.swift index b142011ba752c51314c18b75b080b746957b6ba9..1a035945c5d6ff3a58e69c48bb6bfe8e7ba0f48a 100644 --- a/enzevalos_iphone/SwiftUI/Inbox/InboxView.swift +++ b/enzevalos_iphone/SwiftUI/Inbox/InboxView.swift @@ -20,22 +20,20 @@ struct InboxView: View { @State private var goToFolders = false var body: some View { - NavigationView { - mailListView - .onAppear(perform: updateMails) - .sheet(isPresented: $composeMail) { ComposeView() } - .navigationBarItems(leading: folderButton, trailing: keyManagementButton) - .toolbar { - ToolbarItem(placement: .status) { - lastUpdate - } - - ToolbarItemGroup(placement: .bottomBar) { - Spacer() - composeButton - } + mailListView + .onAppear(perform: updateMails) + .sheet(isPresented: $composeMail) { ComposeView() } + .navigationBarItems(trailing: keyManagementButton) + .toolbar { + ToolbarItem(placement: .status) { + lastUpdate } - } + + ToolbarItemGroup(placement: .bottomBar) { + Spacer() + composeButton + } + } } @@ -108,7 +106,7 @@ struct InboxView: View { } label: { Image(systemName: "tray.2").imageScale(.large) } - .background(NavigationLink(destination: FolderOverView() + .background(NavigationLink(destination: FolderListView() .environment(\.managedObjectContext, PersistentDataProvider .dataProvider diff --git a/enzevalos_iphone/SwiftUI/LetterboxApp.swift b/enzevalos_iphone/SwiftUI/LetterboxApp.swift index e0fee28dfea811ad598044636bc90e31f3f8e0a1..25870715d77b86cc62c85b6bfb7b574d6a413bfa 100644 --- a/enzevalos_iphone/SwiftUI/LetterboxApp.swift +++ b/enzevalos_iphone/SwiftUI/LetterboxApp.swift @@ -16,11 +16,10 @@ struct LetterboxApp: App { var body: some Scene { WindowGroup { if testing { - NavigationView{ + NavigationView { KeyManagementOverview() } - } - else { + } else { switch model.currentState { case .PERMISSIONS: PermissionRequestView() @@ -31,8 +30,12 @@ struct LetterboxApp: App { case .GENERATEKEYS: PermissionRequestView() // TODO Wait case .LAUNCHEDBEFORE: - InboxView(folderPath: MailHandler.INBOX, name: NSLocalizedString("Inbox", comment: "Inbox")) - .environment(\.managedObjectContext, PersistentDataProvider.dataProvider.persistentContainer.viewContext) + FolderListView() + .environment(\.managedObjectContext, + PersistentDataProvider + .dataProvider + .persistentContainer + .viewContext) } } } diff --git a/enzevalos_iphone/SwiftUI/Read/ReadMainView.swift b/enzevalos_iphone/SwiftUI/Read/ReadMainView.swift index d4ee8746db78cfc3f8f9697e7a13941b78d39cf2..27d7620e3c02924b707cad3652c77f3d7b7e5df3 100644 --- a/enzevalos_iphone/SwiftUI/Read/ReadMainView.swift +++ b/enzevalos_iphone/SwiftUI/Read/ReadMainView.swift @@ -66,7 +66,7 @@ struct ReadMainView <M: DisplayMail>: View { tab: ReadPart.Attachments.value, image: Image(systemName: "rectangle.and.paperclip"), description: "Tab.Label.Attachments", - content: AnyView(AttachmentsViewMain(attachments: model.mail.displayAttachments, dlAll: true)) + content: AnyView(AttachmentsViewMain(attachments: model.mail.displayAttachments, downloadAll: true)) ) ] } diff --git a/enzevalos_iphone/SwiftUI/Read/Tabbed Views/AttachmentsViewMain.swift b/enzevalos_iphone/SwiftUI/Read/Tabbed Views/AttachmentsViewMain.swift index 10451bac044aaea1ad031aa0c041aa61e59d1a7e..fa7044dc45a7b18c076888bfe81fd4ef78c7f8ec 100644 --- a/enzevalos_iphone/SwiftUI/Read/Tabbed Views/AttachmentsViewMain.swift +++ b/enzevalos_iphone/SwiftUI/Read/Tabbed Views/AttachmentsViewMain.swift @@ -15,29 +15,40 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. +/// a file that preview the attachments of incoming mails +// currently this view only previews a ProxyAttachment import SwiftUI struct AttachmentsViewMain: View { // TODO: Refactor to model? + + //a list that contains all the attachment files @State var attachments: [DisplayAttachment] // Whether the Download all button was clicked - @State var dlAll = true; + @State var downloadAll = true; var body: some View { VStack{ Spacer() // TODO: Add link section - // check if there even are attachments to be displayed + // default view if there are no attachments to be displayed if attachments.count == 0{ noAttachments } + // otherwise preview the attachments else { attachmentsView } } } + /// default view if there are no attachments to be displayed + var noAttachments: some View { + return Text(NSLocalizedString("ReadView.Attachments.No", comment: "")).font(.footnote).padding(30) + } + + /// a view that previews all the attachment files var attachmentsView: some View { return VStack(alignment: .leading, spacing: 5){ // headline @@ -54,7 +65,7 @@ struct AttachmentsViewMain: View { ForEach(0..<attachments.count) { i in AttPrev( attachment: self.attachments[i], - preload: self.dlAll + shouldBeDownloaded: self.downloadAll ) } } @@ -63,34 +74,39 @@ struct AttachmentsViewMain: View { .padding(.top, 30) .padding(.bottom,10) } - - var noAttachments: some View { - return Text(NSLocalizedString("ReadView.Attachments.No", comment: "")).font(.footnote).padding(30) - } - } struct AttachmentsViewMain_Previews: PreviewProvider { static var previews: some View { + // here we call the view with a single ProxyAttachment() for + // demonstration purposes AttachmentsViewMain(attachments: [ProxyAttachment()]) } } -// MARK: one AttachmentPreview +/// a view that previews one attachment file struct AttPrev:View{ + // the attachment that is going to be previewed var attachment: DisplayAttachment - var preload = false - + // by default false + var shouldBeDownloaded = false + + // whether this attachment is already downloaded to the documents directory @State var isDownloaded: Bool = false + // used togehter with 'open' button to + // open a fullScreenView of a file @State var isFullScreen: Bool = false - func download(){ - func getDocumentsDirectory() -> URL { - let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) - return paths[0] - } + /// a func to find the documents directory + func getDocumentsDirectory() -> URL { + let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) + return paths[0] + } + + /// a func that downloads the attachment into the documents directory + func download() { let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName) do { @@ -101,125 +117,167 @@ struct AttPrev:View{ self.isDownloaded = true } - //is the file already downloaded? + /// a func that checks if an attachment is downloaded into the documents directory or not + /// updates the 'isDownloaded' property accordingly func getDownloadedState(){ - func getDocumentsDirectory() -> URL { - let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) - return paths[0] - } let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName) if FileManager.default.fileExists(atPath: filename.path){self.isDownloaded = true} } var body: some View{ - if preload {self.download()} + if shouldBeDownloaded { + self.download() + } - //this QuickLookView has to be defined here so it reloads on every state-change + // QuickLookView creates the preview of the file + // it has to be defined here to update correctly let QLV = QuickLookView(name: self.attachment.myName, data: self.attachment.myData, shallDL: self.isDownloaded) + return VStack{ - Group{ - CardV(title: self.attachment.myName, + Group{ + CardV(title: self.attachment.myName, - //those are the actions visable under the cklicked preview - actions: self.isDownloaded||self.preload ? - [ - /* - self.ActionView(NSLocalizedString("delete", comment: ""), - icon: AnyView(Image(systemName: "trash")), - onClick: { - func getDocumentsDirectory() -> URL { - let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) - return paths[0] + // these buttons are visable under the preview + // when users click on the preview + actions: self.isDownloaded||self.shouldBeDownloaded ? + // different combination of buttons + // according to downloading status + [ + // anyViewDeleteButton + anyViewOpenButton, + anyViewShareButton + ] + : + [ + anyViewDownloadButton, + // both lists need same length + // to make appearance the same + AnyView(EmptyView()), + AnyView(EmptyView()) + ] + ){ + QLV/*TODO: + .allowsHitTesting(false).disabled(true)*/ //this should make the whole view scrollable averywhere not just on the title } - let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.name!) - - do { - try FileManager.default.removeItem(at: filename) - } catch let error as NSError { - print("Error: \(error)") - } - self.isDownloaded = false - } - - ), */ - self.ActionView(NSLocalizedString("open", comment: ""), - icon: AnyView(Image(systemName: "arrow.up.and.down").rotationEffect(.degrees(45))), - onClick: {self.isFullScreen.toggle()} - ), - AnyView(VStack{ - shareButton - Text(NSLocalizedString("share", comment: "")).font(.system(size: 12)).foregroundColor(.blue) - }) - ] - : - [ - self.ActionView(NSLocalizedString("download", comment: ""), - icon: AnyView(Image(systemName: "arrow.down.circle")), - onClick: { - self.download() - } - ), - //odd but both lists need same length - AnyView(EmptyView()), - AnyView(EmptyView()) - ] - ){ - QLV/*TODO: - .allowsHitTesting(false).disabled(true)*/ //this should make the whole view scrollable averywhere not just on the title - - } - } - // A4 format + } + // preview should resemble the look of A4 format .aspectRatio(100/141, contentMode: .fit) .frame(width: UIScreen.main.bounds.width*2/3)//, maxHeight: 500) - //an invisable NavigationLink to open the preview in fullscreen - NavigationLink(destination: QuickLookView(name: self.attachment.myName, data: self.attachment.myData) - .navigationBarItems(trailing: shareButton), isActive: self.$isFullScreen){Text("loi")}.hidden() - - } - .onAppear(perform: { - self.getDownloadedState() + //a hidden NavigationLink to open the preview in fullscreen + // seems not to work currently + NavigationLink( + destination: QuickLookView(name: self.attachment.myName, data: self.attachment.myData) + .navigationBarItems(trailing: anyViewShareButton), isActive: self.$isFullScreen) {Text("loi")}.hidden()} + .onAppear( + perform: { + self.getDownloadedState() - //download all functionality - if self.preload {self.isDownloaded=true; self.download()} - }) - .onDisappear(perform: { - func getDocumentsDirectory() -> URL { - let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) - return paths[0] - } - let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName) + //download all functionality + if self.shouldBeDownloaded {self.isDownloaded=true; self.download()} + } + ) + // remove file from documents directory + .onDisappear( + perform: { + let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName) - do { - try FileManager.default.removeItem(at: filename) - } catch let error as NSError { - print("Error: \(error)") - } - self.isDownloaded = false - print("======== Attachment DISAPPEAR -> REMOVE FILES ========") - }) + do { + try FileManager.default.removeItem(at: filename) + } + catch let error as NSError {print("Error: \(error)")} + self.isDownloaded = false + print("======== Attachment DISAPPEAR -> REMOVE FILES ========") + } + ) +} + + // an open button converted into an AnyView + // should open the view fullscreen + var anyViewOpenButton: AnyView { + AnyView( + Button ( + action: { + self.isFullScreen.toggle() + }, + label: { + VStack { + Image(systemName: "arrow.up.and.down") + .rotationEffect(.degrees(45)) + Text("open").font(.system(size: 12)) + } + } + ) + ) } - var shareButton: some View { - return Button(action:{ - //popover the standart apple sharing stuff - /* if let coord = AppDelegate.getAppDelegate().readViewCoordinator { - coord.shareData(self.attachment.myData as NSData) - }*/ - }){ - Image(systemName: "square.and.arrow.up") - } + // a share button converted into an AnyView + var anyViewShareButton: AnyView { + AnyView( + Button ( + action: { + // TODO + //popover the standard apple sharing stuff + /* if let coord = AppDelegate.getAppDelegate().readViewCoordinator { + coord.shareData(self.attachment.myData as NSData) + }*/ + }, + label: { + VStack { + Image(systemName: "square.and.arrow.up") + Text("share").font(.system(size: 12)) + } + } + ) + ) + } + + // a delete button converted into an AnyView + var anyViewDeleteButton: AnyView { + AnyView( + Button ( + action: { + // TODO + /* + let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName) + + do { + try FileManager.default.removeItem(at: filename) + } catch let error as NSError { + print("Error: \(error)") + } + self.isDownloaded = false + */ + }, + label: { + VStack { + Image(systemName: "trash") + Text("delete") + .font(.system(size: 12)) + } + } + ) + ) } - //each of those buttons under the card - func ActionView( _ text:String,icon: AnyView, onClick:@escaping ()->Void={})-> AnyView{ - return AnyView(Button( - action: onClick - ){VStack{ - icon - Text(text).font(.system(size: 12)) - }}) + // a download button converted into an AnyView + // dowloads the file into the documents directory + var anyViewDownloadButton: AnyView { + AnyView( + Button ( + action: { + self.download() + }, + label: { + VStack { + Image(systemName: "arrow.down.circle") + Text("download") + .font(.system(size: 12)) + } + } + ) + ) } } + diff --git a/enzevalos_iphone/persistentData/FolderRecord.swift b/enzevalos_iphone/persistentData/FolderRecord.swift index 668199e9ecd2a5e12b97087a86656f4c0f5eeb2c..06db902ecc33a4271253d0f55324c174bfd226fd 100644 --- a/enzevalos_iphone/persistentData/FolderRecord.swift +++ b/enzevalos_iphone/persistentData/FolderRecord.swift @@ -43,8 +43,11 @@ extension FolderRecord { var uids: MCOIndexSet { get { let indexSet = MCOIndexSet() - if let set = self.mailsInFolder, set.count > 0, let mails = set.allObjects as? [MailRecord] { - mails.forEach({indexSet.add(UInt64($0.uID))}) + if let set = self.mailsInFolder, set.count > 0, + let mails = set.allObjects as? [MailRecord] { + mails.forEach { + indexSet.add(UInt64($0.uID)) + } } return indexSet } @@ -71,14 +74,17 @@ extension FolderRecord { } static func lastDate(folder: String, date: Date) { - try? PersistentDataProvider.dataProvider.updateFolder(folder: folder, performingUpdates: {$0.lastUpdate = date}) - + try? PersistentDataProvider.dataProvider.updateFolder(folder: folder) { + $0.lastUpdate = date + } } } extension FolderRecord: DisplayFolder { var name: String { - if let delimiter = delimiter?.first, let n = path?.split(separator: delimiter), let last = n.last { + if let delimiter = delimiter?.first, + let n = path?.split(separator: delimiter), + let last = n.last { return String(last) } return path ?? "NO NAME" @@ -116,6 +122,4 @@ extension FolderRecord: DisplayFolder { } return 0 } - - }