94 lines
2.8 KiB
Swift
94 lines
2.8 KiB
Swift
//
|
|
// ContentView.swift
|
|
// YAPS
|
|
//
|
|
// Created by Gerrit Linnemann on 05.08.20.
|
|
// Copyright © 2020 Adawim UG (haftungsbeschränkt). All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
@State var fileList = [YapsFile]()
|
|
@State var tabbedFile: YapsFile = YapsFile(name: "EMPTY", file: .init(fileURLWithPath: "Y"))
|
|
@State var previewImg = Image("placeholder-image")
|
|
@State var destinationDefined: Bool = false
|
|
@State var destinationURL: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
|
|
|
let finderHelper: FinderHelper = FinderHelper()
|
|
|
|
|
|
var body: some View {
|
|
VStack {
|
|
HStack {
|
|
VStack(alignment: .leading) {
|
|
HStack {
|
|
Button(action: {
|
|
let files = self.finderHelper.askForFolderAndGetFiles()
|
|
|
|
if files.count > 0 {
|
|
self.fileList.removeAll()
|
|
self.fileList.append(contentsOf: files)
|
|
}
|
|
}) {
|
|
Text("Select Folder")
|
|
}
|
|
|
|
Button(action: {
|
|
if !self.destinationDefined {
|
|
self.destinationURL = self.finderHelper.selectFolder(modalTitle: "Choose destination folder.")
|
|
self.destinationDefined = true
|
|
}
|
|
self.finderHelper.iLikeThisImage(yapsFile: self.tabbedFile, destination: self.destinationURL)
|
|
}) {
|
|
Text("Get It!")
|
|
}
|
|
}
|
|
|
|
List {
|
|
ForEach(self.fileList, id: \.self) { yapsFile in
|
|
YapsFileCell(yapsFile: yapsFile)
|
|
.focusable(true, onFocusChange: { (focusChanged) in
|
|
//self.focused = focusChanged
|
|
print("focus changed \(focusChanged)")
|
|
})
|
|
.onTapGesture(perform: {
|
|
let selectedImageURL: URL = yapsFile.file
|
|
|
|
print("pressed \(yapsFile.name)")
|
|
|
|
self.previewImg = FinderHelper().getImageByURL(source: selectedImageURL)
|
|
.resizable()
|
|
|
|
self.tabbedFile = yapsFile
|
|
})
|
|
.onMoveCommand { (direction) in
|
|
print("direction: \(direction)")
|
|
}
|
|
}
|
|
}
|
|
.listStyle(SidebarListStyle())
|
|
}
|
|
.frame(width: 200.0)
|
|
|
|
GeometryReader { geo in
|
|
self.previewImg.self
|
|
.resizable()
|
|
.aspectRatio(contentMode: .fit)
|
|
.frame(width: geo.size.width)
|
|
}
|
|
}
|
|
|
|
Text("\(self.tabbedFile.file.absoluteString)")
|
|
.multilineTextAlignment(.leading)
|
|
.lineLimit(1)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContentView()
|
|
}
|
|
}
|