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