Commit af0d5b0a authored by Oliver Wiese's avatar Oliver Wiese

update attachment view

parent dc93fb51
......@@ -585,6 +585,7 @@
47A5D6DD2294B5480084F81D /* AppAuth.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AppAuth.framework; sourceTree = BUILT_PRODUCTS_DIR; };
47A5D6E12294BF3A0084F81D /* TempKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TempKey.swift; sourceTree = "<group>"; };
47A5D6E32294BFF50084F81D /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
47AAFA6B243CB58F00949015 /* enzevalos_iphone 11.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "enzevalos_iphone 11.xcdatamodel"; sourceTree = "<group>"; };
47B2318A1F0D458100961B28 /* enzevalos_iphone 2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "enzevalos_iphone 2.xcdatamodel"; sourceTree = "<group>"; };
47C036FE2347C0F4006295E8 /* ImportKeyOverviewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportKeyOverviewController.swift; sourceTree = "<group>"; };
47C037022347D4D1006295E8 /* PasteKeyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasteKeyViewController.swift; sourceTree = "<group>"; };
......@@ -2965,6 +2966,7 @@
A135267F1D955BDF00D3BFE1 /* enzevalos_iphone.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
47AAFA6B243CB58F00949015 /* enzevalos_iphone 11.xcdatamodel */,
47D1BB052431F81C001F1EC9 /* enzevalos_iphone 10.xcdatamodel */,
670159DF240FB4E800797FA5 /* enzevalos_iphone 9.xcdatamodel */,
4751C6FD2344D169006B2A4D /* enzevalos_iphone 8.xcdatamodel */,
......
......@@ -450,6 +450,18 @@ extension PersistentMail: DisplayMail {
return self
}
var displayAttachments: [DisplayAttachment] {
var attachments = [DisplayAttachment]()
if let coreDataAttachment = self.attachments {
for att in coreDataAttachment {
if let att = att as? Attachment {
attachments.append(att)
}
}
}
return attachments
}
var folderType: FolderType {
return .Other // TODO FIX
}
......@@ -468,6 +480,17 @@ extension PersistentMail: DisplayMail {
func markAsRead(isRead: Bool) {
self.isRead = isRead
}
}
extension Attachment: DisplayAttachment {
var myName: String {
return name ?? "No name"
}
var myData: Data {
return data ?? Data()
}
}
......@@ -45,21 +45,24 @@ struct KeyRecordRow: View {
*/
private func mailListView() -> AnyView {
let spacing = CGFloat(10)
let offset = -(spacing / 2)
if let first = self.first {
if let second = self.second {
return AnyView(VStack(alignment: .leading, spacing: spacing) {
MailView(mail: first)
Divider()
MailView(mail: second)
.background(Stroke(offsetY: offset))
})
}
.padding(.top, 10))
} else {
return AnyView(VStack(alignment: .leading,spacing: spacing) {
MailView(mail: first)
Divider()
Text(NSLocalizedString("NoFurtherMessages", comment: "No more Mails"))
.background(Stroke(offsetY: offset))
})
}
.padding(.top, 10))
}
} else {
return AnyView(Text("NO MAILS..."))
......
......@@ -17,20 +17,20 @@
import SwiftUI
struct ReadMainView: View {
struct ReadMainView <M: DisplayMail>: View {
public var mail:PersistentMail
public var mail: M
public var coord: ReadViewCoordinator
@State var currentScreen: Int = 1 //doesnt work
@State var isSecIndExpanded:Bool=false
@State var isSecIndExpanded:Bool = false
var body: some View {
//TODO: put into zstack instead
VStack(spacing:0){
SecIndicator //TODO: Why the hell does expanding it reset the whole tabview
//SecIndicator //TODO: Why the hell does expanding it reset the whole tabview
TabView{
ForEach(Tabs, id: \.id ){ tab in
tab.content
......@@ -42,10 +42,10 @@ struct ReadMainView: View {
}
.animation(.easeInOut(duration: 0.4))
}
.navigationBarTitle(Text((mail.trouble ? "❌" :( mail.isSecure ? "🔒" : "👀" )) + " " + (mail.subject ?? ""))
, displayMode: .inline) //TODO: make smooth or find better solution
// .navigationBarTitle(Text((mail.trouble ? "❌" :( mail.isSecure ? "🔒" : "👀" )) + " " + (mail.subject ?? ""))
// , displayMode: .inline) //TODO: make smooth or find better solution
.navigationBarItems(trailing: moreInfoButton)
.onAppear(perform: self.coord.setup)
//.onAppear(perform: self.coord.setup)
.onDisappear(perform: self.coord.reset)
}
......@@ -56,17 +56,17 @@ struct ReadMainView: View {
Tab(
image: Image(systemName: "person.fill"),
description: "sender",
content: AnyView(SenderViewMain<PersistentMail, KeyRecord>(mail: mail))
content: AnyView(SenderViewMain<M>(mail: mail))
),
Tab(
image: Image(systemName: "text.bubble.fill"),
description: "message",
content: AnyView(MessageViewMain<PersistentMail>(mail: mail))
content: AnyView(MessageViewMain<M>(mail: mail))
),
Tab(
image: Image(systemName: "rectangle.and.paperclip"),
description: "attachments",
content: AnyView(AttachmentsViewMain(mail: mail, coord: coord))
content: AnyView(AttachmentsViewMain(attachments: mail.displayAttachments, dlAll: true))
)
]
}
......@@ -77,7 +77,7 @@ struct ReadMainView: View {
Image(systemName: isSecIndExpanded ? "arrow.up.circle" : "info.circle")
}
}
/*
//securityIndicator
var SecIndicator:some View{
get{
......@@ -119,6 +119,7 @@ struct ReadMainView: View {
}
}
}
*/
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -54,10 +54,6 @@ struct CardV<Content:View>: View{
)
.gesture (
TapGesture()
/*.updating($isTapDownB, body: { (currentState, state, transaction) in
//sadly doesnt work ; iwant to make it visable if a user touches
self.isTapDown=state
})*/
.onEnded{ _ in
self.isTapDownB.toggle()
self.isAdvancedVisable.toggle()
......
......@@ -17,47 +17,35 @@
import SwiftUI
struct AttachmentsViewMain: View {
let mail:PersistentMail
let coord:ReadViewCoordinator
//gets the attachments as attachments not as nsElemets
@State var Attachments:[Attachment]? = nil
func attachmentList()->[Attachment]{
if Attachments != nil { return Attachments!}//if we already converted the attachments
print((mail.attachments ?? []).count)
var atts:[Attachment]=[]
for at in mail.attachments ?? []{
atts.append(at as! Attachment)
}
Attachments=atts
return atts
}
struct AttachmentsViewMain: View {
// Gets the attachments as attachments not as nsElemets
@State var attachments: [DisplayAttachment]
// Whether the Download all button was clicked
@State var dlAll = true;
var body: some View {
VStack{
Spacer()
Spacer()
linkSection
attachmentSection
// TODO: Add link section
// check if there even are attachments to be displayed
if attachments.count == 0{
noAttachments
}
else {
attachmentsView
}
}
}
@State var dlAll=false;//whether the Download all button was clicked
var attachments: some View {
var attachmentsView: some View {
return VStack(alignment: .leading, spacing: 5){
//headline
// headline
HStack{
Text(NSLocalizedString("attachmentsHeadline", comment: "attachments:"))
Text(NSLocalizedString("ReadView.Attachments.Headline", comment: "attachments:"))
.font(.system(size:24)).fontWeight(.light)
Spacer()
FloatingActionButton(
/*FloatingActionButton(
radius:10,
onShortPress:{
self.dlAll=true
......@@ -66,79 +54,57 @@ struct AttachmentsViewMain: View {
Image(systemName: dlAll ? "arrow.down" : "arrow.down.circle")
Text(dlAll ? NSLocalizedString("download again", comment: "") : NSLocalizedString("download all", comment: "")).font(.footnote)
}
}
} */
}
.padding(.horizontal , 15)
.padding(3)
//main attachment view
// main attachment view
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 5) {
ForEach(0..<attachmentList().count) { i in
ForEach(0..<attachments.count) { i in
AttPrev(
attachment: self.attachmentList()[i],
preload: self.dlAll,
//needed to pop over sharing functionality
coord: self.coord
attachment: self.attachments[i],
preload: self.dlAll
)
}
}.onAppear(perform: {
print("appeaer")
print(self.mail.attachments!.count)
})
}
}
}.padding(.top, 30)
}
.padding(.top, 30)
.padding(.bottom,10)
}
var noAttachments: some View {
return Text(NSLocalizedString("no attachments", comment: "")).font(.footnote).padding(30)
}
var attachmentSection : AnyView {
//check if there even are attachments to be displayed
if !mail.hasAttachment && mail.attachments!.count==0{
return AnyView(noAttachments)
}
return AnyView(attachments)
}
//TODO
var linkSection: some View {
return Text(NSLocalizedString("linksFuture", comment: "")).font(.footnote).padding(20)
return Text(NSLocalizedString("ReadView.Attachments.No", comment: "")).font(.footnote).padding(30)
}
}
/*struct AttachmentsViewMain_Previews: PreviewProvider {
struct AttachmentsViewMain_Previews: PreviewProvider {
static var previews: some View {
AttachmentsViewMain()
AttachmentsViewMain(attachments: [PseudoAttachment()])
}
}*/
}
// MARK: one AttachmentPreview
struct AttPrev:View{
var attachment:Attachment
var attachment: DisplayAttachment
var preload = false
let coord:ReadViewCoordinator
@State var isDownloaded:Bool = false
@State var isFullScreen:Bool = false
@State var isDownloaded: Bool = false
@State var isFullScreen: Bool = false
func download(){
func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.name!)
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName)
do {
try self.attachment.data!.write(to: filename)
try self.attachment.myData.write(to: filename)
} catch let error as NSError {
print("Error: \(error)")
}
......@@ -151,7 +117,7 @@ struct AttPrev:View{
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.name!)
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName)
if FileManager.default.fileExists(atPath: filename.path){self.isDownloaded = true}
}
......@@ -160,14 +126,15 @@ struct AttPrev:View{
if preload {self.download()}
//this QuickLookView has to be defined here so it reloads on every state-change
let QLV = QuickLookView(name: self.attachment.name!, data: self.attachment.data!, shallDL: self.isDownloaded)
let QLV = QuickLookView(name: self.attachment.myName, data: self.attachment.myData, shallDL: self.isDownloaded)
return VStack{
Group{
CardV(title: self.attachment.name ?? "",
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: {
......@@ -185,7 +152,7 @@ struct AttPrev:View{
self.isDownloaded = false
}
),
), */
self.ActionView(NSLocalizedString("open", comment: ""),
icon: AnyView(Image(systemName: "arrow.up.and.down").rotationEffect(.degrees(45))),
onClick: {self.isFullScreen.toggle()}
......@@ -216,22 +183,39 @@ struct AttPrev:View{
.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.name!, data: self.attachment.data!)
NavigationLink(destination: QuickLookView(name: self.attachment.myName, data: self.attachment.myData)
.navigationBarItems(trailing: shareButton), isActive: self.$isFullScreen){Text("loi")}.hidden()
}
.onAppear(perform:{
.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)
do {
try FileManager.default.removeItem(at: filename)
} catch let error as NSError {
print("Error: \(error)")
}
self.isDownloaded = false
print("======== Attachment DISAPPEAR -> REMOVE FILES ========")
})
}
var shareButton: some View {
return Button(action:{
//popover the standart apple sharing stuff
self.coord.shareData(self.attachment.data! as NSData)
if let coord = AppDelegate.getAppDelegate().readViewCoordinator {
coord.shareData(self.attachment.myData as NSData)
}
}){
Image(systemName: "square.and.arrow.up")
}
......
//
// Warning_MessageView.swift
// enzevalos_iphone
//
// Created by melicoa97 on 11.03.20.
// Copyright © 2020 fu-berlin. All rights reserved.
//
import SwiftUI
struct Warning_MessageView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello World!"/*@END_MENU_TOKEN@*/)
}
}
struct Warning_MessageView_Previews: PreviewProvider {
static var previews: some View {
Warning_MessageView()
}
}
......@@ -47,7 +47,7 @@ struct MessageViewMain <M: DisplayMail>: View {
}
FloatingReplyButtons
}.onAppear(perform: {self.mail.markAsRead(isRead: true)})
}
}
var Subjectbar: some View{
VStack(alignment: .leading){
......
......@@ -22,7 +22,7 @@
import SwiftUI
import CoreLocation
struct SenderViewMain <M: DisplayMail, C: DisplayContact>: View {
struct SenderViewMain <M: DisplayMail>: View {
let mail: M
......@@ -171,7 +171,7 @@ struct SenderView_Previews: PreviewProvider {
]
return ForEach(deviceNames, id: \.self) {deviceName in
SenderViewMain<PseuoMail, PseudoContact>(mail: mail)
SenderViewMain<PseuoMail>(mail: mail)
.previewDisplayName(deviceName)
.previewDevice(.init(rawValue: deviceName))
//.colorScheme(.dark)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment