diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 5f5dd71..82e370f 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -68,6 +68,8 @@ A986A6CE2EB659E000B6E0FA /* StickerBrowserDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = A986A6CB2EB659E000B6E0FA /* StickerBrowserDataSource.swift */; }; A986A6CF2EB659E000B6E0FA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A986A6C62EB659E000B6E0FA /* Assets.xcassets */; }; A986A6D12EB659E000B6E0FA /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A986A6C92EB659E000B6E0FA /* MainInterface.storyboard */; }; + A98BD15C2FF5242700ADC264 /* EmojiPackPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98BD15B2FF5242700ADC264 /* EmojiPackPreview.swift */; }; + A98BD15D2FF5242700ADC264 /* EmojiPackPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98BD15B2FF5242700ADC264 /* EmojiPackPreview.swift */; }; A98FA65B2FF3B29700D50212 /* EmojiTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98FA65A2FF3B29700D50212 /* EmojiTableView.swift */; }; A98FA65C2FF3B29700D50212 /* EmojiTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98FA65A2FF3B29700D50212 /* EmojiTableView.swift */; }; A98FA6612FF3BD5400D50212 /* EmojiCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98FA6602FF3BD5400D50212 /* EmojiCollectionView.swift */; }; @@ -234,6 +236,7 @@ A986A6C82EB659E000B6E0FA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; A986A6CA2EB659E000B6E0FA /* MessagesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesViewController.swift; sourceTree = ""; }; A986A6CB2EB659E000B6E0FA /* StickerBrowserDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerBrowserDataSource.swift; sourceTree = ""; }; + A98BD15B2FF5242700ADC264 /* EmojiPackPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackPreview.swift; sourceTree = ""; }; A98FA65A2FF3B29700D50212 /* EmojiTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiTableView.swift; sourceTree = ""; }; A98FA6602FF3BD5400D50212 /* EmojiCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionView.swift; sourceTree = ""; }; A99589AE2F5E0D83003A4A8C /* image.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = image.png; sourceTree = ""; }; @@ -348,6 +351,7 @@ children = ( A9CD6C342EDDE22800B7F421 /* EmojiPackDetailView.swift */, A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */, + A98BD15B2FF5242700ADC264 /* EmojiPackPreview.swift */, A9F7B37F2F8951210071F198 /* EmojiPackImporterView.swift */, A9C52F6E2F89A22000078588 /* Wiggle.metal */, A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */, @@ -727,6 +731,7 @@ A957C1742ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */, A9A7A44B2F6837A800BB84C6 /* GiphyUser.swift in Sources */, A9EB72392EB93FDB00658CEB /* EmojiTableViewRepresentable.swift in Sources */, + A98BD15D2FF5242700ADC264 /* EmojiPackPreview.swift in Sources */, A955B3EE2EC22C4A00E1732D /* DownloadedView.swift in Sources */, A949B1FB2EA0518800215164 /* SlackResponse.swift in Sources */, A957C17A2ECE542D00EA3EE9 /* GifManager.swift in Sources */, @@ -831,6 +836,7 @@ A9A7A4492F68361200BB84C6 /* Meta.swift in Sources */, A9EB724A2EB948E000658CEB /* EmojiTableViewRepresentable.swift in Sources */, A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */, + A98BD15C2FF5242700ADC264 /* EmojiPackPreview.swift in Sources */, A9BBC51A2EB8FA4500FFE82F /* ViewModifiers.swift in Sources */, A995D95B2F6EBBDD0043E5F5 /* TestStructures.swift in Sources */, A955B3ED2EC22C4A00E1732D /* DownloadedView.swift in Sources */, @@ -1039,7 +1045,7 @@ "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 15; + IPHONEOS_DEPLOYMENT_TARGET = 17; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13; @@ -1091,7 +1097,7 @@ "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 15; + IPHONEOS_DEPLOYMENT_TARGET = 17; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13; @@ -1128,7 +1134,7 @@ INFOPLIST_FILE = StickerSlackiMessageApp/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = StickerSlack; INFOPLIST_KEY_NSHumanReadableCopyright = ""; - IPHONEOS_DEPLOYMENT_TARGET = 16; + IPHONEOS_DEPLOYMENT_TARGET = 17; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -1160,7 +1166,7 @@ INFOPLIST_FILE = StickerSlackiMessageApp/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = StickerSlack; INFOPLIST_KEY_NSHumanReadableCopyright = ""; - IPHONEOS_DEPLOYMENT_TARGET = 16; + IPHONEOS_DEPLOYMENT_TARGET = 17; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/StickerSlack/Emoji/Categorisation/EmojiPack.swift b/StickerSlack/Emoji/Categorisation/EmojiPack.swift index a52c103..32ec15c 100644 --- a/StickerSlack/Emoji/Categorisation/EmojiPack.swift +++ b/StickerSlack/Emoji/Categorisation/EmojiPack.swift @@ -9,7 +9,7 @@ import Foundation import SwiftUI import UniformTypeIdentifiers -struct EmojiPack: Identifiable, Codable, Equatable { +struct EmojiPack: Identifiable, Codable, Equatable, Hashable { var id: UUID var name: String var description: String diff --git a/StickerSlack/Emoji/EmojiHoarder.swift b/StickerSlack/Emoji/EmojiHoarder.swift index 319c5e5..e1bbe89 100644 --- a/StickerSlack/Emoji/EmojiHoarder.swift +++ b/StickerSlack/Emoji/EmojiHoarder.swift @@ -11,24 +11,24 @@ import Combine import UniformTypeIdentifiers import Haptics -class EmojiHoarder: BaseHoarder { +@Observable class EmojiHoarder: BaseHoarder { static let container: URL = library.appendingPathComponent("Emojis", conformingTo: .directory) nonisolated static let localEmojiDB: URL = EmojiHoarder.library.appendingPathComponent("localEmojiDB.json", conformingTo: .fileURL) nonisolated static let localTrieDict: URL = EmojiHoarder.library.appendingPathComponent("localTrieDict.json", conformingTo: .fileURL) nonisolated static let packStore: URL = EmojiHoarder.library.appendingPathComponent("packStore.json", conformingTo: .fileURL) let endpoint: URL = URL(string: "https://cachet.dunkirk.sh/emojis")! - @Published var emojis: [Emoji] = [] - @Published var emojiPacks: [EmojiPack] = [] + var emojis: [Emoji] = [] + var emojiPacks: [EmojiPack] = [] - @Published var trie: Trie = Trie() + 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) + var letterStats: [EmojiHoarder.LetterStat] = [] + var letterStatsSorting: EmojiHoarder.LetterStatSorting = .init(by: .letter, ascending: true) - @Published var showWelcome: Bool = false + var showWelcome: Bool = false init(localOnly: Bool = false, skipIndex: Bool = false) { super.init() @@ -306,6 +306,20 @@ class EmojiHoarder: BaseHoarder { saveEmojiPacks() } + func removeEmojiPack(atOffsets offset: IndexSet) { + withAnimation { + emojiPacks.remove(atOffsets: offset) + } + saveEmojiPacks() + } + + func moveEmojiPacks(fromOffsets: IndexSet, toOffset: Int) { + withAnimation { + emojiPacks.move(fromOffsets: fromOffsets, toOffset: toOffset) + } + saveEmojiPacks() + } + func generateLetterStats() { var result: [EmojiHoarder.LetterStat] = [] for child in trie.root.children { diff --git a/StickerSlack/Gifs/GifHoarder.swift b/StickerSlack/Gifs/GifHoarder.swift index e202e9c..8aefceb 100644 --- a/StickerSlack/Gifs/GifHoarder.swift +++ b/StickerSlack/Gifs/GifHoarder.swift @@ -10,15 +10,15 @@ import SwiftUI import UniformTypeIdentifiers import Combine -class GifHoarder: BaseHoarder { +@Observable class GifHoarder: BaseHoarder { static let container: URL = library.appendingPathComponent("Gifs", conformingTo: .directory) static var apiKey: String = "a2mFsDTpX5blodY8ltkG6Q1xy5NgFSbc" var endpoint: URL = URL(string: "https://api.giphy.com/v1/gifs/trending")! var endpointSearch: URL = URL(string: "https://api.giphy.com/v1/gifs/search")! - @Published var searchTerm: String = "" - @Published var trendingGifs: [Gif] = [] + var searchTerm: String = "" + var trendingGifs: [Gif] = [] // @Published override var downloadedStickers: Set = [] init(localOnly: Bool = false) { diff --git a/StickerSlack/Hoarder.swift b/StickerSlack/Hoarder.swift index 12ab83d..779cfd9 100644 --- a/StickerSlack/Hoarder.swift +++ b/StickerSlack/Hoarder.swift @@ -21,11 +21,11 @@ protocol Hoarder: ObservableObject { nonisolated func delete(emoji: any StickerProtocol, skipStoreIndex: Bool) async } -class BaseHoarder: Hoarder { +@Observable class BaseHoarder: Hoarder { static let library: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.neon443.StickerSlack")!.appendingPathComponent("Library", conformingTo: .directory) - @Published var downloadedStickers: Set = [] + var downloadedStickers: Set = [] var encoder: JSONEncoder = JSONEncoder() var decoder: JSONDecoder = JSONDecoder() diff --git a/StickerSlack/StickerSlackApp.swift b/StickerSlack/StickerSlackApp.swift index 1a441b5..4bbe66d 100644 --- a/StickerSlack/StickerSlackApp.swift +++ b/StickerSlack/StickerSlackApp.swift @@ -7,38 +7,38 @@ import SwiftUI -//@main -//struct StickerSlackApp: App { -// @ObservedObject var emojiHoarder: EmojiHoarder = EmojiHoarder() -// @ObservedObject var gifhoarder: GifHoarder = GifHoarder() -// -// @State var importingEmojiPack: Bool = false -// @State var pack: EmojiPack = .new() -// -// var body: some Scene { -// WindowGroup { -// ContentView(emojiHoarder: emojiHoarder, gifhoarder: gifhoarder) -// .onOpenURL { url in -// if let imported = EmojiPack(fromShareLink: url) { -// importingEmojiPack = true -// pack = imported -// } -// } -// .sheet(isPresented: $importingEmojiPack) { -// EmojiPackImporterView(emojiHoarder: emojiHoarder, pack: $pack) -// } -// } -// } -//} - @main -class StickerSlackApp: UIResponder, UIApplicationDelegate { - var window: UIWindow? +struct StickerSlackApp: App { + @ObservedObject var emojiHoarder: EmojiHoarder = EmojiHoarder() + @ObservedObject var gifhoarder: GifHoarder = GifHoarder() - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool { - window = UIWindow(frame: UIScreen.main.bounds) - window?.rootViewController = TabbedContentView() - window?.makeKeyAndVisible() - return true + @State var importingEmojiPack: Bool = false + @State var pack: EmojiPack = .new() + + var body: some Scene { + WindowGroup { + ContentView(emojiHoarder: emojiHoarder, gifhoarder: gifhoarder) + .onOpenURL { url in + if let imported = EmojiPack(fromShareLink: url) { + importingEmojiPack = true + pack = imported + } + } + .sheet(isPresented: $importingEmojiPack) { + EmojiPackImporterView(emojiHoarder: emojiHoarder, pack: $pack) + } + } } } + +//@main +//class StickerSlackApp: UIResponder, UIApplicationDelegate { +// var window: UIWindow? +// +// func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool { +// window = UIWindow(frame: UIScreen.main.bounds) +// window?.rootViewController = TabbedContentView() +// window?.makeKeyAndVisible() +// return true +// } +//} diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift index 4dc9223..2bc708a 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift @@ -82,11 +82,13 @@ struct EmojiPackDetailView: View { ) } - Text("\(pack.items.count) Emoji\(pack.items.count.plural)") - .bold() - .multilineTextAlignment(.center) - .shadow(radius: 5) - .padding(.bottom) + if !pack.items.isEmpty { + Text("\(pack.items.count) Emoji\(pack.items.count.plural)") + .bold() + .multilineTextAlignment(.center) + .shadow(radius: 5) + .padding(.bottom) + } } .transition(.scale) .navigationTitle(edit ? "Editing" : "Pack Details") diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift index 41dcc4a..eab751d 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift @@ -10,7 +10,11 @@ import SwiftUI struct EmojiPackManager: View { @ObservedObject var hoarder: EmojiHoarder @State var useSwiftUIGrid: Bool = false - @State var showShareSheet: Bool = false + + @Environment(\.editMode) var editMode + @State var selection: Set = [] + + @State var showDeleteAlert: Bool = false var body: some View { NavigationView2 { @@ -23,49 +27,101 @@ struct EmojiPackManager: View { ) Spacer() } else { - List { - ForEach($hoarder.emojiPacks) { $pack in + List(selection: $selection) { + ForEach($hoarder.emojiPacks, id: \.self) { $pack in NavigationLink { EmojiPackDetailView(hoarder: hoarder, pack: $pack, useSwiftUIGrid: useSwiftUIGrid) } label: { Text(pack.name) } - .swipeActions(edge: .trailing) { - Button { - hoarder.removeEmojiPack(pack) - } label: { - Label("", systemImage: "trash") - } - .tint(.red) - if #available(iOS 16, *) { - ShareLink(item: pack.shareLink()) - } else { - Button { - showShareSheet.toggle() - } label: { - Label("", systemImage: "square.and.arrow.up") - } - .sheet(isPresented: $showShareSheet) { - ShareSheet(activityItems: [pack.shareLink()]) - } - } + .contextMenu { + EmojiPackActionButtons(hoarder: hoarder, pack: pack, showLabelText: true) + } preview: { + EmojiPackPreview(hoarder: hoarder, pack: pack) } + .swipeActions(edge: .trailing) { + EmojiPackActionButtons(hoarder: hoarder, pack: pack, showLabelText: false) + } + } + .onMove { indexSet, offset in + hoarder.moveEmojiPacks(fromOffsets: indexSet, toOffset: offset) + } + .onDelete { indexSet in + hoarder.removeEmojiPack(atOffsets: indexSet) } } } } .navigationTitle("Emoji Packs") .navigationBarTitleDisplayMode(.inline) + .animation(nil, value: editMode?.wrappedValue) .toolbar { - ToolbarItem { - Button { + ToolbarItem(placement: .topBarTrailing) { + Button("", systemImage: "plus") { hoarder.newEmojiPack() - } label: { - Image(systemName: "plus") } .tint(.accentColor) .modifier(glassButtonIfAv()) } + ToolbarItem(placement: .topBarLeading) { + EditButton() + } + + if #available(iOS 19, *) { + ToolbarSpacer() + } + +// if editMode?.wrappedValue.isEditing ?? false { + ToolbarItem(placement: .topBarLeading) { + Button("", systemImage: "trash") { + showDeleteAlert.toggle() + } + .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") + } + } +// } + } + } + } + + struct EmojiPackActionButtons: View { + @ObservedObject var hoarder: EmojiHoarder + @State var pack: EmojiPack + @State var showLabelText: Bool = true + + @State private var showShareSheet: Bool = false + + var body: some View { + Button { + hoarder.removeEmojiPack(pack) + } label: { + Label(showLabelText ? "Delete" : "", systemImage: "trash") + .foregroundStyle(.red) + } + .tint(.red) + if #available(iOS 16, *) { + if showLabelText { + ShareLink(item: pack.shareLink()) + } else { + ShareLink(item: pack.shareLink()) + .labelStyle(.iconOnly) + } + } else { + Button { + showShareSheet.toggle() + } label: { + Label(showLabelText ? "Delete" : "", systemImage: "square.and.arrow.up") + } + .sheet(isPresented: $showShareSheet) { + ShareSheet(activityItems: [pack.shareLink()]) + } } } } diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackPreview.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackPreview.swift new file mode 100644 index 0000000..ad1b0af --- /dev/null +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackPreview.swift @@ -0,0 +1,64 @@ +// +// EmojiPackPreview.swift +// StickerSlack +// +// Created by neon443 on 01/07/2026. +// + +import SwiftUI + +struct EmojiPackPreview: View { + @ObservedObject var hoarder: EmojiHoarder + @State var pack: EmojiPack + + var allDownloaded: Bool { + pack.allDownloaded(in: hoarder) + } + var body: some View { + NavigationView2 { + VStack { + Text(pack.name.isEmpty ? "Name" : pack.name) + .bold() + .foregroundStyle(.primary) + .font(.title) + + Text(pack.description.isEmpty ? "Description" : pack.description) + .foregroundStyle(.primary) + + if pack.items.isEmpty { + EmptyCollectionView( + title: "No Emoji", + details: "Add emojis to this pack", + systemImage: "exclamationmark.triangle.fill" + ) + } + + EmojiCollectionViewRepresentable( + hoarder: hoarder, + items: pack.items, + width: 75, + style: .full, + onRemoveSUI: { pack.remove($0) } + ) + + if !pack.items.isEmpty { + Text("\(pack.items.count) Emoji\(pack.items.count.plural)") + .bold() + .multilineTextAlignment(.center) + .shadow(radius: 5) + .padding(.bottom) + } + } + .transition(.scale) + .navigationTitle("Pack Details") + .navigationBarTitleDisplayMode(.inline) + .onDisappear { + hoarder.saveEmojiPacks() + } + } + } +} + +#Preview { + EmojiPackPreview(hoarder: EmojiHoarder(), pack: .test) +}