diff --git a/YAPS/YAPS.xcodeproj/project.pbxproj b/YAPS/YAPS.xcodeproj/project.pbxproj index 4a52f69..ad1ae5d 100644 --- a/YAPS/YAPS.xcodeproj/project.pbxproj +++ b/YAPS/YAPS.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ EC13307424DF2B2D008063CF /* YapsFileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC13307324DF2B2D008063CF /* YapsFileCell.swift */; }; ECF5A75824E070710010A11D /* RawFileExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF5A75724E070710010A11D /* RawFileExtensions.swift */; }; ECF5A76024E41AAC0010A11D /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF5A75F24E41AAC0010A11D /* Shared.swift */; }; + ECF5A76224E93C080010A11D /* MiscHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF5A76124E93C080010A11D /* MiscHelper.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -33,6 +34,7 @@ EC13307324DF2B2D008063CF /* YapsFileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YapsFileCell.swift; sourceTree = ""; }; ECF5A75724E070710010A11D /* RawFileExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RawFileExtensions.swift; sourceTree = ""; }; ECF5A75F24E41AAC0010A11D /* Shared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shared.swift; sourceTree = ""; }; + ECF5A76124E93C080010A11D /* MiscHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MiscHelper.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -76,6 +78,7 @@ EC13306024DAE92E008063CF /* Preview Content */, EC13307024DDB3F4008063CF /* FinderHelper.swift */, ECF5A75F24E41AAC0010A11D /* Shared.swift */, + ECF5A76124E93C080010A11D /* MiscHelper.swift */, ); path = YAPS; sourceTree = ""; @@ -183,6 +186,7 @@ EC13306F24DD687F008063CF /* YapsFile.swift in Sources */, EC13307424DF2B2D008063CF /* YapsFileCell.swift in Sources */, EC13305B24DAE92D008063CF /* AppDelegate.swift in Sources */, + ECF5A76224E93C080010A11D /* MiscHelper.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/YAPS/YAPS/ContentView.swift b/YAPS/YAPS/ContentView.swift index bfef6ff..d0abc31 100644 --- a/YAPS/YAPS/ContentView.swift +++ b/YAPS/YAPS/ContentView.swift @@ -60,7 +60,7 @@ struct ContentView: View { self.setCurrentFile(newCurrent: self.fileList[newIndex], at: newIndex) } } - .frame(width: 200.0) + .frame(width: 260.0) GeometryReader { geo in diff --git a/YAPS/YAPS/FinderHelper.swift b/YAPS/YAPS/FinderHelper.swift index 8cae43b..7cd5a1e 100644 --- a/YAPS/YAPS/FinderHelper.swift +++ b/YAPS/YAPS/FinderHelper.swift @@ -65,7 +65,7 @@ class FinderHelper { } func getImageByFiletype(file: URL) -> Image { - let fileExtension = file.pathExtension + let fileExtension = file.pathExtension.lowercased() var image = Image("file") switch fileExtension { @@ -150,6 +150,19 @@ class FinderHelper { return URL(fileURLWithPath: fullPathRAW) } + func getFileAttributes(yapsFile: YapsFile) -> [FileAttributeKey: Any] { + var attributes: [FileAttributeKey: Any] = [FileAttributeKey: Any]() + + do { + attributes = try FileManager.default.attributesOfItem(atPath: yapsFile.file.path) + } + catch let error as NSError { + print("Ooops! Something went wrong: \(error)") + } + + return attributes + } + func listMounts() -> [URL] { var mounts: [URL] = [URL]() @@ -162,7 +175,7 @@ class FinderHelper { && components[1] == "Volumes" && !(components[2].contains("ime") && components[2].contains("achine")) // skip TimeMachine ^^ { - print(url) + print("Found moung at \(url)") mounts.append(url) } } diff --git a/YAPS/YAPS/MiscHelper.swift b/YAPS/YAPS/MiscHelper.swift new file mode 100644 index 0000000..3c5d47a --- /dev/null +++ b/YAPS/YAPS/MiscHelper.swift @@ -0,0 +1,30 @@ +// +// MiscHelper.swift +// YAPS +// +// Created by Gerrit Linnemann on 16.08.20. +// Copyright © 2020 Adawim UG (haftungsbeschränkt). All rights reserved. +// + +import Foundation + +class MiscHelper { + static let shared = MiscHelper() + + private init() { } + + func dateFormatDefault(inDate: Date) -> String { + let dateFormatterGet = DateFormatter() + dateFormatterGet.dateFormat = "yyyy-MM-dd HH:mm:ss" + + let dateFormatterPrint = DateFormatter() + dateFormatterPrint.dateFormat = "yyyy.MM.dd" + + if let date = dateFormatterGet.date(from: dateFormatterGet.string(from: inDate)) { + return dateFormatterPrint.string(from: date) + } else { + print("There was an error decoding the date string") + return "" + } + } +} diff --git a/YAPS/YAPS/Struct/YapsFileCell.swift b/YAPS/YAPS/Struct/YapsFileCell.swift index b66dbae..ccc7bb6 100644 --- a/YAPS/YAPS/Struct/YapsFileCell.swift +++ b/YAPS/YAPS/Struct/YapsFileCell.swift @@ -15,14 +15,55 @@ struct YapsFileCell: View { var yapsFile : YapsFile var body: some View { - - HStack { - // Icon - FinderHelper.shared.getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20) - - // Text - Text("#\(yapsFile.index) \(yapsFile.name)") - .foregroundColor(self.focused ? .blue : .gray) + Group { + HStack { + // Icon + FinderHelper.shared.getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20) + + VStack(alignment: .leading) { + // Dateiname + Text("\(yapsFile.name)") + .foregroundColor(self.focused ? .blue : .primary) + .multilineTextAlignment(.leading) + .lineLimit(1) + .aspectRatio(contentMode: .fill) + + // Details + Text( + MiscHelper.shared.dateFormatDefault(inDate: FinderHelper.shared.getFileAttributes(yapsFile: yapsFile)[FileAttributeKey.modificationDate] as! Date) + ) + .font(.footnote) + .foregroundColor(.secondary) + .multilineTextAlignment(.leading) + .lineLimit(1) + .aspectRatio(contentMode: .fill) + } + } } + //.background(self.focused ? Color.gray : Color.clear) + } +} + +struct YapsFileCell_Previews: PreviewProvider { + static var previews: some View { + Group { + VStack(alignment: .leading) { + // Dateiname + Text("dateiname.xyz") + .foregroundColor(.primary) + .multilineTextAlignment(.leading) + .lineLimit(1) + .aspectRatio(contentMode: .fill) + + // Details + Text("xyz") + .font(.footnote) + .foregroundColor(.secondary) + .multilineTextAlignment(.leading) + .lineLimit(1) + .aspectRatio(contentMode: .fill) + } + } + .background(/*@START_MENU_TOKEN@*/Color.gray/*@END_MENU_TOKEN@*/) } }