Merge branch 'develop' into IOS-31_ActionExtension

This commit is contained in:
Marcus Kida 2023-01-11 15:31:57 +01:00
commit 6e45f8fcd0
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
8 changed files with 12 additions and 25 deletions

View File

@ -13,7 +13,6 @@
- [Fuzi](https://github.com/cezheng/Fuzi) - [Fuzi](https://github.com/cezheng/Fuzi)
- [Kanna](https://github.com/tid-kijyun/Kanna) - [Kanna](https://github.com/tid-kijyun/Kanna)
- [KeychainAccess](https://github.com/kishikawakatsumi/KeychainAccess.git) - [KeychainAccess](https://github.com/kishikawakatsumi/KeychainAccess.git)
- [Kingfisher](https://github.com/onevcat/Kingfisher)
- [MetaTextKit](https://github.com/TwidereProject/MetaTextKit) - [MetaTextKit](https://github.com/TwidereProject/MetaTextKit)
- [Nuke-FLAnimatedImage-Plugin](https://github.com/kean/Nuke-FLAnimatedImage-Plugin) - [Nuke-FLAnimatedImage-Plugin](https://github.com/kean/Nuke-FLAnimatedImage-Plugin)
- [Nuke](https://github.com/kean/Nuke) - [Nuke](https://github.com/kean/Nuke)

View File

@ -73,15 +73,6 @@
"version": "4.2.2" "version": "4.2.2"
} }
}, },
{
"package": "Kingfisher",
"repositoryURL": "https://github.com/onevcat/Kingfisher.git",
"state": {
"branch": null,
"revision": "44e891bdb61426a95e31492a67c7c0dfad1f87c5",
"version": "7.4.1"
}
},
{ {
"package": "MetaTextKit", "package": "MetaTextKit",
"repositoryURL": "https://github.com/TwidereProject/MetaTextKit.git", "repositoryURL": "https://github.com/TwidereProject/MetaTextKit.git",

View File

@ -56,7 +56,6 @@ let package = Package(
.package(url: "https://github.com/woxtu/UIHostingConfigurationBackport.git", from: "0.1.0"), .package(url: "https://github.com/woxtu/UIHostingConfigurationBackport.git", from: "0.1.0"),
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.12.0"), .package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.12.0"),
.package(url: "https://github.com/eneko/Stripes.git", from: "0.2.0"), .package(url: "https://github.com/eneko/Stripes.git", from: "0.2.0"),
.package(url: "https://github.com/onevcat/Kingfisher.git", from: "7.4.1"),
.package(url: "https://github.com/NextLevel/NextLevelSessionExporter.git", from: "0.4.6"), .package(url: "https://github.com/NextLevel/NextLevelSessionExporter.git", from: "0.4.6"),
], ],
targets: [ targets: [
@ -131,7 +130,6 @@ let package = Package(
.product(name: "CropViewController", package: "TOCropViewController"), .product(name: "CropViewController", package: "TOCropViewController"),
.product(name: "PanModal", package: "PanModal"), .product(name: "PanModal", package: "PanModal"),
.product(name: "Stripes", package: "Stripes"), .product(name: "Stripes", package: "Stripes"),
.product(name: "Kingfisher", package: "Kingfisher"),
.product(name: "NextLevelSessionExporter", package: "NextLevelSessionExporter"), .product(name: "NextLevelSessionExporter", package: "NextLevelSessionExporter"),
] ]
), ),

View File

@ -10,7 +10,7 @@ import UIKit
import AVKit import AVKit
import MastodonCore import MastodonCore
import SessionExporter import SessionExporter
import Kingfisher import Nuke
extension AttachmentViewModel { extension AttachmentViewModel {
func compressVideo(url: URL) async throws -> URL { func compressVideo(url: URL) async throws -> URL {
@ -99,18 +99,18 @@ extension AttachmentViewModel {
func compressImage(data: Data, sizeLimit: SizeLimit) throws -> Output { func compressImage(data: Data, sizeLimit: SizeLimit) throws -> Output {
let maxPayloadSizeInBytes = max((sizeLimit.image ?? 10 * 1024 * 1024), 1 * 1024 * 1024) let maxPayloadSizeInBytes = max((sizeLimit.image ?? 10 * 1024 * 1024), 1 * 1024 * 1024)
guard let image = KFCrossPlatformImage(data: data)?.kf.normalized, guard let image = UIImage(data: data)?.normalized(),
var imageData = image.kf.pngRepresentation() var imageData = image.pngData()
else { else {
throw AttachmentError.invalidAttachmentType throw AttachmentError.invalidAttachmentType
} }
repeat { repeat {
guard let image = KFCrossPlatformImage(data: imageData) else { guard let image = UIImage(data: imageData) else {
throw AttachmentError.invalidAttachmentType throw AttachmentError.invalidAttachmentType
} }
if imageData.kf.imageFormat == .PNG { if AssetType(imageData) == .png {
// A. png image // A. png image
if imageData.count > maxPayloadSizeInBytes { if imageData.count > maxPayloadSizeInBytes {
guard let compressedJpegData = image.jpegData(compressionQuality: 0.8) else { guard let compressedJpegData = image.jpegData(compressionQuality: 0.8) else {
@ -126,7 +126,7 @@ extension AttachmentViewModel {
// B. other image // B. other image
if imageData.count > maxPayloadSizeInBytes { if imageData.count > maxPayloadSizeInBytes {
let targetSize = CGSize(width: image.size.width * 0.8, height: image.size.height * 0.8) let targetSize = CGSize(width: image.size.width * 0.8, height: image.size.height * 0.8)
let scaledImage = image.kf.resize(to: targetSize) let scaledImage = image.resized(size: targetSize)
guard let compressedJpegData = scaledImage.jpegData(compressionQuality: 0.8) else { guard let compressedJpegData = scaledImage.jpegData(compressionQuality: 0.8) else {
throw AttachmentError.invalidAttachmentType throw AttachmentError.invalidAttachmentType
} }
@ -140,7 +140,7 @@ extension AttachmentViewModel {
} while (imageData.count > maxPayloadSizeInBytes) } while (imageData.count > maxPayloadSizeInBytes)
return .image(imageData, imageKind: imageData.kf.imageFormat == .PNG ? .png : .jpg) return .image(imageData, imageKind: AssetType(imageData) == .png ? .png : .jpg)
} }
} }

View File

@ -9,6 +9,7 @@ import os.log
import UIKit import UIKit
import AVKit import AVKit
import UniformTypeIdentifiers import UniformTypeIdentifiers
import Nuke
extension AttachmentViewModel { extension AttachmentViewModel {
@ -55,7 +56,7 @@ extension AttachmentViewModel {
} }
defer { url.stopAccessingSecurityScopedResource() } defer { url.stopAccessingSecurityScopedResource() }
let imageData = try Data(contentsOf: url) let imageData = try Data(contentsOf: url)
return .image(imageData, imageKind: imageData.kf.imageFormat == .PNG ? .png : .jpg) return .image(imageData, imageKind: AssetType(imageData) == .png ? .png : .jpg)
} else if uti.conforms(to: .movie) { } else if uti.conforms(to: .movie) {
guard url.startAccessingSecurityScopedResource() else { guard url.startAccessingSecurityScopedResource() else {
throw AttachmentError.invalidAttachmentType throw AttachmentError.invalidAttachmentType
@ -89,11 +90,12 @@ extension AttachmentViewModel {
} }
let imageData = result.data let imageData = result.data
let assetType = AssetType(imageData)
if imageData.kf.imageFormat == .PNG { if assetType == .png {
return .png return .png
} }
if imageData.kf.imageFormat == .JPEG { if assetType == .jpeg {
return .jpg return .jpg
} }

View File

@ -7,7 +7,6 @@
import os.log import os.log
import UIKit import UIKit
import Kingfisher
import UniformTypeIdentifiers import UniformTypeIdentifiers
import MastodonCore import MastodonCore
import MastodonSDK import MastodonSDK

View File

@ -9,7 +9,6 @@ import os.log
import UIKit import UIKit
import Combine import Combine
import PhotosUI import PhotosUI
import Kingfisher
import MastodonCore import MastodonCore
import MastodonLocalization import MastodonLocalization
import func QuartzCore.CACurrentMediaTime import func QuartzCore.CACurrentMediaTime

View File

@ -11,7 +11,6 @@ import MastodonAsset
import MastodonCore import MastodonCore
import MastodonLocalization import MastodonLocalization
import Stripes import Stripes
import Kingfisher
public struct ComposeContentView: View { public struct ComposeContentView: View {