mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
add an all emojis thingy on messages, add a dlcount
This commit is contained in:
5 files changed
+74
-13
No files matched your search
@@ -17,6 +17,15 @@ struct EmojiPack: Identifiable, Codable, Equatable, Hashable, CustomStringConver
|
|||||||
var description: String {
|
var description: String {
|
||||||
return "\(items.count) emoji\(items.count.plural)"
|
return "\(items.count) emoji\(items.count.plural)"
|
||||||
}
|
}
|
||||||
|
var downloadedDescription: (Int) -> String {
|
||||||
|
{ dlCount in
|
||||||
|
if dlCount != items.count {
|
||||||
|
return "\(dlCount) / \(items.count) emoji\(items.count.plural)"
|
||||||
|
} else {
|
||||||
|
return "\(items.count) emoji\(items.count.plural)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init(id: UUID, name: String, items: [String]) {
|
init(id: UUID, name: String, items: [String]) {
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|||||||
@@ -136,6 +136,24 @@ class EmojiHoarder: BaseHoarder {
|
|||||||
sendChangeNotif(for: .downloadedEmojis)
|
sendChangeNotif(for: .downloadedEmojis)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildDownloadedStickersSync() {
|
||||||
|
var newSet: Set<String> = []
|
||||||
|
|
||||||
|
if let files = try? FileManager.default.contentsOfDirectory(atPath: EmojiHoarder.container.safePath) {
|
||||||
|
for file in files {
|
||||||
|
let name = String(file.split(separator: ".")[0])
|
||||||
|
newSet.insert(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newSet.remove("DS_Store")
|
||||||
|
let immutable = newSet
|
||||||
|
self.downloadedStickers = []
|
||||||
|
self.downloadedStickers = immutable
|
||||||
|
downloadedStickersArr = Array(downloadedStickers).sorted()
|
||||||
|
sendChangeNotif(for: .downloadedEmojis)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
private func loadLocalDB() -> [Emoji] {
|
private func loadLocalDB() -> [Emoji] {
|
||||||
do {
|
do {
|
||||||
let localEmojiDB = try Data(contentsOf: EmojiHoarder.localEmojiDB)
|
let localEmojiDB = try Data(contentsOf: EmojiHoarder.localEmojiDB)
|
||||||
|
|||||||
@@ -10,7 +10,16 @@ import Messages
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
class MessagesAppViewController: MSMessagesAppViewController {
|
class MessagesAppViewController: MSMessagesAppViewController {
|
||||||
var emojiHoarder: EmojiHoarder = EmojiHoarder(localOnly: true, skipIndex: false)
|
var emojiHoarder: EmojiHoarder = EmojiHoarder(localOnly: true, skipIndex: true)
|
||||||
|
|
||||||
|
init() {
|
||||||
|
emojiHoarder.buildDownloadedStickersSync()
|
||||||
|
super.init(nibName: nil, bundle: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import UIKit
|
|||||||
|
|
||||||
class MessagesPackListView: UITableViewController {
|
class MessagesPackListView: UITableViewController {
|
||||||
var emojiHoarder: EmojiHoarder!
|
var emojiHoarder: EmojiHoarder!
|
||||||
var onSelect: ((EmojiPack) -> Void)?
|
var onSelect: ((EmojiPack?) -> Void)?
|
||||||
|
|
||||||
init(hoarder: EmojiHoarder) {
|
init(hoarder: EmojiHoarder) {
|
||||||
self.emojiHoarder = hoarder
|
self.emojiHoarder = hoarder
|
||||||
@@ -26,22 +26,52 @@ class MessagesPackListView: UITableViewController {
|
|||||||
return emojiHoarder.emojiPacks[indexPath.row]
|
return emojiHoarder.emojiPacks[indexPath.row]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func reload() {
|
||||||
|
var indexPaths: [IndexPath] = []
|
||||||
|
for row in 0..<tableView(tableView, numberOfRowsInSection: 1) {
|
||||||
|
indexPaths.append(IndexPath(row: row, section: 1))
|
||||||
|
}
|
||||||
|
tableView.reconfigureRows(at: indexPaths)
|
||||||
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
|
tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: false, scrollPosition: .top)
|
||||||
|
reload()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
if section == 1 {
|
||||||
return emojiHoarder.emojiPacks.count
|
return emojiHoarder.emojiPacks.count
|
||||||
|
} else {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
let cell = UITableViewCell()
|
let cell: UITableViewCell = tableView.cellForRow(at: indexPath) ?? .init()
|
||||||
|
|
||||||
|
guard indexPath.section == 1 else {
|
||||||
|
var config = cell.defaultContentConfiguration()
|
||||||
|
cell.backgroundColor = .lightGray
|
||||||
|
config.text = "All Downloaded"
|
||||||
|
config.textProperties.font = UIFont.systemFont(ofSize: 14)
|
||||||
|
cell.contentConfiguration = config
|
||||||
|
return cell
|
||||||
|
}
|
||||||
var config = cell.defaultContentConfiguration()
|
var config = cell.defaultContentConfiguration()
|
||||||
|
|
||||||
if let pack = packFor(indexPath: indexPath) {
|
if let pack = packFor(indexPath: indexPath) {
|
||||||
config.text = pack.name
|
config.text = pack.name
|
||||||
config.textProperties.font = UIFont.systemFont(ofSize: 14)
|
config.textProperties.font = UIFont.systemFont(ofSize: 14)
|
||||||
config.secondaryText = pack.description
|
|
||||||
|
let dlCount = emojiHoarder.downloadedStickers.intersection(pack.items).count
|
||||||
|
config.secondaryText = pack.downloadedDescription(dlCount)
|
||||||
|
|
||||||
config.secondaryTextProperties.font = UIFont.systemFont(ofSize: 12)
|
config.secondaryTextProperties.font = UIFont.systemFont(ofSize: 12)
|
||||||
config.secondaryTextProperties.color = .systemGray
|
config.secondaryTextProperties.color = .systemGray
|
||||||
}
|
}
|
||||||
@@ -51,6 +81,10 @@ class MessagesPackListView: UITableViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
|
if indexPath.section == 1 {
|
||||||
onSelect?(emojiHoarder.emojiPacks[indexPath.row])
|
onSelect?(emojiHoarder.emojiPacks[indexPath.row])
|
||||||
|
} else {
|
||||||
|
onSelect?(nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,15 +20,6 @@ class StickerBrowserViewController: MSStickerBrowserViewController {
|
|||||||
self.pack = pack
|
self.pack = pack
|
||||||
|
|
||||||
super.init(stickerSize: .small)
|
super.init(stickerSize: .small)
|
||||||
|
|
||||||
reload()
|
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
self,
|
|
||||||
selector: #selector(reload),
|
|
||||||
name: EmojiHoarder.NotifCategory.downloadedEmojis.name,
|
|
||||||
object: nil
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
|
|||||||