mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
update trietestingview
made uikit list view have updated emojirow made reindexing 5x faster by making it not recompute container location
This commit is contained in:
5 files changed
+64
-38
No files matched your search
@@ -12,6 +12,7 @@ import UniformTypeIdentifiers
|
|||||||
import Haptics
|
import Haptics
|
||||||
|
|
||||||
class EmojiHoarder: Hoarder, ObservableObject {
|
class EmojiHoarder: Hoarder, ObservableObject {
|
||||||
|
static let container: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.neon443.StickerSlack")!.appendingPathComponent("Library", conformingTo: .directory)
|
||||||
nonisolated static let localEmojiDB: URL = EmojiHoarder.container.appendingPathComponent("_localEmojiDB.json", conformingTo: .fileURL)
|
nonisolated static let localEmojiDB: URL = EmojiHoarder.container.appendingPathComponent("_localEmojiDB.json", conformingTo: .fileURL)
|
||||||
nonisolated static let localTrie: URL = EmojiHoarder.container.appendingPathComponent("_localTrie.json", conformingTo: .fileURL)
|
nonisolated static let localTrie: URL = EmojiHoarder.container.appendingPathComponent("_localTrie.json", conformingTo: .fileURL)
|
||||||
nonisolated static let localTrieDict: URL = EmojiHoarder.container.appendingPathComponent("_localTrieDict.json", conformingTo: .fileURL)
|
nonisolated static let localTrieDict: URL = EmojiHoarder.container.appendingPathComponent("_localTrieDict.json", conformingTo: .fileURL)
|
||||||
|
|||||||
@@ -7,9 +7,12 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import UniformTypeIdentifiers
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
class GifHoarder: Hoarder, ObservableObject {
|
class GifHoarder: Hoarder, ObservableObject {
|
||||||
|
static let container: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.neon443.StickerSlack")!.appendingPathComponent("Library", conformingTo: .directory)
|
||||||
|
|
||||||
var endpoint: URL = URL(string: "api.giphy.com/v1/gifs/trending")!
|
var endpoint: URL = URL(string: "api.giphy.com/v1/gifs/trending")!
|
||||||
var endpointSearch: URL = URL(string: "api.giphy.com/v1/gifs/search")!
|
var endpointSearch: URL = URL(string: "api.giphy.com/v1/gifs/search")!
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ protocol Hoarder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension Hoarder {
|
extension Hoarder {
|
||||||
static var container: URL { FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.neon443.StickerSlack")!.appendingPathComponent("Library", conformingTo: .directory)
|
|
||||||
}
|
|
||||||
|
|
||||||
var encoder: JSONEncoder { JSONEncoder() }
|
var encoder: JSONEncoder { JSONEncoder() }
|
||||||
var decoder: JSONDecoder { JSONDecoder() }
|
var decoder: JSONDecoder { JSONDecoder() }
|
||||||
}
|
}
|
||||||
@@ -10,36 +10,77 @@ import SwiftUI
|
|||||||
struct TrieTestingView: View {
|
struct TrieTestingView: View {
|
||||||
@ObservedObject var hoarder: EmojiHoarder
|
@ObservedObject var hoarder: EmojiHoarder
|
||||||
|
|
||||||
@State var searchTerm: String = ""
|
|
||||||
@State var searchStatus: Bool? = nil
|
@State var searchStatus: Bool? = nil
|
||||||
|
|
||||||
@State var filterTerm: String = ""
|
@State var filterTerm: String = ""
|
||||||
@State var filterResult: [String] = []
|
@State var filterResult: [String] = []
|
||||||
|
|
||||||
@State var filterTerm2: String = ""
|
|
||||||
|
|
||||||
@State var uikit: Bool = false
|
@State var uikit: Bool = false
|
||||||
|
|
||||||
|
@State private var searchType: SearchType = .contains
|
||||||
|
private enum SearchType: String, CaseIterable {
|
||||||
|
case trie = "trie"
|
||||||
|
case contains = "contains"
|
||||||
|
case exact = "exact"
|
||||||
|
}
|
||||||
|
|
||||||
|
private func runSearch() {
|
||||||
|
filterResult = []
|
||||||
|
searchStatus = nil
|
||||||
|
guard !filterTerm.isEmpty else { return }
|
||||||
|
switch searchType {
|
||||||
|
case .trie:
|
||||||
|
withAnimation(.snappy) {
|
||||||
|
filterResult = hoarder.trie.search(prefix: filterTerm)
|
||||||
|
}
|
||||||
|
print("testing: trie search")
|
||||||
|
case .contains:
|
||||||
|
withAnimation(.snappy) {
|
||||||
|
filterResult = hoarder.emojis.filter({ $0.name.localizedCaseInsensitiveContains(filterTerm) }).map({ $0.name })
|
||||||
|
}
|
||||||
|
print("testing: contains search")
|
||||||
|
case .exact:
|
||||||
|
withAnimation(.snappy) {
|
||||||
|
searchStatus = hoarder.trie.search(for: filterTerm)
|
||||||
|
}
|
||||||
|
print("testing: exact search")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
Toggle("uikit!!", isOn: $uikit)
|
Toggle("uikit!!", isOn: $uikit)
|
||||||
.foregroundStyle(.blue)
|
.foregroundStyle(.blue)
|
||||||
|
|
||||||
|
HStack {
|
||||||
Button("reset", role: .destructive) {
|
Button("reset", role: .destructive) {
|
||||||
hoarder.resetAllIndexes()
|
hoarder.resetAllIndexes()
|
||||||
}
|
}
|
||||||
|
Spacer()
|
||||||
Button("add emojis!") {
|
Button("add emojis!") {
|
||||||
hoarder.buildTrie()
|
hoarder.buildTrie()
|
||||||
}
|
}
|
||||||
.buttonStyle(.borderedProminent)
|
.buttonStyle(.borderedProminent)
|
||||||
|
}
|
||||||
|
|
||||||
|
Picker("", selection: $searchType) {
|
||||||
|
ForEach(SearchType.allCases, id: \.self) { typee in
|
||||||
|
Text(typee.rawValue).tag(typee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(.segmented)
|
||||||
|
.onChange(of: searchType) { _ in
|
||||||
|
runSearch()
|
||||||
|
}
|
||||||
|
.onChange(of: filterTerm) { _ in
|
||||||
|
runSearch()
|
||||||
|
}
|
||||||
|
|
||||||
|
if searchType == .exact {
|
||||||
HStack {
|
HStack {
|
||||||
TextField("", text: $searchTerm)
|
TextField("", text: $filterTerm)
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.border(.orange)
|
.border(.orange)
|
||||||
.onChange(of: searchTerm) { _ in
|
|
||||||
searchStatus = hoarder.trie.search(for: searchTerm)
|
|
||||||
}
|
|
||||||
if let searchStatus {
|
if let searchStatus {
|
||||||
Circle()
|
Circle()
|
||||||
.frame(width: 20, height: 20)
|
.frame(width: 20, height: 20)
|
||||||
@@ -49,28 +90,30 @@ struct TrieTestingView: View {
|
|||||||
.frame(width: 20, height: 20)
|
.frame(width: 20, height: 20)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if searchType == .trie {
|
||||||
HStack {
|
HStack {
|
||||||
TextField("", text: $filterTerm)
|
TextField("", text: $filterTerm)
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.border(.orange)
|
.border(.orange)
|
||||||
.onChange(of: filterTerm) { _ in
|
|
||||||
withAnimation(.snappy) { filterResult = hoarder.trie.search(prefix: filterTerm) }
|
|
||||||
}
|
|
||||||
Text("\(filterResult.count)")
|
Text("\(filterResult.count)")
|
||||||
.modifier(numericTextCompat())
|
.modifier(numericTextCompat())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TextField("", text: $filterTerm2)
|
if searchType == .contains {
|
||||||
|
HStack {
|
||||||
|
TextField("", text: $filterTerm)
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.border(.orange)
|
.border(.orange)
|
||||||
.onChange(of: filterTerm2) { _ in
|
Text("\(filterResult.count)")
|
||||||
withAnimation(.snappy) { filterResult = hoarder.emojis.filter({ $0.name.localizedCaseInsensitiveContains(filterTerm2) }).map({ $0.name }) }
|
.modifier(numericTextCompat())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if uikit {
|
if uikit {
|
||||||
EmojiCollectionView(hoarder: hoarder, items: filterResult)
|
EmojiCollectionView(hoarder: hoarder, items: filterResult)
|
||||||
.id(filterResult)
|
|
||||||
} else {
|
} else {
|
||||||
List(filterResult, id: \.self) { item in
|
List(filterResult, id: \.self) { item in
|
||||||
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[item]!)
|
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[item]!)
|
||||||
@@ -79,6 +122,7 @@ struct TrieTestingView: View {
|
|||||||
|
|
||||||
Text("\(hoarder.trie.root.children.count)")
|
Text("\(hoarder.trie.root.children.count)")
|
||||||
}
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,27 +50,8 @@ struct EmojiCollectionView: UIViewRepresentable {
|
|||||||
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
||||||
|
|
||||||
cell.contentConfiguration = UIHostingConfiguration {
|
cell.contentConfiguration = UIHostingConfiguration {
|
||||||
HStack {
|
EmojiRow(hoarder: hoarder, emoji: emoji)
|
||||||
EmojiPreview(
|
.id(emoji)
|
||||||
hoarder: hoarder,
|
|
||||||
emoji: emoji
|
|
||||||
)
|
|
||||||
.frame(maxWidth: 100, maxHeight: 100)
|
|
||||||
Spacer()
|
|
||||||
if hoarder.downloadedEmojis.contains(emojiName) {
|
|
||||||
Button("", systemImage: "trash") {
|
|
||||||
fatalError()
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
} else {
|
|
||||||
Button("", systemImage: "arrow.down.circle") {
|
|
||||||
Task {
|
|
||||||
await self.hoarder.download(emoji: emoji)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|||||||