mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
rename action and reorg
This commit is contained in:
2 files changed
+203
-170
No files matched your search
@@ -190,6 +190,7 @@ class EmojiPackDetailViewController: UIViewController {
|
|||||||
|
|
||||||
func refreshUI() {
|
func refreshUI() {
|
||||||
self.navigationItem.title = pack.name
|
self.navigationItem.title = pack.name
|
||||||
|
// self.navigationItem.documentProperties
|
||||||
checkForEmptyPack()
|
checkForEmptyPack()
|
||||||
updateDownloadButton()
|
updateDownloadButton()
|
||||||
setToolbar(editing: isEditing)
|
setToolbar(editing: isEditing)
|
||||||
|
|||||||
@@ -23,178 +23,31 @@ class EmojiPackListView: UITableViewController {
|
|||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
func showRenamer(for indexPath: IndexPath) {
|
||||||
self.tableView.allowsMultipleSelectionDuringEditing = true
|
guard let pack = packFor(indexPath: indexPath) else { return }
|
||||||
self.navigationItem.title = "Packs"
|
let alert = UIAlertController(title: "Rename Pack", message: nil, preferredStyle: .alert)
|
||||||
|
alert.addTextField { textField in
|
||||||
self.multiDeleteButton = UIBarButtonItem(
|
textField.text = pack.name
|
||||||
image: UIImage(systemName: "trash"),
|
textField.placeholder = pack.name
|
||||||
style: .plain,
|
// textField.borderStyle = .
|
||||||
target: self,
|
|
||||||
action: #selector(multiDelete)
|
|
||||||
)
|
|
||||||
self.multiDeleteButton.tintColor = .systemRed
|
|
||||||
self.multiDeleteLabel = UIBarButtonItem(title: "X", style: .plain, target: self, action: nil)
|
|
||||||
self.navigationItem.rightBarButtonItem = self.editButtonItem
|
|
||||||
|
|
||||||
self.navigationItem.leftBarButtonItem = UIBarButtonItem(
|
|
||||||
image: UIImage(systemName: "plus"),
|
|
||||||
style: .plain,
|
|
||||||
target: self,
|
|
||||||
action: #selector(addPack)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
||||||
return emojiHoarder.emojiPacks.count
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
||||||
let cell = UITableViewCell()
|
|
||||||
var content = cell.defaultContentConfiguration()
|
|
||||||
guard emojiHoarder.emojiPacks.indices.contains(indexPath.row) else { return cell }
|
|
||||||
let pack = emojiHoarder.emojiPacks[indexPath.row]
|
|
||||||
|
|
||||||
content.text = pack.name
|
|
||||||
content.secondaryText = "\(pack.items.count) emoji\(pack.items.count.plural)"
|
|
||||||
|
|
||||||
cell.contentConfiguration = content
|
|
||||||
|
|
||||||
return cell
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
||||||
guard emojiHoarder.emojiPacks.indices.contains(indexPath.row) else { return }
|
|
||||||
let pack = emojiHoarder.emojiPacks[indexPath.row]
|
|
||||||
|
|
||||||
if !self.isEditing {
|
|
||||||
let detailView = EmojiPackDetailViewController(with: emojiHoarder, andPack: pack)
|
|
||||||
self.navigationController?.pushViewController(detailView/*.collectionView*/, animated: true)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
updateMultiDeleteButton()
|
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { _ in
|
||||||
}
|
self.dismiss(animated: true)
|
||||||
|
}))
|
||||||
override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
|
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in
|
||||||
updateMultiDeleteButton()
|
defer { self.dismiss(animated: true) }
|
||||||
}
|
|
||||||
|
|
||||||
func updateMultiDeleteButton() {
|
|
||||||
if let selectedRows = self.tableView.indexPathsForSelectedRows,
|
|
||||||
!selectedRows.isEmpty {
|
|
||||||
self.multiDeleteButton.isEnabled = true
|
|
||||||
self.multiDeleteLabel.title = "\(selectedRows.count)"
|
|
||||||
} else {
|
|
||||||
self.multiDeleteButton.isEnabled = false
|
|
||||||
self.multiDeleteLabel.title = "0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
|
|
||||||
guard let pack = self.packFor(indexPath: indexPath) else { return nil }
|
|
||||||
|
|
||||||
if let selectedRows = self.tableView.indexPathsForSelectedRows,
|
|
||||||
selectedRows.contains(indexPath) {
|
|
||||||
let multiDelete = UIAction(
|
|
||||||
title: "Delete \(selectedRows.count) pack\(selectedRows.count.plural)",
|
|
||||||
image: UIImage(systemName: "trash"),
|
|
||||||
attributes: .destructive
|
|
||||||
) { action in
|
|
||||||
self.multiDelete()
|
|
||||||
}
|
|
||||||
return UIContextMenuConfiguration(identifier: nil) {
|
|
||||||
return nil
|
|
||||||
} actionProvider: { suggestedActions in
|
|
||||||
return UIMenu(children: [multiDelete])
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash"), attributes: .destructive) { action in
|
|
||||||
self.delete(indexPath)
|
|
||||||
}
|
|
||||||
let duplicate = UIAction(title: "Duplicate", image: UIImage(systemName: "plus.square.fill.on.square.fill")) { action in
|
|
||||||
self.dup(indexPath)
|
|
||||||
}
|
|
||||||
// UIMenu(options: .displayInline, children: [delete])
|
|
||||||
let share = UIAction(title: "Share...", image: UIImage(systemName: "square.and.arrow.up")) { action in
|
|
||||||
self.share(indexPath)
|
|
||||||
}
|
|
||||||
let isDownloaded = pack.allDownloaded(in: emojiHoarder)
|
|
||||||
let download = UIAction(
|
|
||||||
title: "\(isDownloaded ? "Remove " : "")Download",
|
|
||||||
image: UIImage(systemName: isDownloaded ? "trash" : "arrow.down")
|
|
||||||
) { action in
|
|
||||||
Task {
|
|
||||||
if isDownloaded {
|
|
||||||
await pack.deleteAll(hoarder: self.emojiHoarder)
|
|
||||||
} else {
|
|
||||||
await pack.downloadAll(hoarder: self.emojiHoarder)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let submenu = UIMenu(options: .displayInline, children: [duplicate, share])
|
|
||||||
let menu = UIMenu(children: [download, submenu, delete])
|
|
||||||
|
|
||||||
return UIContextMenuConfiguration(identifier: nil) {
|
var editedPack = pack
|
||||||
let grid = EmojiCollectionView(hoarder: self.emojiHoarder, items: pack.items, width: 50, style: .plain)
|
guard let textField = alert.textFields?.first,
|
||||||
let vc = UINavigationController(rootViewController: grid)
|
let text = textField.text else { return }
|
||||||
|
|
||||||
let title = UILabel()
|
editedPack.name = text
|
||||||
title.text = pack.name
|
self.emojiHoarder.updateEmojiPack(editedPack)
|
||||||
title.font = .boldSystemFont(ofSize: title.font.pointSize)
|
self.setEditing(false, animated: true)
|
||||||
let subtitle = UILabel()
|
self.refresh()
|
||||||
subtitle.text = "\(pack.items.count) emoji\(pack.items.count.plural)"
|
}))
|
||||||
subtitle.textColor = .gray
|
alert.preferredAction = alert.actions.last
|
||||||
|
self.present(alert, animated: true)
|
||||||
let stackView = UIStackView(arrangedSubviews: [title, subtitle])
|
|
||||||
stackView.axis = .vertical
|
|
||||||
stackView.alignment = .center
|
|
||||||
stackView.spacing -= 2
|
|
||||||
grid.navigationItem.titleView = stackView
|
|
||||||
return vc
|
|
||||||
} actionProvider: { suggestedActions in
|
|
||||||
return menu
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
|
||||||
guard emojiHoarder.emojiPacks.indices.contains(indexPath.row) else { return nil }
|
|
||||||
|
|
||||||
let delete = UIContextualAction(style: .destructive, title: "Delete") { contextualAction, view, closure in
|
|
||||||
self.delete(indexPath)
|
|
||||||
}
|
|
||||||
delete.image = UIImage(systemName: "trash")
|
|
||||||
|
|
||||||
let dupButton = UIContextualAction(style: .normal, title: "Duplicate") { contextualAction, view, closure in
|
|
||||||
self.dup(indexPath)
|
|
||||||
}
|
|
||||||
dupButton.image = UIImage(systemName: "plus.square.fill.on.square.fill")
|
|
||||||
|
|
||||||
let share = UIContextualAction(style: .normal, title: "Share") { contextualAction, view, closure in
|
|
||||||
self.share(indexPath)
|
|
||||||
}
|
|
||||||
share.image = UIImage(systemName: "square.and.arrow.up")
|
|
||||||
return UISwipeActionsConfiguration(actions: [delete, share, dupButton])
|
|
||||||
}
|
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
|
||||||
self.tableView.reloadData()
|
|
||||||
}
|
|
||||||
|
|
||||||
override func setEditing(_ editing: Bool, animated: Bool) {
|
|
||||||
super.setEditing(editing, animated: animated)
|
|
||||||
updateMultiDeleteButton()
|
|
||||||
var items: [UIBarButtonItem]
|
|
||||||
if editing {
|
|
||||||
if #available(iOS 26, *) {
|
|
||||||
items = [self.editButtonItem, .fixedSpace(), multiDeleteLabel, multiDeleteButton]
|
|
||||||
} else {
|
|
||||||
items = [self.editButtonItem, multiDeleteLabel, multiDeleteButton]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
items = [self.editButtonItem]
|
|
||||||
}
|
|
||||||
self.navigationItem.setRightBarButtonItems(items, animated: true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func addPack() {
|
@objc func addPack() {
|
||||||
@@ -252,4 +105,183 @@ class EmojiPackListView: UITableViewController {
|
|||||||
guard emojiHoarder.emojiPacks.indices.contains(indexPath.row) else { return nil }
|
guard emojiHoarder.emojiPacks.indices.contains(indexPath.row) else { return nil }
|
||||||
return emojiHoarder.emojiPacks[indexPath.row]
|
return emojiHoarder.emojiPacks[indexPath.row]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateMultiDeleteButton() {
|
||||||
|
if let selectedRows = self.tableView.indexPathsForSelectedRows,
|
||||||
|
!selectedRows.isEmpty {
|
||||||
|
self.multiDeleteButton.isEnabled = true
|
||||||
|
self.multiDeleteLabel.title = "\(selectedRows.count)"
|
||||||
|
} else {
|
||||||
|
self.multiDeleteButton.isEnabled = false
|
||||||
|
self.multiDeleteLabel.title = "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func refresh() {
|
||||||
|
self.tableView.reloadData()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
self.tableView.allowsMultipleSelectionDuringEditing = true
|
||||||
|
self.navigationItem.title = "Packs"
|
||||||
|
|
||||||
|
self.navigationItem.leftBarButtonItem = UIBarButtonItem(
|
||||||
|
image: UIImage(systemName: "plus"),
|
||||||
|
style: .plain,
|
||||||
|
target: self,
|
||||||
|
action: #selector(addPack)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.navigationItem.rightBarButtonItem = self.editButtonItem
|
||||||
|
self.multiDeleteLabel = UIBarButtonItem(title: "X", style: .plain, target: self, action: nil)
|
||||||
|
self.multiDeleteButton = UIBarButtonItem(
|
||||||
|
image: UIImage(systemName: "trash"),
|
||||||
|
style: .plain,
|
||||||
|
target: self,
|
||||||
|
action: #selector(multiDelete)
|
||||||
|
)
|
||||||
|
self.multiDeleteButton.tintColor = .systemRed
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func setEditing(_ editing: Bool, animated: Bool) {
|
||||||
|
super.setEditing(editing, animated: animated)
|
||||||
|
updateMultiDeleteButton()
|
||||||
|
var items: [UIBarButtonItem] = [self.editButtonItem]
|
||||||
|
if editing {
|
||||||
|
items.append(contentsOf: [multiDeleteLabel, multiDeleteButton])
|
||||||
|
}
|
||||||
|
self.navigationItem.setRightBarButtonItems(items, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
return emojiHoarder.emojiPacks.count
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
let cell = UITableViewCell()
|
||||||
|
var content = cell.defaultContentConfiguration()
|
||||||
|
|
||||||
|
guard let pack = packFor(indexPath: indexPath) else { return cell }
|
||||||
|
|
||||||
|
content.text = pack.name
|
||||||
|
content.secondaryText = "\(pack.items.count) emoji\(pack.items.count.plural)"
|
||||||
|
cell.contentConfiguration = content
|
||||||
|
return cell
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
|
guard let pack = packFor(indexPath: indexPath) else { return }
|
||||||
|
|
||||||
|
if !self.isEditing {
|
||||||
|
let detailView = EmojiPackDetailViewController(with: emojiHoarder, andPack: pack)
|
||||||
|
self.navigationController?.pushViewController(detailView, animated: true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
updateMultiDeleteButton()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
|
||||||
|
updateMultiDeleteButton()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
|
||||||
|
guard let pack = self.packFor(indexPath: indexPath) else { return nil }
|
||||||
|
|
||||||
|
if let selectedRows = self.tableView.indexPathsForSelectedRows,
|
||||||
|
selectedRows.contains(indexPath) {
|
||||||
|
let multiDelete = UIAction(
|
||||||
|
title: "Delete \(selectedRows.count) pack\(selectedRows.count.plural)",
|
||||||
|
image: UIImage(systemName: "trash"),
|
||||||
|
attributes: .destructive
|
||||||
|
) { action in
|
||||||
|
self.multiDelete()
|
||||||
|
}
|
||||||
|
return UIContextMenuConfiguration(identifier: nil) {
|
||||||
|
return nil
|
||||||
|
} actionProvider: { suggestedActions in
|
||||||
|
return UIMenu(children: [multiDelete])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash"), attributes: .destructive) { action in
|
||||||
|
self.delete(indexPath)
|
||||||
|
}
|
||||||
|
let rename = UIAction(title: "Rename", image: UIImage(systemName: "pencil")) { action in
|
||||||
|
self.showRenamer(for: indexPath)
|
||||||
|
}
|
||||||
|
let duplicate = UIAction(title: "Duplicate", image: UIImage(systemName: "plus.square.fill.on.square.fill")) { action in
|
||||||
|
self.dup(indexPath)
|
||||||
|
}
|
||||||
|
// UIMenu(options: .displayInline, children: [delete])
|
||||||
|
let share = UIAction(title: "Share...", image: UIImage(systemName: "square.and.arrow.up")) { action in
|
||||||
|
self.share(indexPath)
|
||||||
|
}
|
||||||
|
let isDownloaded = pack.allDownloaded(in: emojiHoarder)
|
||||||
|
let download = UIAction(
|
||||||
|
title: "\(isDownloaded ? "Remove " : "")Download",
|
||||||
|
image: UIImage(systemName: isDownloaded ? "trash" : "arrow.down")
|
||||||
|
) { action in
|
||||||
|
Task {
|
||||||
|
if isDownloaded {
|
||||||
|
await pack.deleteAll(hoarder: self.emojiHoarder)
|
||||||
|
} else {
|
||||||
|
await pack.downloadAll(hoarder: self.emojiHoarder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let submenu = UIMenu(options: .displayInline, children: [rename, duplicate, share])
|
||||||
|
let menu = UIMenu(children: [download, submenu, delete])
|
||||||
|
|
||||||
|
return UIContextMenuConfiguration(identifier: nil) {
|
||||||
|
let grid = EmojiCollectionView(hoarder: self.emojiHoarder, items: pack.items, width: 50, style: .plain)
|
||||||
|
let vc = UINavigationController(rootViewController: grid)
|
||||||
|
|
||||||
|
let title = UILabel()
|
||||||
|
title.text = pack.name
|
||||||
|
title.font = .boldSystemFont(ofSize: title.font.pointSize)
|
||||||
|
let subtitle = UILabel()
|
||||||
|
subtitle.text = "\(pack.items.count) emoji\(pack.items.count.plural)"
|
||||||
|
subtitle.textColor = .gray
|
||||||
|
|
||||||
|
let stackView = UIStackView(arrangedSubviews: [title, subtitle])
|
||||||
|
stackView.axis = .vertical
|
||||||
|
stackView.alignment = .center
|
||||||
|
stackView.spacing -= 2
|
||||||
|
grid.navigationItem.titleView = stackView
|
||||||
|
return vc
|
||||||
|
} actionProvider: { suggestedActions in
|
||||||
|
return menu
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||||
|
guard packFor(indexPath: indexPath) != nil else { return nil }
|
||||||
|
|
||||||
|
let delete = UIContextualAction(style: .destructive, title: "Delete") { _, _, _ in
|
||||||
|
self.delete(indexPath)
|
||||||
|
}
|
||||||
|
delete.image = UIImage(systemName: "trash")
|
||||||
|
|
||||||
|
let dupButton = UIContextualAction(style: .normal, title: "Duplicate") { _, _, _ in
|
||||||
|
self.dup(indexPath)
|
||||||
|
}
|
||||||
|
dupButton.image = UIImage(systemName: "plus.square.fill.on.square.fill")
|
||||||
|
|
||||||
|
let rename = UIContextualAction(style: .normal, title: "Rename") { _, _, _ in
|
||||||
|
self.showRenamer(for: indexPath)
|
||||||
|
}
|
||||||
|
rename.image = UIImage(systemName: "pencil")
|
||||||
|
|
||||||
|
let share = UIContextualAction(style: .normal, title: "Share") { _, _, _ in
|
||||||
|
self.share(indexPath)
|
||||||
|
}
|
||||||
|
share.image = UIImage(systemName: "square.and.arrow.up")
|
||||||
|
return UISwipeActionsConfiguration(actions: [delete, dupButton, rename, share])
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||