-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileDetailView.swift
84 lines (74 loc) · 2.5 KB
/
FileDetailView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// FileDetailView.swift
//
// Created by Speedyfriend67 on 28.06.24
//
import SwiftUI
struct FileDetailView: View {
var fileURL: URL
var body: some View {
VStack {
Spacer()
VStack(spacing: 10) {
Text(fileName)
.font(.largeTitle)
.fontWeight(.semibold)
.foregroundColor(.gray)
Text(fileDescription)
.font(.subheadline)
.foregroundColor(.gray)
Text(fileSize)
.font(.subheadline)
.foregroundColor(.gray)
}
Spacer()
HStack {
Spacer()
Button(action: {
shareFile()
}) {
Image(systemName: "square.and.arrow.up")
.font(.title)
.foregroundColor(.blue)
}
.padding()
}
}
.background(Color.black)
.edgesIgnoringSafeArea(.all)
.navigationTitle("File Details")
.navigationBarTitleDisplayMode(.inline)
.onAppear {
loadFileDetails()
}
}
@State private var fileName: String = ""
@State private var fileDescription: String = ""
@State private var fileSize: String = ""
private func loadFileDetails() {
fileName = fileURL.lastPathComponent
fileDescription = fileURL.pathExtension.uppercased() + " File"
do {
let attributes = try FileManager.default.attributesOfItem(atPath: fileURL.path)
if let size = attributes[.size] as? UInt64 {
fileSize = ByteCountFormatter.string(fromByteCount: Int64(size), countStyle: .file)
}
} catch {
fileSize = "Unknown size"
}
}
private func shareFile() {
let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
let scenes = UIApplication.shared.connectedScenes
let windowScene = scenes.first as? UIWindowScene
let window = windowScene?.windows.first
if let topController = window?.rootViewController {
topController.present(activityViewController, animated: true, completion: nil)
}
}
}
struct FileDetailView_Previews: PreviewProvider {
static var previews: some View {
FileDetailView(fileURL: URL(fileURLWithPath: "/path/to/file.ipa"))
}
}