mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
save emojipacks on modify from stickerrow
extract addtoemojipackmenuview shit progress bar for downloads
This commit is contained in:
8 files changed
+95
-50
No files matched your search
@@ -48,6 +48,8 @@
|
||||
A957C1802ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
|
||||
A975F9192FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */; };
|
||||
A975F91A2FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */; };
|
||||
A975F9202FA52B3600A5C62E /* AddToPackMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */; };
|
||||
A975F9212FA52B3600A5C62E /* AddToPackMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */; };
|
||||
A9773C2F2EA54AF000F3B753 /* StickerPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */; };
|
||||
A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */; };
|
||||
A97BFFBD2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */; };
|
||||
@@ -212,6 +214,7 @@
|
||||
A957C17D2ECFAA1100EA3EE9 /* GifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifView.swift; sourceTree = "<group>"; };
|
||||
A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; };
|
||||
A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackGridView.swift; sourceTree = "<group>"; };
|
||||
A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToPackMenuView.swift; sourceTree = "<group>"; };
|
||||
A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = "<group>"; };
|
||||
A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyEmojiPackView.swift; sourceTree = "<group>"; };
|
||||
A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionViewCell.swift; sourceTree = "<group>"; };
|
||||
@@ -352,6 +355,7 @@
|
||||
A955B3EC2EC22C4A00E1732D /* DownloadedView.swift */,
|
||||
A957C1732ECCE2CE00EA3EE9 /* SettingsView.swift */,
|
||||
A955B3F42EC22EE900E1732D /* SearchView.swift */,
|
||||
A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */,
|
||||
);
|
||||
path = SwiftUI;
|
||||
sourceTree = "<group>";
|
||||
@@ -723,6 +727,7 @@
|
||||
A9EB724F2EB94A6B00658CEB /* TrieTestingView.swift in Sources */,
|
||||
A924C3732EA9127200F20781 /* Emoji.swift in Sources */,
|
||||
A9D15B8B2EB1142C00404792 /* EmojiPack.swift in Sources */,
|
||||
A975F9202FA52B3600A5C62E /* AddToPackMenuView.swift in Sources */,
|
||||
A9BE30FB2F5B03F400A57668 /* Sticker.swift in Sources */,
|
||||
A9BE30F62F5B011A00A57668 /* StickerProtocol.swift in Sources */,
|
||||
A921C2DF2ED067BB00E57B1A /* WelcomeView.swift in Sources */,
|
||||
@@ -790,6 +795,7 @@
|
||||
A9C52F702F89A22000078588 /* Wiggle.metal in Sources */,
|
||||
A955B3F12EC22E9700E1732D /* BrowseView.swift in Sources */,
|
||||
A9A7A4402F6835F800BB84C6 /* Trending.swift in Sources */,
|
||||
A975F9212FA52B3600A5C62E /* AddToPackMenuView.swift in Sources */,
|
||||
A9F7B3802F8951210071F198 /* EmojiPackImporterView.swift in Sources */,
|
||||
A9BE30F72F5B011A00A57668 /* StickerProtocol.swift in Sources */,
|
||||
A9C52F6B2F8988CE00078588 /* EmptyCollectionView.swift in Sources */,
|
||||
|
||||
@@ -14,7 +14,6 @@ struct EmojiPack: Identifiable, Codable, Equatable {
|
||||
var name: String
|
||||
var description: String
|
||||
var items: [String]
|
||||
var allDownloaded: Bool = false
|
||||
|
||||
init(id: UUID, name: String, description: String, items: [String]) {
|
||||
self.id = id
|
||||
@@ -134,15 +133,27 @@ struct EmojiPack: Identifiable, Codable, Equatable {
|
||||
url = components!.url!
|
||||
return url
|
||||
}
|
||||
|
||||
func allDownloaded(in hoarder: EmojiHoarder) -> Bool {
|
||||
guard !items.isEmpty else { return false }
|
||||
return Set(self.items).isSubset(of: hoarder.downloadedStickers)
|
||||
}
|
||||
|
||||
func downloadedFraction(in hoarder: EmojiHoarder) -> Double {
|
||||
guard !items.isEmpty else { return 0 }
|
||||
guard !allDownloaded(in: hoarder) else { return 1 }
|
||||
let common = hoarder.downloadedStickers.intersection(items)
|
||||
return Double(common.count)/Double(items.count)
|
||||
}
|
||||
}
|
||||
|
||||
extension EmojiPack {
|
||||
static func new() -> EmojiPack {
|
||||
static func new(withItems items: [String] = []) -> EmojiPack {
|
||||
EmojiPack(
|
||||
id: UUID(),
|
||||
name: "New Pack",
|
||||
description: "Created on \(Date().formatted())",
|
||||
items: []
|
||||
items: items
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -199,7 +199,6 @@ class EmojiHoarder: BaseHoarder {
|
||||
nonisolated func batchDownload(emojis emojisToDownload: [any StickerProtocol]) async {
|
||||
for emoji in emojisToDownload {
|
||||
await download(emoji: emoji, skipStoreIndex: true)
|
||||
|
||||
}
|
||||
|
||||
await buildDownloadedStickers()
|
||||
@@ -210,7 +209,6 @@ class EmojiHoarder: BaseHoarder {
|
||||
await super.download(emoji: emoji, skipStoreIndex: skipStoreIndex)
|
||||
|
||||
await MainActor.run {
|
||||
emojis.insert(.test, at: emojis.count-2)
|
||||
if !skipStoreIndex {
|
||||
let _ = withAnimation(.snappy) {
|
||||
self.downloadedStickers.insert(emoji.name)
|
||||
@@ -263,8 +261,8 @@ class EmojiHoarder: BaseHoarder {
|
||||
try? encoded.write(to: Self.packStore)
|
||||
}
|
||||
|
||||
func newEmojiPack() {
|
||||
addEmojiPack(.new())
|
||||
func newEmojiPack(withItems items: [String] = []) {
|
||||
addEmojiPack(.new(withItems: items))
|
||||
}
|
||||
|
||||
func addEmojiPack(_ packToAdd: EmojiPack) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// AddToPackMenuView.swift
|
||||
// StickerSlack
|
||||
//
|
||||
// Created by neon443 on 01/05/2026.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AddToPackMenuView: View {
|
||||
@ObservedObject var emojiHoarder: EmojiHoarder
|
||||
@State var sticker: Emoji
|
||||
|
||||
var body: some View {
|
||||
Menu {
|
||||
Button("Create new", systemImage: "plus") {
|
||||
emojiHoarder.newEmojiPack(withItems: [sticker.name])
|
||||
}
|
||||
Divider()
|
||||
if emojiHoarder.emojiPacks.isEmpty {
|
||||
Label("No Packs", systemImage: "questionmark.app.dashed")
|
||||
} else {
|
||||
Label("Add to Pack", systemImage: "square.stack.3d.up.fill")
|
||||
}
|
||||
ForEach($emojiHoarder.emojiPacks) { $pack in
|
||||
Button() {
|
||||
pack.addRemove(sticker.name)
|
||||
emojiHoarder.saveEmojiPacks()
|
||||
} label: {
|
||||
if pack.items.contains(sticker.name) {
|
||||
Image(systemName: "checkmark")
|
||||
}
|
||||
Text(pack.name)
|
||||
Text("\(pack.items.count) item"+pack.items.count.plural)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "plus")
|
||||
.resizable().scaledToFit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
AddToPackMenuView(emojiHoarder: EmojiHoarder(localOnly: true, skipIndex: true), sticker: .test)
|
||||
}
|
||||
@@ -20,10 +20,10 @@ struct EmojiPackDetailView: View {
|
||||
@State var useSwiftUIGrid: Bool = false
|
||||
|
||||
var allDownloaded: Bool {
|
||||
let date = Date.now
|
||||
let result = Set(pack.items).isSubset(of: hoarder.downloadedStickers)
|
||||
// print("hit \(Date.now.timeIntervalSince(date)) \(UUID())")
|
||||
return result
|
||||
pack.allDownloaded(in: hoarder)
|
||||
}
|
||||
var downloadedFraction: Double {
|
||||
pack.downloadedFraction(in: hoarder)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -88,6 +88,19 @@ struct EmojiPackDetailView: View {
|
||||
hoarder.saveEmojiPacks()
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarLeading) {
|
||||
Circle()
|
||||
.trim(from: 0, to: pack.downloadedFraction(in: hoarder))
|
||||
.stroke(
|
||||
.foreground,
|
||||
style: StrokeStyle(
|
||||
lineWidth: 5,
|
||||
lineCap: .round
|
||||
)
|
||||
)
|
||||
.rotationEffect(.degrees(-90))
|
||||
.padding(5)
|
||||
}
|
||||
ToolbarItem(placement: .topBarLeading) {
|
||||
Button(
|
||||
"",
|
||||
|
||||
@@ -107,41 +107,6 @@ struct StickerRow<T: Hoarder>: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct AddToPackMenuView: View {
|
||||
@ObservedObject var emojiHoarder: EmojiHoarder
|
||||
@State var sticker: Emoji
|
||||
|
||||
var body: some View {
|
||||
Menu {
|
||||
Button("Create new", systemImage: "plus") {
|
||||
var newPack = EmojiPack.new()
|
||||
newPack.add(sticker.name)
|
||||
emojiHoarder.emojiPacks.append(newPack)
|
||||
}
|
||||
Divider()
|
||||
if emojiHoarder.emojiPacks.isEmpty {
|
||||
Label("No Packs", systemImage: "questionmark.app.dashed")
|
||||
} else {
|
||||
Label("Add to Pack", systemImage: "square.stack.3d.up.fill")
|
||||
}
|
||||
ForEach($emojiHoarder.emojiPacks) { $pack in
|
||||
Button() {
|
||||
pack.addRemove(sticker.name)
|
||||
} label: {
|
||||
if pack.items.contains(sticker.name) {
|
||||
Image(systemName: "checkmark")
|
||||
}
|
||||
Text(pack.name)
|
||||
Text("\(pack.items.count) item"+pack.items.count.plural)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "plus")
|
||||
.resizable().scaledToFit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 17, *)
|
||||
#Preview {
|
||||
@Previewable var hoarder = EmojiHoarder()
|
||||
|
||||
@@ -77,6 +77,8 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
var edit: Bool? = false
|
||||
var onRemove: ((String) -> Void)?
|
||||
|
||||
var dataSource: UICollectionViewDiffableDataSource<Int, String>!
|
||||
|
||||
// [width: [label: height]]
|
||||
static var labelSizeDict: [CGFloat: [String: CGFloat]] = [:]
|
||||
|
||||
@@ -101,8 +103,13 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
self.style = style
|
||||
|
||||
layout.minimumInteritemSpacing = 8
|
||||
|
||||
super.init(collectionViewLayout: layout)
|
||||
|
||||
self.dataSource = UICollectionViewDiffableDataSource<Int, String>(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, itemIdentifier: String) -> UICollectionViewCell? in
|
||||
collectionView.cellForItem(at: indexPath)
|
||||
}
|
||||
collectionView.dataSource = dataSource
|
||||
|
||||
collectionView.contentInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,10 @@ struct EmojiTableView: UIViewRepresentable {
|
||||
context.coordinator.items = items
|
||||
// guard itemsBefore != itemsAfter else { return }
|
||||
Task.detached {
|
||||
if !(-10_000...10_000).contains(itemsBefore.count-itemsAfter.count) {
|
||||
if !(-10_000...10_000).contains(itemsBefore.count-itemsAfter.count) ||
|
||||
itemsAfter == itemsBefore {
|
||||
//diff of more than 10k
|
||||
await context.coordinator.instantApplySnapshot()
|
||||
} else if itemsAfter == itemsBefore {
|
||||
await context.coordinator.instantApplySnapshot()
|
||||
} else {
|
||||
await context.coordinator.applySnapshot(animated: true)
|
||||
}
|
||||
|
||||