Selektieren des Fotos per Pfeiltaste
This commit is contained in:
parent
9b276f55d2
commit
641b1bf0fd
@ -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()
|
||||
|
||||
if files.count > 0 {
|
||||
self.fileList.removeAll()
|
||||
|
||||
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!")
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
VStack(alignment: .leading) {
|
||||
Button(action: {
|
||||
let files = FinderHelper.shared.askForFolderAndGetFiles()
|
||||
|
||||
if files.count > 0 {
|
||||
self.fileList.removeAll()
|
||||
self.fileList.append(contentsOf: files)
|
||||
|
||||
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())
|
||||
}
|
||||
.focusable()
|
||||
.onMoveCommand { (direction) in
|
||||
print("direction: \(direction)")
|
||||
print("#\(Shared.shared.currentFile.index) :: \(Shared.shared.currentFile.name)")
|
||||
}) {
|
||||
Text("Select Folder")
|
||||
}
|
||||
|
||||
GeometryReader { geo in
|
||||
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
|
||||
var newIndex = Shared.shared.currentFile.index
|
||||
|
||||
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)
|
||||
}
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: geo.size.width, height: geo.size.height)
|
||||
}
|
||||
|
||||
Text("\(Shared.shared.currentFile.file.path)")
|
||||
.multilineTextAlignment(.leading)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func checkCurrentFile(yapsFile: YapsFile) -> Bool {
|
||||
let result: Bool = (Shared.shared.currentFile.index == yapsFile.index)
|
||||
if result {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user