Cell-File

This commit is contained in:
Gerrit Linnemann 2020-08-08 21:34:24 +02:00
parent 0dce6e3988
commit 661f8c7dca
4 changed files with 58 additions and 11 deletions

View File

@ -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 = "<group>"; };
EC13306E24DD687F008063CF /* YapsFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YapsFile.swift; sourceTree = "<group>"; };
EC13307024DDB3F4008063CF /* FinderHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinderHelper.swift; sourceTree = "<group>"; };
EC13307324DF2B2D008063CF /* YapsFileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YapsFileCell.swift; sourceTree = "<group>"; };
/* 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 = "<group>";
};
EC13307224DF2B05008063CF /* Struct */ = {
isa = PBXGroup;
children = (
EC13307324DF2B2D008063CF /* YapsFileCell.swift */,
);
path = Struct;
sourceTree = "<group>";
};
/* 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;

View File

@ -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: {
let files = self.finderHelper.selectFolder()
if files.count > 0 {
self.fileList.removeAll()
self.fileList.append(contentsOf: self.finderHelper.selectFolder())
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)

View File

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

View File

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