Ausgabe des Änderungsdatums zu einer Datei

This commit is contained in:
Gerrit Linnemann 2020-08-16 12:36:05 +02:00
parent bc3da08d0c
commit e8760f5245
5 changed files with 99 additions and 11 deletions

View File

@ -17,6 +17,7 @@
EC13307424DF2B2D008063CF /* YapsFileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC13307324DF2B2D008063CF /* YapsFileCell.swift */; }; EC13307424DF2B2D008063CF /* YapsFileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC13307324DF2B2D008063CF /* YapsFileCell.swift */; };
ECF5A75824E070710010A11D /* RawFileExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF5A75724E070710010A11D /* RawFileExtensions.swift */; }; ECF5A75824E070710010A11D /* RawFileExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF5A75724E070710010A11D /* RawFileExtensions.swift */; };
ECF5A76024E41AAC0010A11D /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF5A75F24E41AAC0010A11D /* Shared.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 */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
@ -33,6 +34,7 @@
EC13307324DF2B2D008063CF /* YapsFileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YapsFileCell.swift; sourceTree = "<group>"; }; EC13307324DF2B2D008063CF /* YapsFileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YapsFileCell.swift; sourceTree = "<group>"; };
ECF5A75724E070710010A11D /* RawFileExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RawFileExtensions.swift; sourceTree = "<group>"; }; ECF5A75724E070710010A11D /* RawFileExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RawFileExtensions.swift; sourceTree = "<group>"; };
ECF5A75F24E41AAC0010A11D /* Shared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shared.swift; sourceTree = "<group>"; }; ECF5A75F24E41AAC0010A11D /* Shared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shared.swift; sourceTree = "<group>"; };
ECF5A76124E93C080010A11D /* MiscHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MiscHelper.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -76,6 +78,7 @@
EC13306024DAE92E008063CF /* Preview Content */, EC13306024DAE92E008063CF /* Preview Content */,
EC13307024DDB3F4008063CF /* FinderHelper.swift */, EC13307024DDB3F4008063CF /* FinderHelper.swift */,
ECF5A75F24E41AAC0010A11D /* Shared.swift */, ECF5A75F24E41AAC0010A11D /* Shared.swift */,
ECF5A76124E93C080010A11D /* MiscHelper.swift */,
); );
path = YAPS; path = YAPS;
sourceTree = "<group>"; sourceTree = "<group>";
@ -183,6 +186,7 @@
EC13306F24DD687F008063CF /* YapsFile.swift in Sources */, EC13306F24DD687F008063CF /* YapsFile.swift in Sources */,
EC13307424DF2B2D008063CF /* YapsFileCell.swift in Sources */, EC13307424DF2B2D008063CF /* YapsFileCell.swift in Sources */,
EC13305B24DAE92D008063CF /* AppDelegate.swift in Sources */, EC13305B24DAE92D008063CF /* AppDelegate.swift in Sources */,
ECF5A76224E93C080010A11D /* MiscHelper.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@ -60,7 +60,7 @@ struct ContentView: View {
self.setCurrentFile(newCurrent: self.fileList[newIndex], at: newIndex) self.setCurrentFile(newCurrent: self.fileList[newIndex], at: newIndex)
} }
} }
.frame(width: 200.0) .frame(width: 260.0)
GeometryReader { geo in GeometryReader { geo in

View File

@ -65,7 +65,7 @@ class FinderHelper {
} }
func getImageByFiletype(file: URL) -> Image { func getImageByFiletype(file: URL) -> Image {
let fileExtension = file.pathExtension let fileExtension = file.pathExtension.lowercased()
var image = Image("file") var image = Image("file")
switch fileExtension { switch fileExtension {
@ -150,6 +150,19 @@ class FinderHelper {
return URL(fileURLWithPath: fullPathRAW) 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] { func listMounts() -> [URL] {
var mounts: [URL] = [URL]() var mounts: [URL] = [URL]()
@ -162,7 +175,7 @@ class FinderHelper {
&& components[1] == "Volumes" && components[1] == "Volumes"
&& !(components[2].contains("ime") && components[2].contains("achine")) // skip TimeMachine ^^ && !(components[2].contains("ime") && components[2].contains("achine")) // skip TimeMachine ^^
{ {
print(url) print("Found moung at \(url)")
mounts.append(url) mounts.append(url)
} }
} }

View File

@ -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 ""
}
}
}

View File

@ -15,14 +15,55 @@ struct YapsFileCell: View {
var yapsFile : YapsFile var yapsFile : YapsFile
var body: some View { var body: some View {
Group {
HStack { HStack {
// Icon // Icon
FinderHelper.shared.getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20) FinderHelper.shared.getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20)
// Text VStack(alignment: .leading) {
Text("#\(yapsFile.index) \(yapsFile.name)") // Dateiname
.foregroundColor(self.focused ? .blue : .gray) 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@*/)
}
} }