mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-03-11 05:19:13 +00:00
finished gif.swift i think
add placeholder for gifs browsing and a toggle minor ui improvement to emojirow update test emoji url reduce duplication of cgimage
This commit is contained in:
@@ -58,7 +58,7 @@ struct Emoji: StickerProtocol {
|
|||||||
var (data, _) = try await URLSession.shared.data(from: remoteImageURL)
|
var (data, _) = try await URLSession.shared.data(from: remoteImageURL)
|
||||||
|
|
||||||
if let uiImage = UIImage(data: data),
|
if let uiImage = UIImage(data: data),
|
||||||
let cgImage = UIImage(data: data)?.cgImage,
|
let cgImage = uiImage.cgImage,
|
||||||
await !self.localImageURLString.contains(".gif"),
|
await !self.localImageURLString.contains(".gif"),
|
||||||
cgImage.width < 300 || cgImage.height < 300 {
|
cgImage.width < 300 || cgImage.height < 300 {
|
||||||
data = await resize(image: uiImage, to: CGSize(width: 300, height: 300)).pngData()!
|
data = await resize(image: uiImage, to: CGSize(width: 300, height: 300)).pngData()!
|
||||||
@@ -74,6 +74,6 @@ struct Emoji: StickerProtocol {
|
|||||||
|
|
||||||
static var test: Emoji = Emoji(
|
static var test: Emoji = Emoji(
|
||||||
name: "s?",
|
name: "s?",
|
||||||
url: URL(string: "https://neon443.github.io/images/fav.ico")!
|
url: URL(string: "https://files.catbox.moe/d8go4n.png")!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,20 +6,63 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
//struct Gif: StickerProtocol {
|
struct Gif: StickerProtocol {
|
||||||
// var id: UUID
|
var id: UUID
|
||||||
// var uiID: UUID
|
var uiID: UUID
|
||||||
// var name: String
|
var name: String
|
||||||
// var localImageURLString: String {
|
var localImageURLString: String {
|
||||||
|
let urlString = remoteImageURL.absoluteString
|
||||||
|
let split = urlString.split(separator: ".")
|
||||||
|
let fileExtension = ".\(split.last ?? "png")"
|
||||||
|
|
||||||
|
return EmojiHoarder.container.appendingPathComponent("gifs", conformingTo: .directory).absoluteString+id.uuidString+fileExtension
|
||||||
|
}
|
||||||
|
var remoteImageURL: URL
|
||||||
|
|
||||||
|
// enum CodingKeys: String, CodingKey {
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
// var localImageURL: URL {
|
|
||||||
// return URL(string: localImageURLString)!
|
init(
|
||||||
// }
|
name: String,
|
||||||
// var remoteImageURL: URL
|
url: URL,
|
||||||
//
|
id: UUID = UUID()
|
||||||
// var isLocal: Bool {
|
) {
|
||||||
//
|
self.id = id
|
||||||
// }
|
self.uiID = id
|
||||||
//}
|
self.name = name
|
||||||
|
self.remoteImageURL = url
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadImage() async throws {
|
||||||
|
if let data = try? Data(contentsOf: localImageURL),
|
||||||
|
let _ = UIImage(data: data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var (data, _) = try await URLSession.shared.data(from: remoteImageURL)
|
||||||
|
|
||||||
|
if let uiImage = UIImage(data: data),
|
||||||
|
let cgImage = uiImage.cgImage,
|
||||||
|
!self.localImageURLString.contains(".gif"),
|
||||||
|
cgImage.width < 300 || cgImage.height < 300 {
|
||||||
|
data = resize(image: uiImage, to: CGSize(width: 300, height: 300)).pngData()!
|
||||||
|
}
|
||||||
|
|
||||||
|
try! data.write(to: localImageURL)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
mutating func refresh() {
|
||||||
|
withAnimation { self.uiID = UUID() }
|
||||||
|
}
|
||||||
|
|
||||||
|
static var test: Gif = Gif(
|
||||||
|
name: "doesheknow",
|
||||||
|
url: URL(string: "https://media1.tenor.com/m/FN9udnZmQU8AAAAd/does-he-know-batman.gif")!
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,18 +8,24 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct BrowseView: View {
|
struct BrowseView: View {
|
||||||
|
@State private var browseWhat: StickerType = .slackEmoji
|
||||||
@ObservedObject var hoarder: EmojiHoarder
|
@ObservedObject var hoarder: EmojiHoarder
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
Picker("", selection: .constant(StickerType.giphyGif)) {
|
Picker("", selection: $browseWhat) {
|
||||||
ForEach(StickerType.allCases, id: \.self) { type in
|
ForEach(StickerType.allCases, id: \.self) { type in
|
||||||
Text(type.description)
|
Text(type.description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.pickerStyle(.segmented)
|
.pickerStyle(.segmented)
|
||||||
ForEach(hoarder.emojis, id: \.self) { emoji in
|
switch browseWhat {
|
||||||
EmojiRow(hoarder: hoarder, emoji: emoji)
|
case .slackEmoji:
|
||||||
|
ForEach(hoarder.emojis, id: \.self) { emoji in
|
||||||
|
EmojiRow(hoarder: hoarder, emoji: emoji)
|
||||||
|
}
|
||||||
|
case .giphyGif:
|
||||||
|
Text("hi")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,13 +14,11 @@ struct EmojiRow: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
HStack {
|
||||||
VStack {
|
EmojiPreview(hoarder: hoarder, emoji: emoji)
|
||||||
HStack(spacing: .zero) {
|
|
||||||
Text(emoji.name)
|
|
||||||
}
|
|
||||||
EmojiPreview(hoarder: hoarder, emoji: emoji)
|
|
||||||
}
|
|
||||||
.frame(maxWidth: 100, maxHeight: 100)
|
.frame(maxWidth: 100, maxHeight: 100)
|
||||||
|
.padding(.trailing, 20)
|
||||||
|
|
||||||
|
Text(emoji.name)
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user