mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-03-11 13:26:17 +00:00
massively improved indexing performance:
cache the downloadedEmojis Set and Array added resize image function, yet to use the app icon and name are horizontally aligned in settings
This commit is contained in:
@@ -78,6 +78,11 @@ struct Emoji: Codable, Identifiable, Hashable {
|
||||
return
|
||||
}
|
||||
let (data, _) = try await URLSession.shared.data(from: remoteImageURL)
|
||||
|
||||
if let cgImage = UIImage(data: data)?.cgImage,
|
||||
cgImage.width < 300 || cgImage.height < 300 {
|
||||
|
||||
}
|
||||
try! await data.write(to: localImageURL)
|
||||
return
|
||||
}
|
||||
@@ -92,6 +97,25 @@ struct Emoji: Codable, Identifiable, Hashable {
|
||||
withAnimation { self.uiID = UUID() }
|
||||
}
|
||||
|
||||
func resize(image: UIImage, to targetSize: CGSize) -> UIImage {
|
||||
let oldSize = image.size
|
||||
let ratio: (x: CGFloat, y: CGFloat)
|
||||
ratio.x = targetSize.width / oldSize.width
|
||||
ratio.y = targetSize.height / oldSize.height
|
||||
|
||||
var newSize: CGSize
|
||||
if ratio.x > ratio.y {
|
||||
newSize = CGSize(width: oldSize.width * ratio.y, height: oldSize.height * ratio.y)
|
||||
} else {
|
||||
newSize = CGSize(width: oldSize.width * ratio.x, height: oldSize.height * ratio.x)
|
||||
}
|
||||
|
||||
let rect = CGRect(origin: .zero, size: newSize)
|
||||
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
|
||||
image.draw(in: rect)
|
||||
return UIGraphicsGetImageFromCurrentImageContext() ?? UIImage()
|
||||
}
|
||||
|
||||
static var test: Emoji = Emoji(
|
||||
name: "s?",
|
||||
url: URL(string: "https://neon443.github.io/images/fav.ico")!
|
||||
|
||||
@@ -131,11 +131,19 @@ class EmojiHoarder: ObservableObject {
|
||||
func buildDownloadedEmojis() {
|
||||
downloadedEmojis = []
|
||||
downloadedEmojisArr = []
|
||||
for emoji in emojis {
|
||||
guard emoji.isLocal else { continue }
|
||||
downloadedEmojis.insert(emoji.name)
|
||||
downloadedEmojisArr.append(emoji.name)
|
||||
downloadedEmojisArr = (try? JSONDecoder().decode([String].self, from: UserDefaults.standard.data(forKey: "downloadedEmojisArr") ?? Data())) ?? []
|
||||
downloadedEmojis = (try? JSONDecoder().decode(Set<String>.self, from: UserDefaults.standard.data(forKey: "downloadedEmojis") ?? Data())) ?? []
|
||||
|
||||
if downloadedEmojis.isEmpty || downloadedEmojisArr.isEmpty {
|
||||
for emoji in emojis {
|
||||
guard emoji.isLocal else { continue }
|
||||
downloadedEmojis.insert(emoji.name)
|
||||
downloadedEmojisArr.append(emoji.name)
|
||||
}
|
||||
}
|
||||
|
||||
UserDefaults.standard.set(try! JSONEncoder().encode(downloadedEmojis), forKey: "downloadedEmojis")
|
||||
UserDefaults.standard.set(try! JSONEncoder().encode(downloadedEmojisArr), forKey: "downloadedEmojisArr")
|
||||
}
|
||||
|
||||
nonisolated
|
||||
|
||||
Reference in New Issue
Block a user