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,73 +13,81 @@ struct ContentView: View {
@State var previewImg = Image("placeholder-image")
var body: some View {
VStack {
HStack {
NavigationView {
VStack(alignment: .leading) {
HStack {
Button(action: {
let files = FinderHelper.shared.askForFolderAndGetFiles()
HStack {
VStack(alignment: .leading) {
Button(action: {
let files = FinderHelper.shared.askForFolderAndGetFiles()
if files.count > 0 {
self.fileList.removeAll()
if files.count > 0 {
self.fileList.removeAll()
self.fileList.append(contentsOf: files)
self.fileList.append(contentsOf: files)
}
}) {
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 {
ForEach(self.fileList, id: \.self) { yapsFile in
YapsFileCell(focused: self.checkCurrentFile(yapsFile: yapsFile), yapsFile: yapsFile)
.onTapGesture(perform: {
print("pressed \(yapsFile.name)")
self.previewImg = FinderHelper.shared.getImageByURL(source: yapsFile.file)
.resizable()
Shared.shared.currentFile = yapsFile
self.resetCurrentFile()
self.fileList[yapsFile.index].current = true
})
}
}
self.resetCurrentFile()
}
.listStyle(SidebarListStyle())
}) {
Text("Select Folder")
}
List {
ForEach(self.fileList, id: \.self) { yapsFile in
YapsFileCell(focused: self.checkCurrentFile(yapsFile: yapsFile), yapsFile: yapsFile)
.onTapGesture(perform: {
print("pressed \(yapsFile.name)")
self.previewImg = FinderHelper.shared.getImageByURL(source: yapsFile.file)
.resizable()
Shared.shared.currentFile = yapsFile
self.resetCurrentFile()
self.fileList[yapsFile.index].current = true
})
}
}
.listStyle(SidebarListStyle())
.focusable()
.onMoveCommand { (direction) in
print("direction: \(direction)")
print("#\(Shared.shared.currentFile.index) :: \(Shared.shared.currentFile.name)")
}
var newIndex = Shared.shared.currentFile.index
GeometryReader { geo in
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
VStack(alignment: .center) {
self.previewImg.self
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: geo.size.width)
}
}
Text("\(Shared.shared.currentFile.file.path)")
.multilineTextAlignment(.leading)
.lineLimit(1)
Text("\(Shared.shared.currentFile.file.path)")
.multilineTextAlignment(.leading)
.lineLimit(1)
}
.aspectRatio(contentMode: .fit)
.frame(width: geo.size.width, height: geo.size.height)
}
}
}
func checkCurrentFile(yapsFile: YapsFile) -> Bool {
let result: Bool = (Shared.shared.currentFile.index == yapsFile.index)
if result {