uikit storage settingscell

This commit is contained in:
Nihaal Sharma committed 2026-12-02 15:25:23 +00:00
1 parent ef804d5332
commit 628de4c583
7 files changed
+162 -90

No files matched your search

+12 -8
View File
@@ -35,6 +35,10 @@
A921C2E02ED067BB00E57B1A /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A921C2DE2ED067BB00E57B1A /* WelcomeView.swift */; }; A921C2E02ED067BB00E57B1A /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A921C2DE2ED067BB00E57B1A /* WelcomeView.swift */; };
A924C3732EA9127200F20781 /* Emoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A924C3712EA9127200F20781 /* Emoji.swift */; }; A924C3732EA9127200F20781 /* Emoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A924C3712EA9127200F20781 /* Emoji.swift */; };
A924C3782EA9225800F20781 /* Haptics in Frameworks */ = {isa = PBXBuildFile; productRef = A924C3772EA9225800F20781 /* Haptics */; }; A924C3782EA9225800F20781 /* Haptics in Frameworks */ = {isa = PBXBuildFile; productRef = A924C3772EA9225800F20781 /* Haptics */; };
A931FBCF30C0465C00AB3CC6 /* StorageSettingsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A931FBCE30C0465C00AB3CC6 /* StorageSettingsCell.swift */; };
A931FBD030C0465C00AB3CC6 /* StorageSettingsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A931FBCE30C0465C00AB3CC6 /* StorageSettingsCell.swift */; };
A931FBD230C04F3A00AB3CC6 /* StorageSettingsCellRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A931FBD130C04F3A00AB3CC6 /* StorageSettingsCellRepresentable.swift */; };
A931FBD430C04F3A00AB3CC6 /* StorageSettingsCellRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A931FBD130C04F3A00AB3CC6 /* StorageSettingsCellRepresentable.swift */; };
A935437B2EB2A3C800BB80A4 /* FilterCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */; }; A935437B2EB2A3C800BB80A4 /* FilterCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */; };
A949B1F32EA04E8200215164 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A949B1EF2EA04E8200215164 /* Assets.xcassets */; }; A949B1F32EA04E8200215164 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A949B1EF2EA04E8200215164 /* Assets.xcassets */; };
A949B1F42EA04E8200215164 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1F02EA04E8200215164 /* ContentView.swift */; }; A949B1F42EA04E8200215164 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1F02EA04E8200215164 /* ContentView.swift */; };
@@ -69,9 +73,6 @@
A97BFFC02F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */; }; A97BFFC02F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */; };
A97D3E7E2FA5235300BF3273 /* Haptics in Frameworks */ = {isa = PBXBuildFile; productRef = A97D3E7D2FA5235300BF3273 /* Haptics */; }; A97D3E7E2FA5235300BF3273 /* Haptics in Frameworks */ = {isa = PBXBuildFile; productRef = A97D3E7D2FA5235300BF3273 /* Haptics */; };
A97D3E802FA5235E00BF3273 /* Haptics in Frameworks */ = {isa = PBXBuildFile; productRef = A97D3E7F2FA5235E00BF3273 /* Haptics */; }; A97D3E802FA5235E00BF3273 /* Haptics in Frameworks */ = {isa = PBXBuildFile; productRef = A97D3E7F2FA5235E00BF3273 /* Haptics */; };
A9803AFF30B87CB2002687A4 /* StorageCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9803AFE30B87CB2002687A4 /* StorageCellView.swift */; };
A9803B0030B87CB2002687A4 /* StorageCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9803AFE30B87CB2002687A4 /* StorageCellView.swift */; };
A9803B0130B87CB2002687A4 /* StorageCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9803AFE30B87CB2002687A4 /* StorageCellView.swift */; };
A982A14E2FFD2F8000053E26 /* BrowseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A982A14D2FFD2F8000053E26 /* BrowseViewController.swift */; }; A982A14E2FFD2F8000053E26 /* BrowseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A982A14D2FFD2F8000053E26 /* BrowseViewController.swift */; };
A982A14F2FFD2F8000053E26 /* BrowseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A982A14D2FFD2F8000053E26 /* BrowseViewController.swift */; }; A982A14F2FFD2F8000053E26 /* BrowseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A982A14D2FFD2F8000053E26 /* BrowseViewController.swift */; };
A986A6AE2EB658DF00B6E0FA /* Messages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A969D6932EA3E86500399C05 /* Messages.framework */; }; A986A6AE2EB658DF00B6E0FA /* Messages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A969D6932EA3E86500399C05 /* Messages.framework */; };
@@ -231,6 +232,8 @@
A921C2DE2ED067BB00E57B1A /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; }; A921C2DE2ED067BB00E57B1A /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; };
A924C3712EA9127200F20781 /* Emoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Emoji.swift; sourceTree = "<group>"; }; A924C3712EA9127200F20781 /* Emoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Emoji.swift; sourceTree = "<group>"; };
A924C3742EA9134C00F20781 /* StickerSlack.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = StickerSlack.entitlements; sourceTree = "<group>"; }; A924C3742EA9134C00F20781 /* StickerSlack.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = StickerSlack.entitlements; sourceTree = "<group>"; };
A931FBCE30C0465C00AB3CC6 /* StorageSettingsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageSettingsCell.swift; sourceTree = "<group>"; };
A931FBD130C04F3A00AB3CC6 /* StorageSettingsCellRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageSettingsCellRepresentable.swift; sourceTree = "<group>"; };
A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterCategory.swift; sourceTree = "<group>"; }; A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterCategory.swift; sourceTree = "<group>"; };
A94693D62FEF0A4200E56AC5 /* TabbedContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabbedContentView.swift; sourceTree = "<group>"; }; A94693D62FEF0A4200E56AC5 /* TabbedContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabbedContentView.swift; sourceTree = "<group>"; };
A949B1DF2EA04C0B00215164 /* StickerSlack.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StickerSlack.app; sourceTree = BUILT_PRODUCTS_DIR; }; A949B1DF2EA04C0B00215164 /* StickerSlack.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StickerSlack.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -255,7 +258,6 @@
A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToPackMenuView.swift; sourceTree = "<group>"; }; A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToPackMenuView.swift; sourceTree = "<group>"; };
A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = "<group>"; }; A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = "<group>"; };
A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionViewCell.swift; sourceTree = "<group>"; }; A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionViewCell.swift; sourceTree = "<group>"; };
A9803AFE30B87CB2002687A4 /* StorageCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageCellView.swift; sourceTree = "<group>"; };
A982A14D2FFD2F8000053E26 /* BrowseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseViewController.swift; sourceTree = "<group>"; }; A982A14D2FFD2F8000053E26 /* BrowseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseViewController.swift; sourceTree = "<group>"; };
A986A6AD2EB658DF00B6E0FA /* StickerSlackiMessageApp.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = StickerSlackiMessageApp.appex; sourceTree = BUILT_PRODUCTS_DIR; }; A986A6AD2EB658DF00B6E0FA /* StickerSlackiMessageApp.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = StickerSlackiMessageApp.appex; sourceTree = BUILT_PRODUCTS_DIR; };
A986A6C62EB659E000B6E0FA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; A986A6C62EB659E000B6E0FA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -423,6 +425,7 @@
A94F3E632F9E384D00FA6995 /* TableView */, A94F3E632F9E384D00FA6995 /* TableView */,
A94F3E642F9E385300FA6995 /* CollectionView */, A94F3E642F9E385300FA6995 /* CollectionView */,
A982A14D2FFD2F8000053E26 /* BrowseViewController.swift */, A982A14D2FFD2F8000053E26 /* BrowseViewController.swift */,
A931FBCE30C0465C00AB3CC6 /* StorageSettingsCell.swift */,
); );
path = UIKit; path = UIKit;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -599,7 +602,7 @@
children = ( children = (
A9BDEADD2F82BC93002798DF /* NoStickersView.swift */, A9BDEADD2F82BC93002798DF /* NoStickersView.swift */,
A9C52F6A2F8988CD00078588 /* EmptyCollectionView.swift */, A9C52F6A2F8988CD00078588 /* EmptyCollectionView.swift */,
A9803AFE30B87CB2002687A4 /* StorageCellView.swift */, A931FBD130C04F3A00AB3CC6 /* StorageSettingsCellRepresentable.swift */,
); );
path = Misc; path = Misc;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -764,7 +767,6 @@
A9104C802EB4022500D160EA /* MSSticker.swift in Sources */, A9104C802EB4022500D160EA /* MSSticker.swift in Sources */,
A98FA65C2FF3B29700D50212 /* EmojiTableView.swift in Sources */, A98FA65C2FF3B29700D50212 /* EmojiTableView.swift in Sources */,
A9E8C79A2FF7256B009A38B5 /* EmojiHoarder.Packs.swift in Sources */, A9E8C79A2FF7256B009A38B5 /* EmojiHoarder.Packs.swift in Sources */,
A9803B0130B87CB2002687A4 /* StorageCellView.swift in Sources */,
A9E8C7A32FF7B815009A38B5 /* EmojiPackDetailViewController.swift in Sources */, A9E8C7A32FF7B815009A38B5 /* EmojiPackDetailViewController.swift in Sources */,
A97322A62FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */, A97322A62FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */,
A98C51C1301D2925006CB5A9 /* GifManager.swift in Sources */, A98C51C1301D2925006CB5A9 /* GifManager.swift in Sources */,
@@ -812,6 +814,7 @@
A9773C2F2EA54AF000F3B753 /* StickerPreview.swift in Sources */, A9773C2F2EA54AF000F3B753 /* StickerPreview.swift in Sources */,
A9DB1DCC303DBAF30007C177 /* CGFloat.swift in Sources */, A9DB1DCC303DBAF30007C177 /* CGFloat.swift in Sources */,
A917BACF2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift in Sources */, A917BACF2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift in Sources */,
A931FBD430C04F3A00AB3CC6 /* StorageSettingsCellRepresentable.swift in Sources */,
A98FA6612FF3BD5400D50212 /* EmojiCollectionView.swift in Sources */, A98FA6612FF3BD5400D50212 /* EmojiCollectionView.swift in Sources */,
A9034533301F42DB00EFFFDF /* UIColor.swift in Sources */, A9034533301F42DB00EFFFDF /* UIColor.swift in Sources */,
A9E8C78F2FF71D8C009A38B5 /* DownloadedViewController.swift in Sources */, A9E8C78F2FF71D8C009A38B5 /* DownloadedViewController.swift in Sources */,
@@ -824,6 +827,7 @@
A96D59973013D6670086948E /* MessagesPackListView.swift in Sources */, A96D59973013D6670086948E /* MessagesPackListView.swift in Sources */,
A97BFFBF2F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */, A97BFFBF2F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */,
A9C52F792F89BB0800078588 /* EmojiTableViewCell.swift in Sources */, A9C52F792F89BB0800078588 /* EmojiTableViewCell.swift in Sources */,
A931FBD030C0465C00AB3CC6 /* StorageSettingsCell.swift in Sources */,
A9C52F722F89A85F00078588 /* ShareSheet.swift in Sources */, A9C52F722F89A85F00078588 /* ShareSheet.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@@ -836,7 +840,6 @@
A98C51BC301D290D006CB5A9 /* GifView.swift in Sources */, A98C51BC301D290D006CB5A9 /* GifView.swift in Sources */,
A97322A12FA7B9C8004B657D /* JumboMoji.swift in Sources */, A97322A12FA7B9C8004B657D /* JumboMoji.swift in Sources */,
A986A6C32EB6598100B6E0FA /* FilterCategory.swift in Sources */, A986A6C32EB6598100B6E0FA /* FilterCategory.swift in Sources */,
A9803B0030B87CB2002687A4 /* StorageCellView.swift in Sources */,
A9CD6C3A2EDDE6B500B7F421 /* EmojiPack.swift in Sources */, A9CD6C3A2EDDE6B500B7F421 /* EmojiPack.swift in Sources */,
A9EB724B2EB94A5700658CEB /* Trie.swift in Sources */, A9EB724B2EB94A5700658CEB /* Trie.swift in Sources */,
A9BDEAE02F82BCB4002798DF /* NoStickersView.swift in Sources */, A9BDEAE02F82BCB4002798DF /* NoStickersView.swift in Sources */,
@@ -869,7 +872,6 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
A91649983080BA69008D1B9D /* StickerSlackApp.swift in Sources */, A91649983080BA69008D1B9D /* StickerSlackApp.swift in Sources */,
A9803AFF30B87CB2002687A4 /* StorageCellView.swift in Sources */,
A9DB1DCB303DBAF30007C177 /* CGFloat.swift in Sources */, A9DB1DCB303DBAF30007C177 /* CGFloat.swift in Sources */,
A99C4B8E2FF2E8D30070CBA5 /* TabbedContentView.swift in Sources */, A99C4B8E2FF2E8D30070CBA5 /* TabbedContentView.swift in Sources */,
A9034536301FC41600EFFFDF /* EmojiPackImporterViewController.swift in Sources */, A9034536301FC41600EFFFDF /* EmojiPackImporterViewController.swift in Sources */,
@@ -890,7 +892,9 @@
A98C51BF301D2925006CB5A9 /* GifManager.swift in Sources */, A98C51BF301D2925006CB5A9 /* GifManager.swift in Sources */,
A9B9A82F2EB2CCED004C9245 /* EmojiHoarder.swift in Sources */, A9B9A82F2EB2CCED004C9245 /* EmojiHoarder.swift in Sources */,
A9CD6C3B2EDDE6B500B7F421 /* EmojiPack.swift in Sources */, A9CD6C3B2EDDE6B500B7F421 /* EmojiPack.swift in Sources */,
A931FBD230C04F3A00AB3CC6 /* StorageSettingsCellRepresentable.swift in Sources */,
A9EB724A2EB948E000658CEB /* EmojiTableViewRepresentable.swift in Sources */, A9EB724A2EB948E000658CEB /* EmojiTableViewRepresentable.swift in Sources */,
A931FBCF30C0465C00AB3CC6 /* StorageSettingsCell.swift in Sources */,
A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */, A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */,
A9E8C7A22FF7B815009A38B5 /* EmojiPackDetailViewController.swift in Sources */, A9E8C7A22FF7B815009A38B5 /* EmojiPackDetailViewController.swift in Sources */,
A98BD15C2FF5242700ADC264 /* EmojiPackPreview.swift in Sources */, A98BD15C2FF5242700ADC264 /* EmojiPackPreview.swift in Sources */,
@@ -7,7 +7,7 @@
"location" : "https://github.com/neon443/Haptics", "location" : "https://github.com/neon443/Haptics",
"state" : { "state" : {
"branch" : "main", "branch" : "main",
"revision" : "30113208bf0b8c1ac01f5780d7c29eee525199d5" "revision" : "6ef89927b4f8dc574613663334d9a97fa90952f5"
} }
} }
], ],
@@ -9,7 +9,9 @@ import Foundation
import SwiftUI import SwiftUI
import Combine import Combine
import UniformTypeIdentifiers import UniformTypeIdentifiers
#if canImport(Haptics)
import Haptics import Haptics
#endif
class EmojiHoarder: BaseHoarder { class EmojiHoarder: BaseHoarder {
static let container: URL = library.appendingPathComponent("Emojis", conformingTo: .directory) static let container: URL = library.appendingPathComponent("Emojis", conformingTo: .directory)
@@ -131,7 +133,9 @@ class EmojiHoarder: BaseHoarder {
await buildDownloadedStickers() await buildDownloadedStickers()
Task { @MainActor in
self.usedStorage = UserDefaults.standard.double(forKey: "usedStorage") self.usedStorage = UserDefaults.standard.double(forKey: "usedStorage")
}
if usedStorage == 0 { if usedStorage == 0 {
await calculateStorageUsage() await calculateStorageUsage()
} }
@@ -1,80 +0,0 @@
//
// StorageCellView.swift
// StickerSlack
//
// Created by neon443 on 26/11/2026.
//
import Foundation
import SwiftUI
struct StorageCellView: View {
@ObservedObject var hoarder: EmojiHoarder
@State var totalStorage: Measurement<UnitInformationStorage> = .init(value: 1, unit: .exabytes)
@State var usedStorage: Measurement<UnitInformationStorage> = .init(value: 1, unit: .exabytes)
@State var stickerSlackStorage: Measurement<UnitInformationStorage> = .init(value: 1, unit: .exabytes)
var body: some View {
VStack {
HStack {
Text("Storage")
Spacer()
Text("\(Int(stickerSlackStorage.value.rounded(.up))) \(stickerSlackStorage.unit.symbol)")
.foregroundStyle(.gray)
.onAppear {
stickerSlackStorage = Measurement(value: hoarder.usedStorage, unit: UnitInformationStorage.bytes).converted(to: .megabytes)
}
Text("of")
Text("\(Int(totalStorage.value.rounded())) \(totalStorage.unit.symbol)")
.foregroundStyle(.gray)
.onAppear {
var storage: AnyObject?
try? (EmojiHoarder.localTrieDict as NSURL).getResourceValue(&storage, forKey: URLResourceKey.volumeTotalCapacityKey)
let measurement = Measurement(value: storage as? Double ?? 0, unit: UnitInformationStorage.bytes)
totalStorage = measurement.converted(to: UnitInformationStorage.gigabytes)
print(totalStorage)
var availStorage: AnyObject?
try? (EmojiHoarder.localTrieDict as NSURL).getResourceValue(&availStorage, forKey: URLResourceKey.volumeAvailableCapacityKey)
let unit = Measurement(value: availStorage as? Double ?? 0, unit: UnitInformationStorage.bytes)
usedStorage = unit.converted(to: UnitInformationStorage.gigabytes)
print(totalStorage - usedStorage)
}
Text("used")
}
.padding(.top, 8)
HStack(spacing: 1) {
Rectangle()
.foregroundStyle(.red)
Rectangle()
.foregroundStyle(.gray)
Rectangle()
.foregroundStyle(.black)
}
.background(.black)
.clipShape(RoundedRectangle(cornerRadius: 5))
.frame(maxHeight: 30)
HStack {
HStack {
Circle()
.foregroundStyle(.red)
.frame(maxHeight: 20)
Text("StickerSlack")
}
HStack {
Circle()
.foregroundStyle(.gray)
.frame(maxHeight: 16)
Text("Other Apps")
}
Spacer()
}
.padding(.vertical, 8)
}
}
}
#Preview {
StorageCellView(hoarder: EmojiHoarder())
}
@@ -0,0 +1,33 @@
//
// StorageSettingsCell.swift
// StickerSlack
//
// Created by neon443 on 02/12/2026.
//
import Foundation
import SwiftUI
struct StorageSettingsCellRepresentable: UIViewRepresentable {
var hoarder: EmojiHoarder
func makeUIView(context: Context) -> StorageSettingsCell {
let view = StorageSettingsCell(hoarder: hoarder)
return view
}
func updateUIView(_ uiView: StorageSettingsCell, context: Context) {
uiView.refreshUI()
}
@available(iOS 16, *)
func sizeThatFits(_ proposal: ProposedViewSize, uiView: StorageSettingsCell, context: Context) -> CGSize? {
let targetWidth = proposal.width ?? UIScreen.main.bounds.width
let size = uiView.systemLayoutSizeFitting(
CGSize(width: targetWidth, height: UIView.layoutFittingCompressedSize.height),
withHorizontalFittingPriority: .required,
verticalFittingPriority: .fittingSizeLevel
)
return CGSize(width: targetWidth, height: size.height)
}
}
+3 -1
View File
@@ -44,7 +44,8 @@ struct SettingsView: View {
} }
Section("Stats") { Section("Stats") {
StorageCellView(hoarder: hoarder) StorageSettingsCellRepresentable(hoarder: hoarder)
.frame(minHeight: 50)
Text("\(hoarder.emojis.count) total Emoji") Text("\(hoarder.emojis.count) total Emoji")
Text("\(hoarder.downloadedStickers.count) downloaded Emoji") Text("\(hoarder.downloadedStickers.count) downloaded Emoji")
if hoarder.downloadedStickers.count == hoarder.emojis.count { if hoarder.downloadedStickers.count == hoarder.emojis.count {
@@ -55,6 +56,7 @@ struct SettingsView: View {
} }
} }
// NavigationLink { // NavigationLink {
// List { // List {
// Picker(selection: $hoarder.letterStatsSorting.by) { // Picker(selection: $hoarder.letterStatsSorting.by) {
@@ -0,0 +1,109 @@
//
// StorageSettingsCell.swift
// StickerSlack
//
// Created by neon443 on 02/12/2026.
//
import Foundation
import UIKit
class StorageSettingsCell: UIStackView {
var hoarder: EmojiHoarder
var usedBar: UIView = .init()
var otherBar: UIView = .init()
var totalBar: UIView = .init()
var usedConstraint: NSLayoutConstraint!
var otherConstraint: NSLayoutConstraint!
var usageLabel: UILabel!
var labelStack: UIStackView!
var otherStorage: Measurement<UnitInformationStorage> = .init(value: 1, unit: .exabytes)
var totalStorage: Measurement<UnitInformationStorage> = .init(value: 1, unit: .exabytes)
init(hoarder: EmojiHoarder) {
self.hoarder = hoarder
self.labelStack = UIStackView()
self.usageLabel = UILabel()
super.init(frame: .zero)
setup()
refreshUI()
}
required init(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setup() {
self.axis = .vertical
self.addArrangedSubview(labelStack)
self.addArrangedSubview(totalBar)
labelStack.axis = .horizontal
let titleLabel = UILabel()
titleLabel.text = "Storage"
labelStack.addArrangedSubview(titleLabel)
usageLabel.textColor = .gray
labelStack.addArrangedSubview(usageLabel)
totalBar.addSubview(otherBar)
totalBar.addSubview(usedBar)
usedBar.backgroundColor = .systemRed
otherBar.backgroundColor = .systemGray
totalBar.backgroundColor = .black
totalBar.layer.cornerRadius = 3
totalBar.clipsToBounds = true
otherBar.translatesAutoresizingMaskIntoConstraints = false
usedBar.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
otherBar.leadingAnchor.constraint(equalTo: totalBar.leadingAnchor),
otherBar.centerYAnchor.constraint(equalTo: totalBar.centerYAnchor),
otherBar.heightAnchor.constraint(equalTo: totalBar.heightAnchor),
usedBar.leadingAnchor.constraint(equalTo: totalBar.leadingAnchor),
usedBar.centerYAnchor.constraint(equalTo: totalBar.centerYAnchor),
usedBar.heightAnchor.constraint(equalTo: totalBar.heightAnchor),
totalBar.heightAnchor.constraint(equalToConstant: 18)
])
usedConstraint = usedBar.widthAnchor.constraint(equalToConstant: 100)
usedConstraint.isActive = true
otherConstraint = otherBar.widthAnchor.constraint(equalToConstant: 200)
otherConstraint.isActive = true
}
func refreshUI() {
usedConstraint.isActive = false
otherConstraint.isActive = false
calculateStorages()
usedConstraint = usedBar.widthAnchor.constraint(equalTo: totalBar.widthAnchor, multiplier: hoarder.usedStorage/totalStorage.value)
otherConstraint = otherBar.widthAnchor.constraint(equalTo: totalBar.widthAnchor, multiplier: otherStorage.value/totalStorage.value)
usedConstraint.isActive = true
otherConstraint.isActive = true
let used = Measurement(value: hoarder.usedStorage, unit: UnitInformationStorage.bytes)
usageLabel.text = "\(Int(used.converted(to: .megabytes).value))"
}
func calculateStorages() {
var storage: AnyObject?
try? (EmojiHoarder.localTrieDict as NSURL).getResourceValue(&storage, forKey: URLResourceKey.volumeTotalCapacityKey)
totalStorage = Measurement(value: storage as? Double ?? 0, unit: UnitInformationStorage.bytes)
print(totalStorage)
var availStorage: AnyObject?
try? (EmojiHoarder.localTrieDict as NSURL).getResourceValue(&availStorage, forKey: URLResourceKey.volumeAvailableCapacityKey)
otherStorage = Measurement(value: totalStorage.value-(availStorage as? Double ?? 0), unit: UnitInformationStorage.bytes)
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.