Skip to content

Commit a69dfbb

Browse files
committed
[FileManager] SDCard with Preview
1 parent 6726569 commit a69dfbb

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

Flipper/Packages/Peripheral/Sources/RPC/Model/Storage.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ public struct StorageSpace: Equatable {
55
public let total: Int
66

77
public var used: Int { total - free }
8+
9+
public init(free: Int, total: Int) {
10+
self.free = free
11+
self.total = total
12+
}
813
}
914

1015
public enum Element: Equatable {

Flipper/iOS/UI/FileManager/Components/SDCardInfo.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ extension FileManagerView {
55
struct SDCardInfo: View {
66
let storage: StorageSpace?
77

8-
init(_ storage: StorageSpace?) {
9-
self.storage = storage
10-
}
11-
128
var body: some View {
139
HStack(spacing: 32) {
1410
VStack(alignment: .leading, spacing: 12) {
@@ -32,7 +28,7 @@ extension FileManagerView {
3228
.frame(width: 84, height: 84)
3329
.foregroundColor(.primary)
3430
}
35-
.padding(8)
31+
.padding(12)
3632
.background(Color.groupedBackground)
3733
.cornerRadius(12)
3834
}
@@ -97,3 +93,13 @@ fileprivate extension StorageSpace {
9793
return CGFloat(used) / CGFloat(total)
9894
}
9995
}
96+
97+
#Preview {
98+
VStack {
99+
FileManagerView.SDCardInfo(storage: nil)
100+
101+
FileManagerView.SDCardInfo(storage: .init(free: 10, total: 40))
102+
}
103+
.padding(12)
104+
.background(Color.background)
105+
}

Flipper/iOS/UI/FileManager/FileManagerListing.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ extension FileManagerView {
3838
: _elements.filter { !$0.name.hasPrefix(".") }
3939
}
4040

41+
var storage: StorageSpace? {
42+
device.storageInfo?.external
43+
}
44+
4145
var body: some View {
4246
VStack {
4347
if let error = error {
@@ -47,7 +51,7 @@ extension FileManagerView {
4751
} else {
4852
List {
4953
if path.isRoot {
50-
SDCardInfo(device.storageInfo?.external)
54+
SDCardInfo(storage: storage)
5155
} else {
5256
NavigationPathView(path: path)
5357
}

0 commit comments

Comments
 (0)