mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
fixed some gifs not being loaded as downloaded
-added UIName to separate the gif's slug and title fixed downloading gifs into emoji container
This commit is contained in:
10 files changed
+42
-14
No files matched your search
@@ -14,6 +14,10 @@ import UniformTypeIdentifiers
|
||||
struct Emoji: StickerProtocol {
|
||||
var id: String
|
||||
var name: String
|
||||
var UIName: String {
|
||||
get { name }
|
||||
set { return }
|
||||
}
|
||||
var typeGlyph: String = "slack.logo"
|
||||
var remoteImageURL: URL
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ import UniformTypeIdentifiers
|
||||
struct Gif: StickerProtocol {
|
||||
var id: String
|
||||
var name: String
|
||||
var UIName: String
|
||||
var typeGlyph: String = "giphy.logo"
|
||||
var remoteImageURL: URL
|
||||
|
||||
var giphyImages: GiphyImages?
|
||||
|
||||
// enum CodingKeys: String, CodingKey {
|
||||
@@ -23,12 +23,14 @@ struct Gif: StickerProtocol {
|
||||
|
||||
init(
|
||||
name: String,
|
||||
UIName: String,
|
||||
url: URL,
|
||||
giphyImages: GiphyImages?,
|
||||
id: String = UUID().uuidString
|
||||
) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.UIName = UIName
|
||||
self.giphyImages = giphyImages
|
||||
self.remoteImageURL = url
|
||||
}
|
||||
|
||||
@@ -32,8 +32,9 @@ struct GifObject: Codable, Identifiable {
|
||||
|
||||
var toGif: Gif {
|
||||
return Gif(
|
||||
name: self.title,
|
||||
url: URL(string: self.images.fixed_width.url)!,
|
||||
name: self.slug,
|
||||
UIName: self.title,
|
||||
url: URL(string: self.images.original.url)!,
|
||||
giphyImages: images,
|
||||
id: self.id
|
||||
)
|
||||
|
||||
@@ -10,10 +10,18 @@ import Messages
|
||||
|
||||
extension StickerProtocol {
|
||||
var localImageURLString: String {
|
||||
let containerPath: String
|
||||
if type(of: self) == Emoji.self {
|
||||
containerPath = EmojiHoarder.container.path()
|
||||
} else if type(of: self) == Gif.self {
|
||||
containerPath = GifHoarder.container.path()
|
||||
} else {
|
||||
fatalError("sticker type unrecogniesd")
|
||||
}
|
||||
let urlString = remoteImageURL.absoluteString
|
||||
let split = urlString.split(separator: ".")
|
||||
let fileExtension = ".\(split.last ?? "png")"
|
||||
return EmojiHoarder.container.path()+name+"."+id+fileExtension
|
||||
let fileExtension = ".\(split.last!)"
|
||||
return containerPath+name+"."+id+fileExtension
|
||||
}
|
||||
|
||||
var localImageURL: URL {
|
||||
|
||||
@@ -11,6 +11,7 @@ import Messages
|
||||
protocol StickerProtocol: Codable, Identifiable, Hashable {
|
||||
var id: String { get set }
|
||||
var name: String { get set }
|
||||
var UIName: String { get set }
|
||||
|
||||
var typeGlyph: String { get }
|
||||
|
||||
|
||||
@@ -31,12 +31,24 @@ struct BrowseView: View {
|
||||
.ignoresSafeArea(.container, edges: .bottom)
|
||||
.id(emojiHoarder.emojis)
|
||||
case .giphyGifs:
|
||||
ScrollView {
|
||||
ForEach(gifHoarder.trendingGifs) { gif in
|
||||
StickerRow(hoarder: gifHoarder, sticker: gif)
|
||||
.listRowSeparator(.hidden)
|
||||
Button("download all") {
|
||||
Task {
|
||||
for gif in gifHoarder.trendingGifs {
|
||||
await gifHoarder.download(emoji: gif)
|
||||
}
|
||||
}
|
||||
}
|
||||
Button("del all") {
|
||||
for gif in gifHoarder.trendingGifs {
|
||||
gifHoarder.delete(emoji: gif)
|
||||
}
|
||||
}
|
||||
List {
|
||||
ForEach(gifHoarder.trendingGifs) { gif in
|
||||
StickerRow(hoarder: gifHoarder, sticker: gif)
|
||||
}
|
||||
}
|
||||
.listRowSeparator(.hidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +54,9 @@ struct DownloadedView: View {
|
||||
.aspectRatio(1, contentMode: .fit)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 15))
|
||||
.contextMenu {
|
||||
Text(emoji.name)
|
||||
Text(emoji.UIName)
|
||||
Button("Copy Name", systemImage: "doc.on.clipboard") {
|
||||
UIPasteboard.general.string = emoji.name
|
||||
UIPasteboard.general.string = emoji.UIName
|
||||
}
|
||||
Button("Copy Image", systemImage: "photo.fill.on.rectangle.fill") {
|
||||
UIPasteboard.general.image = emoji.image
|
||||
|
||||
@@ -61,7 +61,7 @@ struct EmojiPackDetailView: View {
|
||||
let emoji = hoarder.trie.dict[name] ?? .test
|
||||
VStack {
|
||||
StickerPreview(sticker: emoji)
|
||||
Text(emoji.name)
|
||||
Text(emoji.UIName)
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
Spacer()
|
||||
|
||||
@@ -19,7 +19,7 @@ struct StickerPreview: View {
|
||||
} else if type == Gif.self {
|
||||
return .giphyGifs
|
||||
} else {
|
||||
fatalError()
|
||||
fatalError("sticker type unrecognisedd")
|
||||
}
|
||||
}
|
||||
var body: some View {
|
||||
|
||||
@@ -24,7 +24,7 @@ struct StickerRow<T: Hoarder>: View {
|
||||
.transition(.scale)
|
||||
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text(sticker.name)
|
||||
Text(sticker.UIName)
|
||||
.font(.caption)
|
||||
.bold(isDownloaded)
|
||||
.foregroundColor(isDownloaded ? .green : .primary)
|
||||
|
||||