mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
fix state issues for packs
fix crash
This commit is contained in:
4 files changed
+9
-37
No files matched your search
@@ -15,7 +15,6 @@ extension EmojiHoarder {
|
|||||||
self.emojiPacks = decoded.map {
|
self.emojiPacks = decoded.map {
|
||||||
EmojiPack(fromShareLink: $0) ?? .new()
|
EmojiPack(fromShareLink: $0) ?? .new()
|
||||||
}
|
}
|
||||||
sendChangeNotif(for: .emojiPacks)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveEmojiPacks() {
|
func saveEmojiPacks() {
|
||||||
@@ -39,7 +38,6 @@ extension EmojiHoarder {
|
|||||||
withAnimation {
|
withAnimation {
|
||||||
emojiPacks.append(packToAdd)
|
emojiPacks.append(packToAdd)
|
||||||
}
|
}
|
||||||
sendChangeNotif(for: .emojiPacks)
|
|
||||||
saveEmojiPacks()
|
saveEmojiPacks()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,8 +45,6 @@ extension EmojiHoarder {
|
|||||||
withAnimation {
|
withAnimation {
|
||||||
emojiPacks.removeAll { $0.id == packToRemove.id }
|
emojiPacks.removeAll { $0.id == packToRemove.id }
|
||||||
}
|
}
|
||||||
sendChangeNotif(for: .emojiPack(packToRemove.id))
|
|
||||||
sendChangeNotif(for: .emojiPacks)
|
|
||||||
saveEmojiPacks()
|
saveEmojiPacks()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +52,6 @@ extension EmojiHoarder {
|
|||||||
withAnimation {
|
withAnimation {
|
||||||
emojiPacks.remove(atOffsets: offset)
|
emojiPacks.remove(atOffsets: offset)
|
||||||
}
|
}
|
||||||
sendChangeNotif(for: .emojiPacks)
|
|
||||||
saveEmojiPacks()
|
saveEmojiPacks()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +60,6 @@ extension EmojiHoarder {
|
|||||||
withAnimation {
|
withAnimation {
|
||||||
self.emojiPacks[index] = updatedPack
|
self.emojiPacks[index] = updatedPack
|
||||||
}
|
}
|
||||||
sendChangeNotif(for: .emojiPacks)
|
|
||||||
saveEmojiPacks()
|
saveEmojiPacks()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +67,6 @@ extension EmojiHoarder {
|
|||||||
withAnimation {
|
withAnimation {
|
||||||
emojiPacks.move(fromOffsets: fromOffsets, toOffset: toOffset)
|
emojiPacks.move(fromOffsets: fromOffsets, toOffset: toOffset)
|
||||||
}
|
}
|
||||||
sendChangeNotif(for: .emojiPacks)
|
|
||||||
saveEmojiPacks()
|
saveEmojiPacks()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,8 +269,6 @@ class EmojiHoarder: BaseHoarder {
|
|||||||
enum NotifCategory {
|
enum NotifCategory {
|
||||||
case emojis
|
case emojis
|
||||||
case downloadedEmojis
|
case downloadedEmojis
|
||||||
case emojiPacks
|
|
||||||
case emojiPack(UUID)
|
|
||||||
|
|
||||||
var name: Notification.Name {
|
var name: Notification.Name {
|
||||||
switch self {
|
switch self {
|
||||||
@@ -278,10 +276,6 @@ class EmojiHoarder: BaseHoarder {
|
|||||||
Notification.Name("EmojiHoarder.notif.emojis")
|
Notification.Name("EmojiHoarder.notif.emojis")
|
||||||
case .downloadedEmojis:
|
case .downloadedEmojis:
|
||||||
Notification.Name("EmojiHoarder.notif.downloadedEmojis")
|
Notification.Name("EmojiHoarder.notif.downloadedEmojis")
|
||||||
case .emojiPacks:
|
|
||||||
Notification.Name("EmojiHoarder.notif.emojiPacks")
|
|
||||||
case .emojiPack(let emojiPackID):
|
|
||||||
Notification.Name("EmojiHoarder.notif.emojiPack.\(emojiPackID)")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,27 +105,12 @@ class EmojiPackDetailViewController: UIViewController {
|
|||||||
let x = UIBarButtonItem(title: "menu", image: UIImage(systemName: "ellipsis"), primaryAction: nil, menu: UIMenu(children: [shareButton2, downloadButton2]))
|
let x = UIBarButtonItem(title: "menu", image: UIImage(systemName: "ellipsis"), primaryAction: nil, menu: UIMenu(children: [shareButton2, downloadButton2]))
|
||||||
|
|
||||||
self.navigationItem.rightBarButtonItems = [collectionView.editButtonItem, x]
|
self.navigationItem.rightBarButtonItems = [collectionView.editButtonItem, x]
|
||||||
|
|
||||||
// NotificationCenter.default.addObserver(
|
|
||||||
// self,
|
|
||||||
// selector: #selector(packChanged),
|
|
||||||
// name: EmojiHoarder.NotifCategory.emojiPack(pack.id).name,
|
|
||||||
// object: nil
|
|
||||||
// )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func packChanged(_ notification: Notification) {
|
|
||||||
guard notification.name == EmojiHoarder.NotifCategory.emojiPack(pack.id).name else { return }
|
|
||||||
guard let updatedPack = hoarder.emojiPacks.first(where: { $0.id == pack.id }) else { return }
|
|
||||||
self.pack = updatedPack
|
|
||||||
self.navigationItem.title = pack.name
|
|
||||||
collectionView.refreshUI(with: pack.items)
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc func showSheet() {
|
@objc func showSheet() {
|
||||||
if let sheet = searchView.sheetPresentationController {
|
if let sheet = searchView.sheetPresentationController {
|
||||||
sheet.detents = [.medium(), .large()]
|
sheet.detents = [.medium(), .large()]
|
||||||
@@ -167,7 +152,10 @@ class EmojiPackDetailViewController: UIViewController {
|
|||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
NotificationCenter.default.post(name: EmojiHoarder.NotifCategory.emojiPack(pack.id).name, object: nil)
|
guard let updatedPack = hoarder.emojiPacks.first(where: { $0.id == pack.id }) else { return }
|
||||||
|
self.pack = updatedPack
|
||||||
|
self.navigationItem.title = pack.name
|
||||||
|
collectionView.refreshUI(with: pack.items)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillDisappear(_ animated: Bool) {
|
override func viewWillDisappear(_ animated: Bool) {
|
||||||
|
|||||||
@@ -29,13 +29,6 @@ class EmojiPackListView: UITableViewController {
|
|||||||
self.multiDeleteButton = UIBarButtonItem(image: UIImage(systemName: "trash"), style: .plain, target: self, action: #selector(multiDelete))
|
self.multiDeleteButton = UIBarButtonItem(image: UIImage(systemName: "trash"), style: .plain, target: self, action: #selector(multiDelete))
|
||||||
self.setToolbarItems([multiDeleteButton], animated: true)
|
self.setToolbarItems([multiDeleteButton], animated: true)
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
self,
|
|
||||||
selector: #selector(refresh),
|
|
||||||
name: EmojiHoarder.NotifCategory.emojiPacks.name,
|
|
||||||
object: nil
|
|
||||||
)
|
|
||||||
|
|
||||||
self.navigationItem.leftBarButtonItem = UIBarButtonItem(
|
self.navigationItem.leftBarButtonItem = UIBarButtonItem(
|
||||||
image: UIImage(systemName: "plus"),
|
image: UIImage(systemName: "plus"),
|
||||||
style: .plain,
|
style: .plain,
|
||||||
@@ -149,6 +142,10 @@ class EmojiPackListView: UITableViewController {
|
|||||||
return UISwipeActionsConfiguration(actions: [delete, share, dupButton])
|
return UISwipeActionsConfiguration(actions: [delete, share, dupButton])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
self.tableView.reloadData()
|
||||||
|
}
|
||||||
|
|
||||||
override func setEditing(_ editing: Bool, animated: Bool) {
|
override func setEditing(_ editing: Bool, animated: Bool) {
|
||||||
super.setEditing(editing, animated: animated)
|
super.setEditing(editing, animated: animated)
|
||||||
self.navigationController?.setToolbarHidden(!editing, animated: true)
|
self.navigationController?.setToolbarHidden(!editing, animated: true)
|
||||||
@@ -163,7 +160,7 @@ class EmojiPackListView: UITableViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc func refresh(_ notification: Notification) {
|
@objc func refresh(_ notification: Notification) {
|
||||||
self.tableView.reloadData()
|
// self.tableView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
func delete(_ indexPath: IndexPath) {
|
func delete(_ indexPath: IndexPath) {
|
||||||
|
|||||||