Skip to content
Snippets Groups Projects
Commit 185f9ee9 authored by Aylin's avatar Aylin
Browse files

Final Version?

parent 1dd6d4f9
Branches
No related tags found
1 merge request!83Resolve "Integrate attachment functionality in new ComposeView"
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -10,8 +10,8 @@ import Foundation
struct Attachment: DisplayAttachment, Identifiable, Equatable {
// DisplayAttachment
var fileName: String
var fileData: Data
var myName: String
var myData: Data
// Identifiable
var id = UUID()
......@@ -23,7 +23,7 @@ struct Attachment: DisplayAttachment, Identifiable, Equatable {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
let wholePath = getDocumentsDirectory().appendingPathComponent(self.fileName)
let wholePath = getDocumentsDirectory().appendingPathComponent(self.myName)
do {
try FileManager.default.removeItem(at: wholePath)
......@@ -35,7 +35,7 @@ struct Attachment: DisplayAttachment, Identifiable, Equatable {
/// a func that returns the size of the calling attachment file as a string
func countData() -> String {
// size in byte
var sizeOfData = Double(self.fileData.count)
var sizeOfData = Double(self.myData.count)
// smaller than 1KB
if sizeOfData < 1000 {
......
......@@ -16,6 +16,7 @@ struct AddAttachmentsView: View {
if let newImage = imageAttachment {
// TODO: This is closure is never executed because
// imageAttachments is not set properly
// check ImagePicker
print("user chose image")
}
}
......@@ -33,8 +34,7 @@ struct AddAttachmentsView: View {
attachFileButton
Spacer()
imageUploadButton
Spacer()
.frame(height: 3)
.padding(.bottom, 3)
}
filePreviews
......@@ -48,10 +48,10 @@ struct AddAttachmentsView: View {
case .imagePicker:
ImagePicker(image: $imageAttachment)
case let .fullScreenPreview(attachment):
Text(attachment.fileName)
Text(attachment.myName)
.font(Font.body.weight(.semibold))
QuickLookView(name: attachment.fileName,
data: attachment.fileData,
QuickLookView(name: attachment.myName,
data: attachment.myData,
shallDL: false)
.aspectRatio(100/141, contentMode: .fit)
}
......@@ -77,7 +77,7 @@ struct AddAttachmentsView: View {
let fileData = try Data(contentsOf: fileURL)
// create Attachment and add in to the attachments list
let newAttachment = Attachment(fileName: fileName, fileData: fileData)
let newAttachment = Attachment(myName: fileName, myData: fileData)
model.attachments.append(newAttachment)
} catch {
// Error while loading file
......@@ -115,7 +115,7 @@ struct AddAttachmentsView: View {
// shallDL has to be true here, because QuickLookView will download
// the file into the Documents Directory for us
// it then uses that DD file to create a preview of the content
QuickLookView(name: attachment.fileName, data: attachment.fileData, shallDL: true)
QuickLookView(name: attachment.myName, data: attachment.myData, shallDL: true)
.padding(3)
.background(RoundedRectangle(cornerRadius: 5)
.stroke(Color.secondary, lineWidth: 2))
......@@ -143,7 +143,7 @@ struct AddAttachmentsView: View {
Spacer()
// display file name and size
Text(attachment.fileName + ", " + attachment.countData())
Text(attachment.myName + ", " + attachment.countData())
.lineLimit(1)
.font(.caption)
.foregroundColor(.secondary)
......
......@@ -73,7 +73,7 @@ class ComposeModel: ObservableObject {
var convertedAttachments: [MCOAttachment] = []
for current in attachments{
do {
if let newMCOAttachment = MCOAttachment.init(data: current.fileData, filename: current.fileName) {
if let newMCOAttachment = MCOAttachment.init(data: current.myData, filename: current.myName) {
convertedAttachments.append(newMCOAttachment)
print("Converted and attached file")
}
......
......@@ -114,8 +114,8 @@ protocol DisplayFolder {
}
protocol DisplayAttachment {
var fileName: String { get }
var fileData: Data { get }
var myName: String { get }
var myData: Data { get }
}
protocol DisplayContact {
......
......@@ -91,10 +91,10 @@ struct AttPrev:View{
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.fileName)
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName)
do {
try self.attachment.fileData.write(to: filename)
try self.attachment.myData.write(to: filename)
} catch let error as NSError {
print("Error: \(error)")
}
......@@ -107,7 +107,7 @@ struct AttPrev:View{
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.fileName)
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName)
if FileManager.default.fileExists(atPath: filename.path){self.isDownloaded = true}
}
......@@ -116,10 +116,10 @@ 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.fileName, data: self.attachment.fileData, shallDL: self.isDownloaded)
let QLV = QuickLookView(name: self.attachment.myName, data: self.attachment.myData, shallDL: self.isDownloaded)
return VStack{
Group{
CardV(title: self.attachment.fileName,
CardV(title: self.attachment.myName,
//those are the actions visable under the cklicked preview
actions: self.isDownloaded||self.preload ?
......@@ -175,7 +175,7 @@ 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.fileName, data: self.attachment.fileData)
NavigationLink(destination: QuickLookView(name: self.attachment.myName, data: self.attachment.myData)
.navigationBarItems(trailing: shareButton), isActive: self.$isFullScreen){Text("loi")}.hidden()
}
......@@ -190,7 +190,7 @@ struct AttPrev:View{
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.fileName)
let filename = getDocumentsDirectory().appendingPathComponent(self.attachment.myName)
do {
try FileManager.default.removeItem(at: filename)
......
......@@ -19,11 +19,11 @@ extension AttachmentRecord {
}
extension AttachmentRecord: DisplayAttachment {
var fileName: String {
var myName: String {
return name ?? "NoName!"
}
var fileData: Data {
var myData: Data {
return data ?? Data()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment