aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Views
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2023-12-07 09:20:15 -0800
committerDustin Mierau <dustin@mierau.me>2023-12-07 09:20:15 -0800
commit154763b8e2b14ff2a92d5a1f1f3e14a18167e6fc (patch)
tree11217bdecc78f47a0dfc597c90a6ff882b13cbde /Hotline/Views
parente93eea234f294551c20787718cead4877429a5b7 (diff)
Some work on file display.
Diffstat (limited to 'Hotline/Views')
-rw-r--r--Hotline/Views/FilesView.swift141
-rw-r--r--Hotline/Views/TrackerView.swift4
2 files changed, 98 insertions, 47 deletions
diff --git a/Hotline/Views/FilesView.swift b/Hotline/Views/FilesView.swift
index 1395ca6..52963e0 100644
--- a/Hotline/Views/FilesView.swift
+++ b/Hotline/Views/FilesView.swift
@@ -1,22 +1,25 @@
import SwiftUI
import UniformTypeIdentifiers
-struct FilesView: View {
+struct FileListView: View {
@Environment(HotlineClient.self) private var hotline
@State private var fetched = false
+ @State var fileList: [HotlineFile] = []
+
+ var path: [String] = []
static let byteFormatter = ByteCountFormatter()
private func formattedFileSize(_ fileSize: UInt32) -> String {
-// let bcf = ByteCountFormatter()
- FilesView.byteFormatter.allowedUnits = [.useAll]
- FilesView.byteFormatter.countStyle = .file
- return FilesView.byteFormatter.string(fromByteCount: Int64(fileSize))
+ // let bcf = ByteCountFormatter()
+ FileListView.byteFormatter.allowedUnits = [.useAll]
+ FileListView.byteFormatter.countStyle = .file
+ return FileListView.byteFormatter.string(fromByteCount: Int64(fileSize))
}
private func fileIcon(name: String) -> UIImage {
-// func utTypeForFilename(_ filename: String) -> UTType? {
+ // func utTypeForFilename(_ filename: String) -> UTType? {
let fileExtension = (name as NSString).pathExtension
if let fileType = UTType(filenameExtension: fileExtension) {
print("\(name) \(fileExtension) = \(fileType)")
@@ -42,57 +45,103 @@ struct FilesView: View {
}
var body: some View {
- NavigationStack {
- List(hotline.fileList, id: \.self, children: \.files) { tree in
- if tree.isFolder {
- DisclosureGroup {
- HStack {
- HStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) {
- Image(systemName: "folder.fill")
- }
- .frame(minWidth: 25)
- Text("File").fontWeight(.medium)
- Spacer()
- Text("4").foregroundStyle(.secondary)
-// HStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) {
-// }
-// .frame(minWidth: 25)
-// ProgressView(value: 0.8)
- }
- } label: {
- HStack {
- HStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) {
- Image(systemName: "folder.fill")
- }
- .frame(minWidth: 25)
- Text(tree.name).fontWeight(.medium)
- Spacer()
- Text("\(tree.fileSize)").foregroundStyle(.secondary)
- }
+ List {
+ ForEach(fileList, id: \.self) { file in
+ if file.isFolder {
+ DisclosureGroup {
+ if !fetched {
+ ProgressView()
}
- }
- else {
+ else {
+ FileListView(path: [])
+ }
+ } label: {
HStack {
HStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) {
- Image(uiImage: fileIcon(name: tree.name))
- .renderingMode(.template)
- .foregroundColor(.accentColor)
+ Image(systemName: "folder.fill")
}
.frame(minWidth: 25)
- Text(tree.name)
+ Text(file.name).fontWeight(.medium)
Spacer()
- Text(formattedFileSize(tree.fileSize)).foregroundStyle(.gray)
+ Text("\(file.fileSize)").foregroundStyle(.secondary)
}
}
- }
- .listStyle(.plain)
- .task {
- if !fetched {
- hotline.sendGetFileList() {
- fetched = true
+ }
+ else {
+ HStack {
+ HStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) {
+ Image(uiImage: fileIcon(name: file.name))
+ .renderingMode(.template)
+ .foregroundColor(.accentColor)
+ }
+ .frame(minWidth: 25)
+ Text(file.name)
+ Spacer()
+ Text(formattedFileSize(file.fileSize)).foregroundStyle(.gray)
}
}
}
+ }
+ .listStyle(.plain)
+ .task {
+ if !fetched {
+ hotline.sendGetFileList() {
+ print("FETCHED!")
+ fetched = true
+ } reply: {
+ print("GOT FILES REPLY?")
+ fileList = hotline.fileList
+ }
+ }
+ }
+ }
+}
+
+struct FilesView: View {
+ @Environment(HotlineClient.self) private var hotline
+
+ @State private var fetched = false
+
+// let fileList: [HotlineFile]
+
+// static let byteFormatter = ByteCountFormatter()
+//
+// private func formattedFileSize(_ fileSize: UInt32) -> String {
+// // let bcf = ByteCountFormatter()
+// FilesView.byteFormatter.allowedUnits = [.useAll]
+// FilesView.byteFormatter.countStyle = .file
+// 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 {
+ NavigationStack {
+ FileListView(path: [])
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
diff --git a/Hotline/Views/TrackerView.swift b/Hotline/Views/TrackerView.swift
index 7f59118..c8d0f2e 100644
--- a/Hotline/Views/TrackerView.swift
+++ b/Hotline/Views/TrackerView.swift
@@ -92,7 +92,9 @@ struct TrackerView: View {
Text("\(server.address)").opacity(0.3).font(.system(size: 13))
}
Spacer()
- Text("\(server.users)").opacity(0.3).font(.system(size: 16)).fontWeight(.medium)
+ if server.users > 0 {
+ Text("\(server.users)").opacity(0.3).font(.system(size: 16)).fontWeight(.medium)
+ }
}
if server == selectedServer {
Spacer(minLength: 16)