diff --git a/YAPS/YAPS.xcodeproj/project.pbxproj b/YAPS/YAPS.xcodeproj/project.pbxproj index 5f47c56..cb19793 100644 --- a/YAPS/YAPS.xcodeproj/project.pbxproj +++ b/YAPS/YAPS.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ EC13306524DAE92E008063CF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EC13306324DAE92E008063CF /* Main.storyboard */; }; EC13306F24DD687F008063CF /* YapsFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC13306E24DD687F008063CF /* YapsFile.swift */; }; EC13307124DDB3F4008063CF /* FinderHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC13307024DDB3F4008063CF /* FinderHelper.swift */; }; + EC13307424DF2B2D008063CF /* YapsFileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC13307324DF2B2D008063CF /* YapsFileCell.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -27,6 +28,7 @@ EC13306724DAE92E008063CF /* YAPS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = YAPS.entitlements; sourceTree = ""; }; EC13306E24DD687F008063CF /* YapsFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YapsFile.swift; sourceTree = ""; }; EC13307024DDB3F4008063CF /* FinderHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinderHelper.swift; sourceTree = ""; }; + EC13307324DF2B2D008063CF /* YapsFileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YapsFileCell.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -59,6 +61,7 @@ EC13305924DAE92D008063CF /* YAPS */ = { isa = PBXGroup; children = ( + EC13307224DF2B05008063CF /* Struct */, EC13306D24DD685F008063CF /* Model */, EC13305A24DAE92D008063CF /* AppDelegate.swift */, EC13305C24DAE92D008063CF /* ContentView.swift */, @@ -88,6 +91,14 @@ path = Model; sourceTree = ""; }; + EC13307224DF2B05008063CF /* Struct */ = { + isa = PBXGroup; + children = ( + EC13307324DF2B2D008063CF /* YapsFileCell.swift */, + ); + path = Struct; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -162,6 +173,7 @@ EC13305D24DAE92D008063CF /* ContentView.swift in Sources */, EC13307124DDB3F4008063CF /* FinderHelper.swift in Sources */, EC13306F24DD687F008063CF /* YapsFile.swift in Sources */, + EC13307424DF2B2D008063CF /* YapsFileCell.swift in Sources */, EC13305B24DAE92D008063CF /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/YAPS/YAPS/ContentView.swift b/YAPS/YAPS/ContentView.swift index 2301cd8..049f61a 100644 --- a/YAPS/YAPS/ContentView.swift +++ b/YAPS/YAPS/ContentView.swift @@ -9,7 +9,6 @@ import SwiftUI struct ContentView: View { - @State var fileList = [YapsFile]() @State var previewImg = Image("placeholder-image") @@ -20,8 +19,12 @@ struct ContentView: View { VStack(alignment: .leading) { HStack { Button(action: { - self.fileList.removeAll() - self.fileList.append(contentsOf: self.finderHelper.selectFolder()) + let files = self.finderHelper.selectFolder() + + if files.count > 0 { + self.fileList.removeAll() + self.fileList.append(contentsOf: files) + } }) { Text("Select Folder") } @@ -29,21 +32,21 @@ struct ContentView: View { List { ForEach(self.fileList, id: \.self) { yapsFile in - HStack { - self.finderHelper.getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20) - Text(yapsFile.name) - } + YapsFileCell(yapsFile: yapsFile) + .focusable() .onTapGesture(perform: { let selectedImageURL: URL = yapsFile.file print("pressed \(yapsFile.name)") - self.previewImg = self.finderHelper.getImageByURL(source: selectedImageURL) + self.previewImg = FinderHelper().getImageByURL(source: selectedImageURL) .resizable() }) + .onMoveCommand { (direction) in + print("direction: \(direction)") + } } } - .focusable() } .frame(width: 150.0) diff --git a/YAPS/YAPS/Model/YapsFile.swift b/YAPS/YAPS/Model/YapsFile.swift index 1f4dbd7..2576171 100644 --- a/YAPS/YAPS/Model/YapsFile.swift +++ b/YAPS/YAPS/Model/YapsFile.swift @@ -11,6 +11,6 @@ import Foundation struct YapsFile: Identifiable, Hashable { let id = UUID() - var name: String - var file: URL + let name: String + let file: URL } diff --git a/YAPS/YAPS/Struct/YapsFileCell.swift b/YAPS/YAPS/Struct/YapsFileCell.swift new file mode 100644 index 0000000..9831803 --- /dev/null +++ b/YAPS/YAPS/Struct/YapsFileCell.swift @@ -0,0 +1,32 @@ +// +// YapsFileCell.swift +// YAPS +// +// Created by Gerrit Linnemann on 08.08.20. +// Copyright © 2020 Adawim UG (haftungsbeschränkt). All rights reserved. +// + +import Foundation +import SwiftUI + +struct YapsFileCell: View { + @State var focused: Bool = false + + var yapsFile : YapsFile + + var body: some View { + + HStack { + // Icon + FinderHelper().getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20) + + // Text + Text(yapsFile.name) + .foregroundColor(self.focused ? .red : .green) + } + .focusable(true, onFocusChange: { (focusChanged) in + self.focused = focusChanged + print("focus changed \(focusChanged)") + }) + } +}