diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 9f4e1d5..d2dbe19 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -109,8 +109,8 @@ A9BE30FF2F5FA78E00A57668 /* Hoarder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9BE30FD2F5FA47100A57668 /* Hoarder.swift */; }; A9C172DC2EB8C9AC008A7885 /* Trie.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C172DB2EB8C9AC008A7885 /* Trie.swift */; }; A9C172DD2EB8C9AC008A7885 /* Trie.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C172DB2EB8C9AC008A7885 /* Trie.swift */; }; - A9CD6C352EDDE22800B7F421 /* EmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CD6C342EDDE22800B7F421 /* EmojiPackView.swift */; }; - A9CD6C362EDDE22800B7F421 /* EmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CD6C342EDDE22800B7F421 /* EmojiPackView.swift */; }; + A9CD6C352EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CD6C342EDDE22800B7F421 /* EmojiPackDetailView.swift */; }; + A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CD6C342EDDE22800B7F421 /* EmojiPackDetailView.swift */; }; A9CD6C382EDDE37500B7F421 /* EmojiPackManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */; }; A9CD6C392EDDE37500B7F421 /* EmojiPackManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */; }; A9CD6C3A2EDDE6B500B7F421 /* EmojiPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D15B892EB1142C00404792 /* EmojiPack.swift */; }; @@ -213,7 +213,7 @@ A9BE30F92F5B03F400A57668 /* Sticker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sticker.swift; sourceTree = ""; }; A9BE30FD2F5FA47100A57668 /* Hoarder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hoarder.swift; sourceTree = ""; }; A9C172DB2EB8C9AC008A7885 /* Trie.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Trie.swift; sourceTree = ""; }; - A9CD6C342EDDE22800B7F421 /* EmojiPackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackView.swift; sourceTree = ""; }; + A9CD6C342EDDE22800B7F421 /* EmojiPackDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackDetailView.swift; sourceTree = ""; }; 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 = ""; }; @@ -295,7 +295,7 @@ A91C098C2EBBD7AB00210C34 /* Emoji */ = { isa = PBXGroup; children = ( - A9CD6C342EDDE22800B7F421 /* EmojiPackView.swift */, + A9CD6C342EDDE22800B7F421 /* EmojiPackDetailView.swift */, ); path = Emoji; sourceTree = ""; @@ -638,7 +638,7 @@ A9BDEADE2F82BC93002798DF /* NoStickersView.swift in Sources */, A955B3F52EC22EE900E1732D /* SearchView.swift in Sources */, A935437B2EB2A3C800BB80A4 /* FilterCategory.swift in Sources */, - A9CD6C352EDDE22800B7F421 /* EmojiPackView.swift in Sources */, + A9CD6C352EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */, A9A7A44E2F68383900BB84C6 /* GiphyImages.swift in Sources */, A9C172DD2EB8C9AC008A7885 /* Trie.swift in Sources */, A955B3F22EC22E9700E1732D /* BrowseView.swift in Sources */, @@ -722,7 +722,7 @@ A9A7A4682F6AA17C00BB84C6 /* Int.swift in Sources */, A9C172DC2EB8C9AC008A7885 /* Trie.swift in Sources */, A957C1752ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */, - A9CD6C362EDDE22800B7F421 /* EmojiPackView.swift in Sources */, + A9CD6C362EDDE22800B7F421 /* EmojiPackDetailView.swift in Sources */, A9EB72472EB948C400658CEB /* StickerRow.swift in Sources */, A9CD6C392EDDE37500B7F421 /* EmojiPackManager.swift in Sources */, A955B3F62EC22EE900E1732D /* SearchView.swift in Sources */, diff --git a/StickerSlack/Emoji/Categorisation/EmojiPackManager.swift b/StickerSlack/Emoji/Categorisation/EmojiPackManager.swift index 8542cc3..be6edfc 100644 --- a/StickerSlack/Emoji/Categorisation/EmojiPackManager.swift +++ b/StickerSlack/Emoji/Categorisation/EmojiPackManager.swift @@ -12,8 +12,9 @@ struct EmojiPackManager: View { var body: some View { ForEach(hoarder.emojiPacks) { pack in - EmojiPackView(hoarder: hoarder, pack: pack) + EmojiPackDetailView(hoarder: hoarder, pack: pack) } + EmojiPackDetailView(hoarder: hoarder, pack: .test) } } diff --git a/StickerSlack/Emoji/EmojiHoarder.swift b/StickerSlack/Emoji/EmojiHoarder.swift index 7f1c4e0..e31f597 100644 --- a/StickerSlack/Emoji/EmojiHoarder.swift +++ b/StickerSlack/Emoji/EmojiHoarder.swift @@ -22,6 +22,7 @@ class EmojiHoarder: BaseHoarder { @Published var trie: Trie = Trie() // @Published var downloadedStickers: Set = [] + var downloadedStickersArr: [String] = [] @Published var letterStats: [EmojiHoarder.LetterStat] = [] @Published var letterStatsSorting: EmojiHoarder.LetterStatSorting = .init(by: .letter, ascending: true) @@ -155,6 +156,7 @@ class EmojiHoarder: BaseHoarder { override func buildDownloadedStickers(for stickerType: String = "Emojis") async { await super.buildDownloadedStickers(for: stickerType) + downloadedStickersArr = Array(downloadedStickers).sorted() } func storeDownloadedIndexes() { @@ -216,6 +218,7 @@ class EmojiHoarder: BaseHoarder { if !skipStoreIndex { let _ = withAnimation(.snappy) { self.downloadedStickers.insert(emoji.name) + self.downloadedStickersArr.append(emoji.name) } self.storeDownloadedIndexes() } @@ -228,6 +231,7 @@ class EmojiHoarder: BaseHoarder { if !skipStoreIndex { let _ = withAnimation(.snappy) { downloadedStickers.remove(emoji.name) + downloadedStickersArr.removeAll(where: { $0 == emoji.name }) } storeDownloadedIndexes() } diff --git a/StickerSlack/SwiftUI/ContentView.swift b/StickerSlack/SwiftUI/ContentView.swift index fc4e507..f98bf17 100644 --- a/StickerSlack/SwiftUI/ContentView.swift +++ b/StickerSlack/SwiftUI/ContentView.swift @@ -20,6 +20,10 @@ struct ContentView: View { BrowseView(emojiHoarder: emojiHoarder, gifHoarder: gifhoarder) } + Tab("Packs", systemImage: "square.stack.3d.up.fill") { + EmojiPackManager(hoarder: emojiHoarder) + } + Tab("Downloaded", systemImage: "arrow.down.circle.fill") { DownloadedView(emojiHoarder: emojiHoarder, gifHoarder: gifhoarder) } @@ -38,6 +42,10 @@ struct ContentView: View { .tabItem { Label("Browse", systemImage: "square.grid.2x2.fill") } + EmojiPackManager(hoarder: emojiHoarder) + .tabItem { + Label("Packs", systemImage: "square.stack.3d.up.fill") + } DownloadedView(emojiHoarder: emojiHoarder, gifHoarder: gifhoarder) .tabItem { Label("Downloaded", systemImage: "arrow.down.circle.fill") diff --git a/StickerSlack/SwiftUI/DownloadedView.swift b/StickerSlack/SwiftUI/DownloadedView.swift index f7e8e92..a7183db 100644 --- a/StickerSlack/SwiftUI/DownloadedView.swift +++ b/StickerSlack/SwiftUI/DownloadedView.swift @@ -35,13 +35,14 @@ struct DownloadedView: View { .pickerStyle(.segmented) if emojiHoarder.downloadedStickers.isEmpty && gifHoarder.downloadedStickers.isEmpty { NoStickersView() + .padding() } GeometryReader { geo in ScrollView { let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing))) let layout = Array(repeating: col, count: columns) LazyVGrid(columns: layout, spacing: spacing) { - ForEach(Array(emojiHoarder.downloadedStickers), id: \.self) { name in + ForEach(emojiHoarder.downloadedStickersArr, id: \.self) { name in if let emoji = emojiHoarder.trie.dict[name] { ZStack { Rectangle() diff --git a/StickerSlack/SwiftUI/Emoji/EmojiPackDetailView.swift b/StickerSlack/SwiftUI/Emoji/EmojiPackDetailView.swift new file mode 100644 index 0000000..b90a8cc --- /dev/null +++ b/StickerSlack/SwiftUI/Emoji/EmojiPackDetailView.swift @@ -0,0 +1,99 @@ +// +// EmojiPackView.swift +// StickerSlack +// +// Created by neon443 on 01/12/2025. +// + +import SwiftUI + +struct EmojiPackDetailView: View { + @ObservedObject var hoarder: EmojiHoarder + @State var pack: EmojiPack + @State var edit: Bool = true + + var minColWidth: CGFloat { 75 } + var spacing: CGFloat { 10 } + var col: GridItem { + GridItem( + .flexible(minimum: minColWidth, maximum: 100), + spacing: spacing, + alignment: .center + ) + } + var body: some View { + NavigationStack { + GeometryReader { geo in + VStack { + if #unavailable(iOS 19) { + Button() { + + } label: { + Text(pack.name) + .bold() + .foregroundStyle(edit ? .blue : .primary) + .font(.title) + } + .disabled(!edit) + } + Button() { + + } label: { + Text(pack.description) + .foregroundStyle(edit ? .blue : .primary) + } + .disabled(!edit) + + let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing))) + let layout = Array(repeating: col, count: columns) + LazyVGrid(columns: layout, spacing: spacing) { + ForEach(pack.emojiNames, id: \.self) { name in + let emoji = hoarder.trie.dict[name] ?? .test + VStack { + StickerPreview(sticker: emoji) + Text(emoji.name) + .multilineTextAlignment(.center) + .font(.caption) + } + } + } + .padding(.vertical) + + Text("\(pack.emojiNames.count) Emoji\(pack.emojiNames.count.plural)") + .bold() + .multilineTextAlignment(.center) + } + .padding() + .navigationTitle(edit ? "Editing" : pack.name) + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem() { + Button( + "", + systemImage: edit ? "checkmark" : "pencil" + ) { + withAnimation { edit.toggle() } + } + .modifier(glassButtonIfAv(edit)) + .tint(edit ? .blue : .primary) + } + if #available(iOS 19, *) { + ToolbarSpacer() + } + ToolbarItem() { + ShareLink(item: URL(string: "stickerslack://")!) { + Image(systemName: "square.and.arrow.up") + } + } + } + } + } + } +} + +#Preview { + EmojiPackDetailView( + hoarder: EmojiHoarder(localOnly: true, skipIndex: true), + pack: .test + ) +} diff --git a/StickerSlack/SwiftUI/Emoji/EmojiPackView.swift b/StickerSlack/SwiftUI/Emoji/EmojiPackView.swift deleted file mode 100644 index dd6d839..0000000 --- a/StickerSlack/SwiftUI/Emoji/EmojiPackView.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// EmojiPackView.swift -// StickerSlack -// -// Created by neon443 on 01/12/2025. -// - -import SwiftUI - -struct EmojiPackView: View { - @ObservedObject var hoarder: EmojiHoarder - @State var pack: EmojiPack - - var body: some View { - Text(pack.name) - .bold() - Text(pack.description) - .foregroundStyle(.gray) - ForEach(pack.emojiNames, id: \.self) { name in - StickerPreview(sticker: hoarder.trie.dict[name] ?? .test) - } - } -} - -#Preview { - EmojiPackView( - hoarder: EmojiHoarder(localOnly: true, skipIndex: true), - pack: .test - ) -} diff --git a/StickerSlack/SwiftUI/ViewModifiers.swift b/StickerSlack/SwiftUI/ViewModifiers.swift index 29e7d05..4bf4864 100644 --- a/StickerSlack/SwiftUI/ViewModifiers.swift +++ b/StickerSlack/SwiftUI/ViewModifiers.swift @@ -27,3 +27,23 @@ struct tabViewActivationSearchActivation: ViewModifier { } } } + +struct glassButtonIfAv: ViewModifier { + var enabled: Bool + + init(_ enabled: Bool) { + self.enabled = enabled + } + + func body(content: Content) -> some View { + if enabled { + if #available(iOS 19, *) { + content.buttonStyle(.glassProminent) + } else { + content.buttonStyle(.borderedProminent) + } + } else { + content + } + } +}