Selektieren des Fotos per Pfeiltaste

This commit is contained in:
Gerrit Linnemann 2020-08-16 07:59:28 +02:00
parent 9b276f55d2
commit 641b1bf0fd

View File

@ -13,34 +13,21 @@ struct ContentView: View {
@State var previewImg = Image("placeholder-image") @State var previewImg = Image("placeholder-image")
var body: some View { var body: some View {
VStack {
HStack { HStack {
NavigationView {
VStack(alignment: .leading) { VStack(alignment: .leading) {
HStack {
Button(action: { Button(action: {
let files = FinderHelper.shared.askForFolderAndGetFiles() let files = FinderHelper.shared.askForFolderAndGetFiles()
if files.count > 0 { if files.count > 0 {
self.fileList.removeAll() self.fileList.removeAll()
self.fileList.append(contentsOf: files) self.fileList.append(contentsOf: files)
self.resetCurrentFile()
} }
}) { }) {
Text("Select Folder") Text("Select Folder")
} }
Button(action: {
if !Shared.shared.destinationDefined {
Shared.shared.destination = FinderHelper.shared.selectFolder(modalTitle: "Choose destination folder.")
Shared.shared.destinationDefined = true
}
FinderHelper.shared.iLikeThisImage(yapsFile: Shared.shared.currentFile, destination: Shared.shared.destination)
}) {
Text("Get It!")
}
}
List { List {
ForEach(self.fileList, id: \.self) { yapsFile in ForEach(self.fileList, id: \.self) { yapsFile in
YapsFileCell(focused: self.checkCurrentFile(yapsFile: yapsFile), yapsFile: yapsFile) YapsFileCell(focused: self.checkCurrentFile(yapsFile: yapsFile), yapsFile: yapsFile)
@ -57,28 +44,49 @@ struct ContentView: View {
}) })
} }
} }
}
.listStyle(SidebarListStyle()) .listStyle(SidebarListStyle())
}
.focusable() .focusable()
.onMoveCommand { (direction) in .onMoveCommand { (direction) in
print("direction: \(direction)") var newIndex = Shared.shared.currentFile.index
print("#\(Shared.shared.currentFile.index) :: \(Shared.shared.currentFile.name)")
switch direction {
case MoveCommandDirection.down:
newIndex += 1
case MoveCommandDirection.up:
newIndex -= 1
default:
newIndex += 0
} }
let currentFile = self.fileList[newIndex]
Shared.shared.currentFile = currentFile
self.resetCurrentFile()
self.fileList[newIndex].current = true
self.previewImg = FinderHelper.shared.getImageByURL(source: self.fileList[newIndex].file)
}
}
.frame(width: 200.0)
GeometryReader { geo in GeometryReader { geo in
VStack(alignment: .center) {
self.previewImg.self self.previewImg.self
.resizable() .resizable()
.aspectRatio(contentMode: .fit) .aspectRatio(contentMode: .fit)
.frame(width: geo.size.width)
}
}
Text("\(Shared.shared.currentFile.file.path)") Text("\(Shared.shared.currentFile.file.path)")
.multilineTextAlignment(.leading) .multilineTextAlignment(.leading)
.lineLimit(1) .lineLimit(1)
} }
.aspectRatio(contentMode: .fit)
.frame(width: geo.size.width, height: geo.size.height)
} }
}
}
func checkCurrentFile(yapsFile: YapsFile) -> Bool { func checkCurrentFile(yapsFile: YapsFile) -> Bool {
let result: Bool = (Shared.shared.currentFile.index == yapsFile.index) let result: Bool = (Shared.shared.currentFile.index == yapsFile.index)