From 49063f7d9ab484b877e901d8b9f006a3ef0ff71d Mon Sep 17 00:00:00 2001 From: Lumaa Date: Sun, 28 Jan 2024 17:49:08 +0100 Subject: [PATCH] Forgot credit EmojiText --- README.md | 1 + Threaded/Data/Content/Compressor.swift | 3 + .../Data/Content/MediaTransferables.swift | 94 +++++++++++++++++++ .../Data/Content/ShareableOnlineImage.swift | 24 ----- Threaded/Localizable.xcstrings | 2 +- 5 files changed, 99 insertions(+), 25 deletions(-) create mode 100644 Threaded/Data/Content/Compressor.swift create mode 100644 Threaded/Data/Content/MediaTransferables.swift delete mode 100644 Threaded/Data/Content/ShareableOnlineImage.swift diff --git a/README.md b/README.md index e5d24bb..26d4269 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Threaded is a 100% free, made in SwiftUI, [#OpenSource](https://github.com/luma - [IceCubesApp](https://github.com/dimillian/IceCubesApp) by [@dimillian](https://github.com/dimillian) - [SwiftSoup](https://github.com/scinfu/SwiftSoup) - [Nuke](https://github.com/kean/Nuke) +- [EmojiText](https://github.com/divadretlaw/EmojiText) ## To-do list diff --git a/Threaded/Data/Content/Compressor.swift b/Threaded/Data/Content/Compressor.swift new file mode 100644 index 0000000..02c3e31 --- /dev/null +++ b/Threaded/Data/Content/Compressor.swift @@ -0,0 +1,3 @@ +//Made by Lumaa + +import Foundation diff --git a/Threaded/Data/Content/MediaTransferables.swift b/Threaded/Data/Content/MediaTransferables.swift new file mode 100644 index 0000000..15ca00e --- /dev/null +++ b/Threaded/Data/Content/MediaTransferables.swift @@ -0,0 +1,94 @@ +//Made by Lumaa + +import Foundation +import SwiftUI +import UIKit +import UniformTypeIdentifiers + +// Dimillian fixed it - https://mastodon.social/@dimillian/111708477095374920 + +struct ShareableOnlineImage: Codable, Transferable { + let url: URL + + func fetchAsImage() -> Image { + let data = try? Data(contentsOf: url) + guard let data, let uiimage = UIImage(data: data) else { + return Image(systemName: "photo") + } + return Image(uiImage: uiimage) + } + + static var transferRepresentation: some TransferRepresentation { + ProxyRepresentation { media in + media.fetchAsImage() + } + } +} + +extension PostingView { + final class MovieFileTransferable: Transferable, Sendable { + let url: URL + + init(url: URL) { + self.url = url + _ = url.startAccessingSecurityScopedResource() + } + + deinit { + url.stopAccessingSecurityScopedResource() + } + + static var transferRepresentation: some TransferRepresentation { + FileRepresentation(importedContentType: .movie) { receivedTransferrable in + return MovieFileTransferable(url: receivedTransferrable.file) + } + FileRepresentation(importedContentType: .video) { receivedTransferrable in + return MovieFileTransferable(url: receivedTransferrable.file) + } + } + } + + final class GifFileTranseferable: Transferable, Sendable { + let url: URL + + init(url: URL) { + self.url = url + _ = url.startAccessingSecurityScopedResource() + } + + deinit { + url.stopAccessingSecurityScopedResource() + } + + var data: Data? { + try? Data(contentsOf: url) + } + + static var transferRepresentation: some TransferRepresentation { + FileRepresentation(importedContentType: .gif) { receivedTransferrable in + return GifFileTranseferable(url: receivedTransferrable.file) + } + } + } +} + +extension PostingView { + final class ImageFileTranseferable: Transferable, Sendable { + public let url: URL + + init(url: URL) { + self.url = url + _ = url.startAccessingSecurityScopedResource() + } + + deinit { + url.stopAccessingSecurityScopedResource() + } + + public static var transferRepresentation: some TransferRepresentation { + FileRepresentation(importedContentType: .image) { receivedTransferrable in + return ImageFileTranseferable(url: receivedTransferrable.file) + } + } + } +} diff --git a/Threaded/Data/Content/ShareableOnlineImage.swift b/Threaded/Data/Content/ShareableOnlineImage.swift deleted file mode 100644 index 1e1f7b0..0000000 --- a/Threaded/Data/Content/ShareableOnlineImage.swift +++ /dev/null @@ -1,24 +0,0 @@ -//Made by Lumaa - -import Foundation -import SwiftUI - -// Dimillian fixed it - https://mastodon.social/@dimillian/111708477095374920 - -struct ShareableOnlineImage: Codable, Transferable { - let url: URL - - func fetchAsImage() -> Image { - let data = try? Data(contentsOf: url) - guard let data, let uiimage = UIImage(data: data) else { - return Image(systemName: "photo") - } - return Image(uiImage: uiimage) - } - - static var transferRepresentation: some TransferRepresentation { - ProxyRepresentation { media in - media.fetchAsImage() - } - } -} diff --git a/Threaded/Localizable.xcstrings b/Threaded/Localizable.xcstrings index 8461654..147cd27 100644 --- a/Threaded/Localizable.xcstrings +++ b/Threaded/Localizable.xcstrings @@ -48,7 +48,7 @@ "en" : { "stringUnit" : { "state" : "translated", - "value" : "Threaded uses third-party open-source libraries and code:\n- [IceCubesApp](https://github.com/dimillian/IceCubesApp)\n- [SwiftSoup](https://github.com/scinfu/SwiftSoup)\n- [Nuke](https://github.com/kean/Nuke)" + "value" : "Threaded uses third-party open-source libraries and code:\n- [IceCubesApp](https://github.com/dimillian/IceCubesApp)\n- [SwiftSoup](https://github.com/scinfu/SwiftSoup)\n- [Nuke](https://github.com/kean/Nuke)\n- [EmojiText](https://github.com/divadretlaw/EmojiText)" } } }