aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Views/FilesView.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2023-12-06 13:52:20 -0800
committerDustin Mierau <dustin@mierau.me>2023-12-06 13:52:20 -0800
commitc0068f11c51bb587c16dfacb73629b3c6fb67fc8 (patch)
tree20753433f348b03bb590e0fe6a4cafbe56f4c859 /Hotline/Views/FilesView.swift
parent06a2166415bca7e5fe32eac505859bdd690ab8e0 (diff)
Further work on UI organization
Diffstat (limited to 'Hotline/Views/FilesView.swift')
-rw-r--r--Hotline/Views/FilesView.swift88
1 files changed, 70 insertions, 18 deletions
diff --git a/Hotline/Views/FilesView.swift b/Hotline/Views/FilesView.swift
index 7bacbce..1b35695 100644
--- a/Hotline/Views/FilesView.swift
+++ b/Hotline/Views/FilesView.swift
@@ -1,4 +1,5 @@
import SwiftUI
+import UniformTypeIdentifiers
struct FilesView: View {
@Environment(HotlineClient.self) private var hotline
@@ -14,28 +15,79 @@ struct FilesView: View {
return FilesView.byteFormatter.string(fromByteCount: Int64(fileSize))
}
+ private func fileIcon(name: String) -> UIImage {
+// func utTypeForFilename(_ filename: String) -> UTType? {
+ let fileExtension = (name as NSString).pathExtension
+ if let fileType = UTType(filenameExtension: fileExtension) {
+ print("\(name) \(fileExtension) = \(fileType)")
+
+ if fileType.isSubtype(of: .movie) {
+ return UIImage(systemName: "play.rectangle")!
+ }
+ else if fileType.isSubtype(of: .image) {
+ return UIImage(systemName: "photo")!
+ }
+ else if fileType.isSubtype(of: .archive) {
+ return UIImage(systemName: "doc.zipper")!
+ }
+ else if fileType.isSubtype(of: .text) {
+ return UIImage(systemName: "doc.text")!
+ }
+ else {
+ return UIImage(systemName: "doc")!
+ }
+ }
+
+ return UIImage(systemName: "doc")!
+ }
+
var body: some View {
- List(hotline.fileList, id: \.self, children: \.files) { tree in
- HStack {
- if tree.isFolder {
- Image(systemName: "folder")
- Text(tree.name).bold()
- Spacer()
- Text("\(tree.fileSize)").foregroundStyle(.gray)
+ NavigationStack {
+ List(hotline.fileList, id: \.self, children: \.files) { tree in
+ HStack {
+ if tree.isFolder {
+ HStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) {
+ Image(systemName: "folder.fill")
+ }
+ .frame(minWidth: 25)
+ Text(tree.name).bold()
+ Spacer()
+ Text("\(tree.fileSize)").foregroundStyle(.gray)
+ }
+ else {
+ HStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) {
+ Image(uiImage: fileIcon(name: tree.name))
+ }
+ .frame(minWidth: 25)
+ Text(tree.name).bold()
+ Spacer()
+ Text(formattedFileSize(tree.fileSize)).foregroundStyle(.gray)
+ }
}
- else {
- Image(systemName: "doc")
- Text(tree.name).bold()
- Spacer()
- Text(formattedFileSize(tree.fileSize)).foregroundStyle(.gray)
+ }
+ .listStyle(.plain)
+ .task {
+ if !fetched {
+ hotline.sendGetFileList() {
+ fetched = true
+ }
}
}
- }
- .listStyle(.plain)
- .task {
- if !fetched {
- hotline.sendGetFileList() {
- fetched = true
+ .navigationBarTitleDisplayMode(.inline)
+ .toolbar {
+ ToolbarItem(placement: .principal) {
+ Text(hotline.server?.name ?? "")
+ .font(.headline)
+ }
+ ToolbarItem(placement: .navigationBarLeading) {
+ Button {
+ hotline.disconnect()
+ } label: {
+ Image(systemName: "xmark.circle.fill")
+ .symbolRenderingMode(.hierarchical)
+ .foregroundColor(.secondary)
+ }
+
}
}
}