From 78cca9a052fcaae8a7f8d1ab85dd70ec03777c06 Mon Sep 17 00:00:00 2001 From: Nihaal Sharma <69979447+neon443@users.noreply.github.com> Date: Fri, 3 Jul 2026 00:27:44 +0100 Subject: [PATCH] added notification posting for uikit ui reactiveness added dowloadedviewcontroller to recieve updates when data changes fixed crash due to unregistered reusable cell identifiers working delete button for multiselect cleaned up downloadedview extracted packs logic into an extension file extracted letterstats into an extension file --- StickerSlack.xcodeproj/project.pbxproj | 32 ++- .../EmojiHoarder.LetterStats.swift | 57 +++++ .../EmojiHoarder/EmojiHoarder.Packs.swift | 71 ++++++ .../EmojiHoarder.swift | 202 ++++++------------ StickerSlack/Hoarder.swift | 1 - StickerSlack/SwiftUI/DownloadedView.swift | 26 +-- .../SwiftUI/EmojiPacks/EmojiPackManager.swift | 16 +- .../CollectionView/EmojiCollectionView.swift | 6 +- .../EmojiCollectionViewRepresentable.swift | 3 - .../UIKit/DownloadedViewController.swift | 37 ++++ StickerSlack/UIKit/TabbedContentView.swift | 11 +- 11 files changed, 286 insertions(+), 176 deletions(-) create mode 100644 StickerSlack/EmojiHoarder/EmojiHoarder.LetterStats.swift create mode 100644 StickerSlack/EmojiHoarder/EmojiHoarder.Packs.swift rename StickerSlack/{Emoji => EmojiHoarder}/EmojiHoarder.swift (71%) create mode 100644 StickerSlack/UIKit/DownloadedViewController.swift diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 82e370f..541dda4 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -150,6 +150,14 @@ A9CD6C3B2EDDE6B500B7F421 /* EmojiPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D15B892EB1142C00404792 /* EmojiPack.swift */; }; A9D15B8B2EB1142C00404792 /* EmojiPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D15B892EB1142C00404792 /* EmojiPack.swift */; }; A9D6A8212F7014AE00F198FB /* TestStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = A995D95A2F6EBBDD0043E5F5 /* TestStructures.swift */; }; + A9E8C78F2FF71D8C009A38B5 /* DownloadedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C78E2FF71D8C009A38B5 /* DownloadedViewController.swift */; }; + A9E8C7902FF71D8C009A38B5 /* DownloadedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C78E2FF71D8C009A38B5 /* DownloadedViewController.swift */; }; + A9E8C79A2FF7256B009A38B5 /* EmojiHoarder.Packs.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7992FF7256B009A38B5 /* EmojiHoarder.Packs.swift */; }; + A9E8C79B2FF7256B009A38B5 /* EmojiHoarder.Packs.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7992FF7256B009A38B5 /* EmojiHoarder.Packs.swift */; }; + A9E8C79C2FF7256B009A38B5 /* EmojiHoarder.Packs.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C7992FF7256B009A38B5 /* EmojiHoarder.Packs.swift */; }; + A9E8C79E2FF726DA009A38B5 /* EmojiHoarder.LetterStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C79D2FF726D4009A38B5 /* EmojiHoarder.LetterStats.swift */; }; + A9E8C79F2FF726DA009A38B5 /* EmojiHoarder.LetterStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C79D2FF726D4009A38B5 /* EmojiHoarder.LetterStats.swift */; }; + A9E8C7A02FF726DA009A38B5 /* EmojiHoarder.LetterStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C79D2FF726D4009A38B5 /* EmojiHoarder.LetterStats.swift */; }; A9EB72392EB93FDB00658CEB /* EmojiTableViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */; }; A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72462EB948C400658CEB /* StickerRow.swift */; }; A9EB72492EB948C400658CEB /* StickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72462EB948C400658CEB /* StickerRow.swift */; }; @@ -269,6 +277,9 @@ A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackManager.swift; sourceTree = ""; }; A9D15B892EB1142C00404792 /* EmojiPack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPack.swift; sourceTree = ""; }; A9E2ECD72EB74CE00038B2D6 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = ""; }; + A9E8C78E2FF71D8C009A38B5 /* DownloadedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadedViewController.swift; sourceTree = ""; }; + A9E8C7992FF7256B009A38B5 /* EmojiHoarder.Packs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiHoarder.Packs.swift; sourceTree = ""; }; + A9E8C79D2FF726D4009A38B5 /* EmojiHoarder.LetterStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiHoarder.LetterStats.swift; sourceTree = ""; }; A9EB72382EB93FDB00658CEB /* EmojiTableViewRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiTableViewRepresentable.swift; sourceTree = ""; }; A9EB72462EB948C400658CEB /* StickerRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerRow.swift; sourceTree = ""; }; A9EB724C2EB94A6B00658CEB /* TrieTestingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrieTestingView.swift; sourceTree = ""; }; @@ -385,6 +396,7 @@ A94F3E642F9E385300FA6995 /* CollectionView */, A9C52F712F89A85F00078588 /* ShareSheet.swift */, A9FB3EE22FA7AB3A00030E2A /* UIKitGifView.swift */, + A9E8C78E2FF71D8C009A38B5 /* DownloadedViewController.swift */, ); path = UIKit; sourceTree = ""; @@ -422,6 +434,7 @@ A9BE30EB2F5AFE1E00A57668 /* StickerType.swift */, A9BE30F42F5B011400A57668 /* Stickers */, A9BE30ED2F5B003A00A57668 /* Gifs */, + A9E8C7942FF72550009A38B5 /* EmojiHoarder */, A949B1F92EA0517800215164 /* Emoji */, A91C09892EBBD75A00210C34 /* Trie */, A9104C812EB4022E00D160EA /* Extensions */, @@ -437,7 +450,6 @@ isa = PBXGroup; children = ( A924C3712EA9127200F20781 /* Emoji.swift */, - A949B1F72EA04F2300215164 /* EmojiHoarder.swift */, A91C098B2EBBD78700210C34 /* Categorisation */, A957C1792ECE542D00EA3EE9 /* GifManager.swift */, A957C17D2ECFAA1100EA3EE9 /* GifView.swift */, @@ -544,6 +556,16 @@ path = Stickers; sourceTree = ""; }; + A9E8C7942FF72550009A38B5 /* EmojiHoarder */ = { + isa = PBXGroup; + children = ( + A949B1F72EA04F2300215164 /* EmojiHoarder.swift */, + A9E8C7992FF7256B009A38B5 /* EmojiHoarder.Packs.swift */, + A9E8C79D2FF726D4009A38B5 /* EmojiHoarder.LetterStats.swift */, + ); + path = EmojiHoarder; + sourceTree = ""; + }; A9F423C32F87229100C0BE3B /* Shared */ = { isa = PBXGroup; children = ( @@ -718,12 +740,14 @@ A949B1F42EA04E8200215164 /* ContentView.swift in Sources */, A9CD6C382EDDE37500B7F421 /* EmojiPackManager.swift in Sources */, A9FB3EE42FA7AB3A00030E2A /* UIKitGifView.swift in Sources */, + A9E8C79E2FF726DA009A38B5 /* EmojiHoarder.LetterStats.swift in Sources */, A949B1F52EA04E8200215164 /* StickerSlackApp.swift in Sources */, A9A7A4452F68360900BB84C6 /* Pagination.swift in Sources */, A9104C802EB4022500D160EA /* MSSticker.swift in Sources */, A98FA65C2FF3B29700D50212 /* EmojiTableView.swift in Sources */, A9A7A43F2F6835F800BB84C6 /* Trending.swift in Sources */, A9A7A4422F68360200BB84C6 /* GifObject.swift in Sources */, + A9E8C79A2FF7256B009A38B5 /* EmojiHoarder.Packs.swift in Sources */, A97322A62FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */, A975F9192FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */, A957C1772ECD008E00EA3EE9 /* Bundle.swift in Sources */, @@ -764,6 +788,7 @@ A9BE30F22F5B004E00A57668 /* Gif.swift in Sources */, A917BACF2F9B787B008DB31E /* EmojiCollectionViewRepresentable.swift in Sources */, A98FA6612FF3BD5400D50212 /* EmojiCollectionView.swift in Sources */, + A9E8C78F2FF71D8C009A38B5 /* DownloadedViewController.swift in Sources */, A9BE30EC2F5AFE1E00A57668 /* StickerType.swift in Sources */, A9A7A4482F68361200BB84C6 /* Meta.swift in Sources */, A995D95C2F6EBBDD0043E5F5 /* TestStructures.swift in Sources */, @@ -787,6 +812,7 @@ A9EB724B2EB94A5700658CEB /* Trie.swift in Sources */, A9BDEAE02F82BCB4002798DF /* NoStickersView.swift in Sources */, A9BE30FA2F5B03F400A57668 /* Sticker.swift in Sources */, + A9E8C79B2FF7256B009A38B5 /* EmojiHoarder.Packs.swift in Sources */, A986A6CD2EB659E000B6E0FA /* MessagesViewController.swift in Sources */, A9A7A4572F69568700BB84C6 /* GifHoarder.swift in Sources */, A9BE30FF2F5FA78E00A57668 /* Hoarder.swift in Sources */, @@ -805,6 +831,7 @@ A9D6A8212F7014AE00F198FB /* TestStructures.swift in Sources */, A9BBC5192EB8FA4500FFE82F /* ViewModifiers.swift in Sources */, A986A6C42EB6598500B6E0FA /* SlackResponse.swift in Sources */, + A9E8C79F2FF726DA009A38B5 /* EmojiHoarder.LetterStats.swift in Sources */, A986A6C22EB6597600B6E0FA /* Emoji.swift in Sources */, A986A6C12EB6595F00B6E0FA /* EmojiHoarder.swift in Sources */, ); @@ -821,6 +848,7 @@ A9C52F762F89A93D00078588 /* URL.swift in Sources */, A9B9A8302EB2CD0B004C9245 /* Emoji.swift in Sources */, A9C52F702F89A22000078588 /* Wiggle.metal in Sources */, + A9E8C79C2FF7256B009A38B5 /* EmojiHoarder.Packs.swift in Sources */, A955B3F12EC22E9700E1732D /* BrowseView.swift in Sources */, A9A7A4402F6835F800BB84C6 /* Trending.swift in Sources */, A975F9212FA52B3600A5C62E /* AddToPackMenuView.swift in Sources */, @@ -839,6 +867,7 @@ A98BD15C2FF5242700ADC264 /* EmojiPackPreview.swift in Sources */, A9BBC51A2EB8FA4500FFE82F /* ViewModifiers.swift in Sources */, A995D95B2F6EBBDD0043E5F5 /* TestStructures.swift in Sources */, + A9E8C7A02FF726DA009A38B5 /* EmojiHoarder.LetterStats.swift in Sources */, A955B3ED2EC22C4A00E1732D /* DownloadedView.swift in Sources */, A9EC46AD2F6D9E4600E066E6 /* Hoarder.swift in Sources */, A9A7A4682F6AA17C00BB84C6 /* Int.swift in Sources */, @@ -851,6 +880,7 @@ A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */, A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */, A9CD6C392EDDE37500B7F421 /* EmojiPackManager.swift in Sources */, + A9E8C7902FF71D8C009A38B5 /* DownloadedViewController.swift in Sources */, A955B3F62EC22EE900E1732D /* SearchView.swift in Sources */, A97322A52FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */, A98FA6622FF3BD5400D50212 /* EmojiCollectionView.swift in Sources */, diff --git a/StickerSlack/EmojiHoarder/EmojiHoarder.LetterStats.swift b/StickerSlack/EmojiHoarder/EmojiHoarder.LetterStats.swift new file mode 100644 index 0000000..9a97a18 --- /dev/null +++ b/StickerSlack/EmojiHoarder/EmojiHoarder.LetterStats.swift @@ -0,0 +1,57 @@ +// +// EmojiHoarder.LetterStats.swift +// StickerSlack +// +// Created by neon443 on 03/07/2026. +// + +import Foundation + +extension EmojiHoarder { + func generateLetterStats() { + var result: [EmojiHoarder.LetterStat] = [] + for child in trie.root.children { + let count = trie.collectWords(startingWith: child.key, from: child.value).count + let stat = LetterStat(char: child.key, count: count) + result.append(stat) + } + self.letterStats = result + sortLetterStats(by: self.letterStatsSorting) + } + + func sortLetterStats(by: EmojiHoarder.LetterStatSorting) { + self.letterStatsSorting = by + let sortByLetter = letterStatsSorting.by == .letter + switch by.ascending { + case true: + letterStats.sort { + if sortByLetter { + $0.char > $1.char + } else { + $0.count > $1.count + } + } + case false: + letterStats.sort { + if sortByLetter { + $0.char > $1.char + } else { + $0.count < $1.count + } + } + } + } + + struct LetterStat: Hashable { + var char: String + var count: Int + } + enum SortLetterStatsBy: String, CaseIterable { + case letter = "Letter" + case count = "Count" + } + struct LetterStatSorting: Hashable, Equatable { + var by: EmojiHoarder.SortLetterStatsBy = .count + var ascending: Bool = true + } +} diff --git a/StickerSlack/EmojiHoarder/EmojiHoarder.Packs.swift b/StickerSlack/EmojiHoarder/EmojiHoarder.Packs.swift new file mode 100644 index 0000000..01123b4 --- /dev/null +++ b/StickerSlack/EmojiHoarder/EmojiHoarder.Packs.swift @@ -0,0 +1,71 @@ +// +// EmojiHoarder.Packs.swift +// StickerSlack +// +// Created by neon443 on 03/07/2026. +// + +import Foundation +import SwiftUI + +extension EmojiHoarder { + func loadEmojiPacks() { + guard let data = try? Data(contentsOf: Self.packStore), + let decoded = try? decoder.decode([URL].self, from: data) else { return } + self.emojiPacks = decoded.map { + EmojiPack(fromShareLink: $0) ?? .new() + } + sendChangeNotif(for: .emojiPacks) + } + + func saveEmojiPacks() { + var toStore: [URL] = [] + for pack in emojiPacks { + toStore.append(pack.shareLink()) + } + guard let encoded = try? encoder.encode(toStore) else { return } + try? encoded.write(to: Self.packStore) + } + + func newEmojiPack(withItems items: [String] = []) { + addEmojiPack(.new(withItems: items)) + sendChangeNotif(for: .emojiPacks) + } + + func addEmojiPack(_ packToAdd: EmojiPack) { + var packToAdd = packToAdd + if emojiPacks.contains(where: { $0.id == packToAdd.id }) { + packToAdd.id = UUID() + } + withAnimation { + emojiPacks.append(packToAdd) + } + sendChangeNotif(for: .emojiPacks) + saveEmojiPacks() + } + + func removeEmojiPack(_ packToRemove: EmojiPack) { + withAnimation { + emojiPacks.removeAll { $0.id == packToRemove.id } + } + sendChangeNotif(for: .emojiPack(packToRemove)) + sendChangeNotif(for: .emojiPacks) + saveEmojiPacks() + } + + func removeEmojiPack(atOffsets offset: IndexSet) { + withAnimation { + emojiPacks.remove(atOffsets: offset) + } + sendChangeNotif(for: .emojiPacks) + saveEmojiPacks() + } + + func moveEmojiPacks(fromOffsets: IndexSet, toOffset: Int) { + withAnimation { + emojiPacks.move(fromOffsets: fromOffsets, toOffset: toOffset) + } + sendChangeNotif(for: .emojiPacks) + saveEmojiPacks() + } +} diff --git a/StickerSlack/Emoji/EmojiHoarder.swift b/StickerSlack/EmojiHoarder/EmojiHoarder.swift similarity index 71% rename from StickerSlack/Emoji/EmojiHoarder.swift rename to StickerSlack/EmojiHoarder/EmojiHoarder.swift index e1bbe89..e0f056d 100644 --- a/StickerSlack/Emoji/EmojiHoarder.swift +++ b/StickerSlack/EmojiHoarder/EmojiHoarder.swift @@ -41,6 +41,7 @@ import Haptics loadEmojiPacks() self.emojis = loadLocalDB() + sendChangeNotif(for: .emojis) self.trie.dict = loadTrieDict() startLoading(localOnly: localOnly, skipIndex: skipIndex) @@ -64,48 +65,6 @@ import Haptics } } - func downloadAllStickers() async { - let start: Date = .now - -// let dict = trie.dict -// let allStickers = Set(emojis.map { $0.name }) -// let downloadedStickers = downloadedStickers -// let toDownload = allStickers.filter { !downloadedStickers.contains($0) } -// -// await withTaskGroup { group in -// for name in toDownload { -// group.addTask { -// await self.download(emoji: dict[name], skipStoreIndex: true) -// } -// } -// } -// await buildDownloadedStickers() - - let cores = ProcessInfo.processInfo.processorCount-1 - var ranges: [Range] = [] - for i in 0.. [Emoji] { @@ -192,6 +154,7 @@ import Haptics await fetched != self.emojis { await MainActor.run { withAnimation(.snappy) { self.emojis = fetched } + sendChangeNotif(for: .emojis) } } } @@ -208,6 +171,35 @@ import Haptics } } + //MARK: emojis + func downloadAllStickers() async { + let start: Date = .now + + let cores = ProcessInfo.processInfo.processorCount-1 + var ranges: [Range] = [] + for i in 0.. $1.char - } else { - $0.count > $1.count - } - } - case false: - letterStats.sort { - if sortByLetter { - $0.char > $1.char - } else { - $0.count < $1.count - } + enum NotifCategory { + case emojis + case downloadedEmojis + case emojiPacks + case emojiPack(EmojiPack) + + var name: Notification.Name { + switch self { + case .emojis: + Notification.Name("EmojiHoarder.notif.emojis") + case .downloadedEmojis: + Notification.Name("EmojiHoarder.notif.downloadedEmojis") + case .emojiPacks: + Notification.Name("EmojiHoarder.notif.emojiPacks") + case .emojiPack(let emojiPack): + Notification.Name("EmojiHoarder.notif.emojiPack.\(emojiPack.id)") } } } - - struct LetterStat: Hashable { - var char: String - var count: Int - } - enum SortLetterStatsBy: String, CaseIterable { - case letter = "Letter" - case count = "Count" - } - struct LetterStatSorting: Hashable, Equatable { - var by: EmojiHoarder.SortLetterStatsBy = .count - var ascending: Bool = true - } } diff --git a/StickerSlack/Hoarder.swift b/StickerSlack/Hoarder.swift index 779cfd9..8a5089d 100644 --- a/StickerSlack/Hoarder.swift +++ b/StickerSlack/Hoarder.swift @@ -22,7 +22,6 @@ protocol Hoarder: ObservableObject { } @Observable class BaseHoarder: Hoarder { - static let library: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.neon443.StickerSlack")!.appendingPathComponent("Library", conformingTo: .directory) var downloadedStickers: Set = [] diff --git a/StickerSlack/SwiftUI/DownloadedView.swift b/StickerSlack/SwiftUI/DownloadedView.swift index 470cfa4..0df2016 100644 --- a/StickerSlack/SwiftUI/DownloadedView.swift +++ b/StickerSlack/SwiftUI/DownloadedView.swift @@ -11,21 +11,21 @@ struct DownloadedView: View { @ObservedObject var emojiHoarder: EmojiHoarder @ObservedObject var gifHoarder: GifHoarder - @Environment(\.colorScheme) var colorScheme - var isDark: Bool { colorScheme == .dark } - @State var browseWhat: StickerType = .slackEmoji +// @Environment(\.colorScheme) var colorScheme +// var isDark: Bool { colorScheme == .dark } + @State private var browseWhat: StickerType = .slackEmoji - @State var showShare: Bool = false +// @State var showShare: Bool = false - var minColWidth: CGFloat { 75 } - var spacing: CGFloat { 5 } - var col: GridItem { - GridItem( - .flexible(minimum: minColWidth, maximum: 100), - spacing: spacing, - alignment: .center - ) - } +// var minColWidth: CGFloat { 75 } +// var spacing: CGFloat { 5 } +// var col: GridItem { +// GridItem( +// .flexible(minimum: minColWidth, maximum: 100), +// spacing: spacing, +// alignment: .center +// ) +// } var body: some View { Picker("", selection: $browseWhat) { diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift index 91d0895..27d348c 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift @@ -67,24 +67,20 @@ struct EmojiPackManager: View { EditButton() } +#if compiler(>=6.2) if #available(iOS 19, *) { ToolbarSpacer() } +#endif ToolbarItem(placement: .topBarLeading) { Button("", systemImage: "trash") { - showDeleteAlert.toggle() + for pack in selection { + hoarder.removeEmojiPack(pack) + } + selection = [] } .disabled(selection.isEmpty) -// .confirmationDialog("These items will be deleted immediately", isPresented: $showDeleteAlert) { -// Button("Delete \(selection.count) pack\(selection.count.plural)", role: .destructive) { -// for pack in selection { -// hoarder.removeEmojiPack(pack) -// } -// } -// } message: { -// Text("This action cannot be undone") -// } } } } diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift index 30f3d2c..2ac7ec3 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift @@ -40,6 +40,10 @@ final class EmojiCollectionView: UICollectionViewController, UICollectionViewDel super.init(collectionViewLayout: layout) + collectionView.register(PlainEmojiCollectionViewCell.self, forCellWithReuseIdentifier: "plain") + collectionView.register(EmojiCollectionViewCell.self, forCellWithReuseIdentifier: "full") + collectionView.delegate = self + self.dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, itemIdentifier: String) -> UICollectionViewCell? in self.collectionView(collectionView, cellForItemAt: indexPath) } @@ -74,7 +78,7 @@ final class EmojiCollectionView: UICollectionViewController, UICollectionViewDel self.refreshUI(edit: edit, with: items) } - func refreshUI(edit: Bool?, with items: [String]) { + func refreshUI(edit: Bool? = false, with items: [String]) { self.edit = edit if edit ?? false { self.startAnimating() diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewRepresentable.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewRepresentable.swift index 53a05f3..6cda4e5 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewRepresentable.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewRepresentable.swift @@ -21,9 +21,6 @@ struct EmojiCollectionViewRepresentable: UIViewRepresentable { func makeUIView(context: Context) -> UICollectionView { let collectionView = context.coordinator as UICollectionViewController - collectionView.collectionView.register(PlainEmojiCollectionViewCell.self, forCellWithReuseIdentifier: "plain") - collectionView.collectionView.register(EmojiCollectionViewCell.self, forCellWithReuseIdentifier: "full") - collectionView.collectionView.delegate = context.coordinator return collectionView.collectionView } diff --git a/StickerSlack/UIKit/DownloadedViewController.swift b/StickerSlack/UIKit/DownloadedViewController.swift new file mode 100644 index 0000000..1162a57 --- /dev/null +++ b/StickerSlack/UIKit/DownloadedViewController.swift @@ -0,0 +1,37 @@ +// +// DownloadedViewController.swift +// StickerSlack +// +// Created by neon443 on 02/07/2026. +// + +import Foundation +import UIKit + +class DownloadedViewController: UINavigationController, UINavigationControllerDelegate { + let downloadedView: EmojiCollectionView + var emojiHoarder: EmojiHoarder + + init(emojiHoarder: EmojiHoarder) { + self.emojiHoarder = emojiHoarder + downloadedView = EmojiCollectionView( + hoarder: emojiHoarder, + items: emojiHoarder.downloadedStickersArr, + width: 75, + style: .plainWithMenu + ) + downloadedView.navigationItem.title = "Saved" + super.init(rootViewController: downloadedView) + + NotificationCenter.default.addObserver(self, selector: #selector(downloadedEmojisChanged), name: EmojiHoarder.NotifCategory.downloadedEmojis.name, object: nil) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + @objc + func downloadedEmojisChanged(_ notification: Notification) { + downloadedView.refreshUI(with: emojiHoarder.downloadedStickersArr) + } +} diff --git a/StickerSlack/UIKit/TabbedContentView.swift b/StickerSlack/UIKit/TabbedContentView.swift index 0dadbe8..c36f8b0 100644 --- a/StickerSlack/UIKit/TabbedContentView.swift +++ b/StickerSlack/UIKit/TabbedContentView.swift @@ -41,15 +41,8 @@ final class TabbedContentView: UITabBarController { packs.tabBarItem = UITabBarItem(title: "Packs", image: UIImage(systemName: "square.stack.3d.up.fill"), tag: 1) - let downloadedView = EmojiCollectionView( - hoarder: emojiHoarder, - items: emojiHoarder.downloadedStickersArr, - width: 75, - style: .plainWithMenu - ) - let downloaded = UINavigationController(rootViewController: downloadedView) - downloadedView.navigationItem.title = "Downloaded" - downloaded.tabBarItem = UITabBarItem(title: "Downloaded", image: UIImage(systemName: "arrow.down.circle.fill"), tag: 2) + let downloaded = DownloadedViewController(emojiHoarder: emojiHoarder) + downloaded.tabBarItem = UITabBarItem(title: "Saved", image: UIImage(systemName: "arrow.down.circle.fill"), tag: 2) let settingsView = SettingsView(hoarder: emojiHoarder) let settings = UIHostingController(rootView: settingsView)