add key fix storage usage labels

This commit is contained in:
Nihaal Sharma committed 2026-12-03 09:20:16 +00:00
1 parent 628de4c583
commit 1b13e57b5e
3 files changed
+65 -4

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@ class EmojiHoarder: BaseHoarder {
@Published var showWelcome: Bool = false @Published var showWelcome: Bool = false
@Published var usedStorage: Double = 0 @Published var usedStorage: Double = 1
init(localOnly: Bool = false, skipIndex: Bool = false) { init(localOnly: Bool = false, skipIndex: Bool = false) {
super.init() super.init()
+1 -1
View File
@@ -45,7 +45,7 @@ struct SettingsView: View {
Section("Stats") { Section("Stats") {
StorageSettingsCellRepresentable(hoarder: hoarder) StorageSettingsCellRepresentable(hoarder: hoarder)
.frame(minHeight: 50) // .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 {
+63 -2
View File
@@ -19,11 +19,14 @@ class StorageSettingsCell: UIStackView {
var otherConstraint: NSLayoutConstraint! var otherConstraint: NSLayoutConstraint!
var usageLabel: UILabel! var usageLabel: UILabel!
var totalStorageLabel: UILabel!
var labelStack: UIStackView! var labelStack: UIStackView!
var otherStorage: Measurement<UnitInformationStorage> = .init(value: 1, unit: .exabytes) var otherStorage: Measurement<UnitInformationStorage> = .init(value: 1, unit: .exabytes)
var totalStorage: Measurement<UnitInformationStorage> = .init(value: 1, unit: .exabytes) var totalStorage: Measurement<UnitInformationStorage> = .init(value: 1, unit: .exabytes)
var keyStack: UIStackView!
init(hoarder: EmojiHoarder) { init(hoarder: EmojiHoarder) {
self.hoarder = hoarder self.hoarder = hoarder
@@ -42,6 +45,7 @@ class StorageSettingsCell: UIStackView {
func setup() { func setup() {
self.axis = .vertical self.axis = .vertical
self.spacing = 8
self.addArrangedSubview(labelStack) self.addArrangedSubview(labelStack)
self.addArrangedSubview(totalBar) self.addArrangedSubview(totalBar)
@@ -49,13 +53,35 @@ class StorageSettingsCell: UIStackView {
let titleLabel = UILabel() let titleLabel = UILabel()
titleLabel.text = "Storage" titleLabel.text = "Storage"
labelStack.addArrangedSubview(titleLabel) labelStack.addArrangedSubview(titleLabel)
let trailingStack = UIStackView()
labelStack.addArrangedSubview(trailingStack)
usageLabel.textColor = .gray usageLabel.textColor = .gray
labelStack.addArrangedSubview(usageLabel) trailingStack.addArrangedSubview(usageLabel)
let usedUnitLabel = UILabel()
usedUnitLabel.text = " MB of "
usedUnitLabel.textColor = .gray
trailingStack.addArrangedSubview(usedUnitLabel)
totalStorageLabel = UILabel()
totalStorageLabel.text = "69"
totalStorageLabel.textColor = .gray
trailingStack.addArrangedSubview(totalStorageLabel)
let totalUnitLabel = UILabel()
totalUnitLabel.text = " GB used"
totalUnitLabel.textColor = .gray
trailingStack.addArrangedSubview(totalUnitLabel)
totalBar.addSubview(otherBar) totalBar.addSubview(otherBar)
totalBar.addSubview(usedBar) totalBar.addSubview(usedBar)
usedBar.backgroundColor = .systemRed usedBar.backgroundColor = .systemRed
otherBar.backgroundColor = .systemGray otherBar.backgroundColor = .systemGray
totalBar.backgroundColor = .black totalBar.backgroundColor = .black
totalBar.layer.cornerRadius = 3 totalBar.layer.cornerRadius = 3
totalBar.clipsToBounds = true totalBar.clipsToBounds = true
@@ -78,6 +104,36 @@ class StorageSettingsCell: UIStackView {
usedConstraint.isActive = true usedConstraint.isActive = true
otherConstraint = otherBar.widthAnchor.constraint(equalToConstant: 200) otherConstraint = otherBar.widthAnchor.constraint(equalToConstant: 200)
otherConstraint.isActive = true otherConstraint.isActive = true
let redCircle = UIView()
redCircle.layer.cornerRadius = 8
redCircle.clipsToBounds = true
redCircle.backgroundColor = .systemRed
redCircle.translatesAutoresizingMaskIntoConstraints = false
redCircle.heightAnchor.constraint(equalToConstant: 16).isActive = true
redCircle.widthAnchor.constraint(equalToConstant: 16).isActive = true
let ssLabel = UILabel()
ssLabel.text = "StickerSlack Emojis"
ssLabel.font = .preferredFont(forTextStyle: .caption1)
let grayCircle = UIView()
grayCircle.layer.cornerRadius = 8
grayCircle.clipsToBounds = true
grayCircle.backgroundColor = .systemGray
grayCircle.translatesAutoresizingMaskIntoConstraints = false
grayCircle.heightAnchor.constraint(equalToConstant: 16).isActive = true
grayCircle.widthAnchor.constraint(equalToConstant: 16).isActive = true
let otherLabel = UILabel()
otherLabel.text = "Other Apps & Data"
otherLabel.font = .preferredFont(forTextStyle: .caption1)
keyStack = UIStackView(arrangedSubviews: [redCircle, ssLabel, grayCircle, otherLabel, UIView()])
keyStack.heightAnchor.constraint(equalToConstant: 16).isActive = true
keyStack.axis = .horizontal
keyStack.spacing = 8
self.addArrangedSubview(keyStack)
} }
func refreshUI() { func refreshUI() {
@@ -93,6 +149,12 @@ class StorageSettingsCell: UIStackView {
let used = Measurement(value: hoarder.usedStorage, unit: UnitInformationStorage.bytes) let used = Measurement(value: hoarder.usedStorage, unit: UnitInformationStorage.bytes)
usageLabel.text = "\(Int(used.converted(to: .megabytes).value))" usageLabel.text = "\(Int(used.converted(to: .megabytes).value))"
totalStorageLabel.text = "\(Int(totalStorage.converted(to: .gigabytes).value))"
}
override func didMoveToWindow() {
refreshUI()
} }
func calculateStorages() { func calculateStorages() {
@@ -104,6 +166,5 @@ class StorageSettingsCell: UIStackView {
var availStorage: AnyObject? var availStorage: AnyObject?
try? (EmojiHoarder.localTrieDict as NSURL).getResourceValue(&availStorage, forKey: URLResourceKey.volumeAvailableCapacityKey) try? (EmojiHoarder.localTrieDict as NSURL).getResourceValue(&availStorage, forKey: URLResourceKey.volumeAvailableCapacityKey)
otherStorage = Measurement(value: totalStorage.value-(availStorage as? Double ?? 0), unit: UnitInformationStorage.bytes) 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.