mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-18 03:36:30 +00:00
Add BlurHash
This commit is contained in:
parent
187bc42373
commit
19963de055
8 changed files with 83 additions and 12 deletions
|
@ -37,9 +37,9 @@ public struct Attachment: Codable, Hashable {
|
||||||
public let url: URL
|
public let url: URL
|
||||||
public let remoteUrl: URL?
|
public let remoteUrl: URL?
|
||||||
public let previewUrl: URL?
|
public let previewUrl: URL?
|
||||||
public let textUrl: URL?
|
|
||||||
public let meta: Meta?
|
public let meta: Meta?
|
||||||
public let description: String?
|
public let description: String?
|
||||||
|
public let blurhash: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension Attachment {
|
public extension Attachment {
|
||||||
|
|
|
@ -91,6 +91,7 @@
|
||||||
D0625E59250F092900502611 /* StatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0625E58250F092900502611 /* StatusTableViewCell.swift */; };
|
D0625E59250F092900502611 /* StatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0625E58250F092900502611 /* StatusTableViewCell.swift */; };
|
||||||
D0625E5D250F0B5C00502611 /* StatusContentConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0625E5C250F0B5C00502611 /* StatusContentConfiguration.swift */; };
|
D0625E5D250F0B5C00502611 /* StatusContentConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0625E5C250F0B5C00502611 /* StatusContentConfiguration.swift */; };
|
||||||
D06BC5E625202AD90079541D /* ProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06BC5E525202AD90079541D /* ProfileViewController.swift */; };
|
D06BC5E625202AD90079541D /* ProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06BC5E525202AD90079541D /* ProfileViewController.swift */; };
|
||||||
|
D06FA32725F0659600C9639A /* BlurHash in Frameworks */ = {isa = PBXBuildFile; productRef = D06FA32625F0659600C9639A /* BlurHash */; };
|
||||||
D07EC7CF25B13921006DF726 /* PickerEmoji+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D07EC7CE25B13921006DF726 /* PickerEmoji+Extensions.swift */; };
|
D07EC7CF25B13921006DF726 /* PickerEmoji+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D07EC7CE25B13921006DF726 /* PickerEmoji+Extensions.swift */; };
|
||||||
D07EC7D025B13921006DF726 /* PickerEmoji+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D07EC7CE25B13921006DF726 /* PickerEmoji+Extensions.swift */; };
|
D07EC7D025B13921006DF726 /* PickerEmoji+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D07EC7CE25B13921006DF726 /* PickerEmoji+Extensions.swift */; };
|
||||||
D07EC7DC25B13DBB006DF726 /* EmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D07EC7DB25B13DBB006DF726 /* EmojiCollectionViewCell.swift */; };
|
D07EC7DC25B13DBB006DF726 /* EmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D07EC7DB25B13DBB006DF726 /* EmojiCollectionViewCell.swift */; };
|
||||||
|
@ -183,6 +184,7 @@
|
||||||
D0D2AC4D25BCD2A9003D5DF2 /* TagTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D2AC4C25BCD2A9003D5DF2 /* TagTableViewCell.swift */; };
|
D0D2AC4D25BCD2A9003D5DF2 /* TagTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D2AC4C25BCD2A9003D5DF2 /* TagTableViewCell.swift */; };
|
||||||
D0D2AC5325BCD2BA003D5DF2 /* TagContentConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D2AC5225BCD2BA003D5DF2 /* TagContentConfiguration.swift */; };
|
D0D2AC5325BCD2BA003D5DF2 /* TagContentConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D2AC5225BCD2BA003D5DF2 /* TagContentConfiguration.swift */; };
|
||||||
D0D2AC6725BD0484003D5DF2 /* LineChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D2AC6625BD0484003D5DF2 /* LineChartView.swift */; };
|
D0D2AC6725BD0484003D5DF2 /* LineChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D2AC6625BD0484003D5DF2 /* LineChartView.swift */; };
|
||||||
|
D0D4301425F067D600BE5504 /* BlurHash in Frameworks */ = {isa = PBXBuildFile; productRef = D0D4301325F067D600BE5504 /* BlurHash */; };
|
||||||
D0D93EBA25D9C70400C622ED /* AutocompleteItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D93EB925D9C70400C622ED /* AutocompleteItemView.swift */; };
|
D0D93EBA25D9C70400C622ED /* AutocompleteItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D93EB925D9C70400C622ED /* AutocompleteItemView.swift */; };
|
||||||
D0D93EC025D9C71D00C622ED /* AutocompleteItemContentConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D93EBF25D9C71D00C622ED /* AutocompleteItemContentConfiguration.swift */; };
|
D0D93EC025D9C71D00C622ED /* AutocompleteItemContentConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D93EBF25D9C71D00C622ED /* AutocompleteItemContentConfiguration.swift */; };
|
||||||
D0D93EC525D9C75E00C622ED /* AutocompleteItemContentConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D93EBF25D9C71D00C622ED /* AutocompleteItemContentConfiguration.swift */; };
|
D0D93EC525D9C75E00C622ED /* AutocompleteItemContentConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D93EBF25D9C71D00C622ED /* AutocompleteItemContentConfiguration.swift */; };
|
||||||
|
@ -442,6 +444,7 @@
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
D0E2C1D124FD97F000854680 /* ViewModels in Frameworks */,
|
D0E2C1D124FD97F000854680 /* ViewModels in Frameworks */,
|
||||||
|
D06FA32725F0659600C9639A /* BlurHash in Frameworks */,
|
||||||
D04F34B625E42ABE00714251 /* SDWebImage in Frameworks */,
|
D04F34B625E42ABE00714251 /* SDWebImage in Frameworks */,
|
||||||
D0FE7C8025C4C79F00203957 /* PreviewViewModels in Frameworks */,
|
D0FE7C8025C4C79F00203957 /* PreviewViewModels in Frameworks */,
|
||||||
);
|
);
|
||||||
|
@ -458,6 +461,7 @@
|
||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
D0D4301425F067D600BE5504 /* BlurHash in Frameworks */,
|
||||||
D04F34BC25E42ADC00714251 /* SDWebImage in Frameworks */,
|
D04F34BC25E42ADC00714251 /* SDWebImage in Frameworks */,
|
||||||
D04F9E8E259E9C950081B0C9 /* ViewModels in Frameworks */,
|
D04F9E8E259E9C950081B0C9 /* ViewModels in Frameworks */,
|
||||||
);
|
);
|
||||||
|
@ -862,6 +866,7 @@
|
||||||
D0E2C1D024FD97F000854680 /* ViewModels */,
|
D0E2C1D024FD97F000854680 /* ViewModels */,
|
||||||
D0FE7C7F25C4C79F00203957 /* PreviewViewModels */,
|
D0FE7C7F25C4C79F00203957 /* PreviewViewModels */,
|
||||||
D04F34B525E42ABE00714251 /* SDWebImage */,
|
D04F34B525E42ABE00714251 /* SDWebImage */,
|
||||||
|
D06FA32625F0659600C9639A /* BlurHash */,
|
||||||
);
|
);
|
||||||
productName = "Metatext (iOS)";
|
productName = "Metatext (iOS)";
|
||||||
productReference = D047FA8C24C3E21200AF17C5 /* Metatext.app */;
|
productReference = D047FA8C24C3E21200AF17C5 /* Metatext.app */;
|
||||||
|
@ -903,6 +908,7 @@
|
||||||
packageProductDependencies = (
|
packageProductDependencies = (
|
||||||
D04F9E8D259E9C950081B0C9 /* ViewModels */,
|
D04F9E8D259E9C950081B0C9 /* ViewModels */,
|
||||||
D04F34BB25E42ADC00714251 /* SDWebImage */,
|
D04F34BB25E42ADC00714251 /* SDWebImage */,
|
||||||
|
D0D4301325F067D600BE5504 /* BlurHash */,
|
||||||
);
|
);
|
||||||
productName = "Share Extension";
|
productName = "Share Extension";
|
||||||
productReference = D08E526C257C36CA00FA2C5F /* Share Extension.appex */;
|
productReference = D08E526C257C36CA00FA2C5F /* Share Extension.appex */;
|
||||||
|
@ -966,6 +972,7 @@
|
||||||
mainGroup = D047FA7F24C3E21000AF17C5;
|
mainGroup = D047FA7F24C3E21000AF17C5;
|
||||||
packageReferences = (
|
packageReferences = (
|
||||||
D04F34B425E42ABE00714251 /* XCRemoteSwiftPackageReference "SDWebImage" */,
|
D04F34B425E42ABE00714251 /* XCRemoteSwiftPackageReference "SDWebImage" */,
|
||||||
|
D06FA32525F0659600C9639A /* XCRemoteSwiftPackageReference "blurhash" */,
|
||||||
);
|
);
|
||||||
productRefGroup = D047FA8D24C3E21200AF17C5 /* Products */;
|
productRefGroup = D047FA8D24C3E21200AF17C5 /* Products */;
|
||||||
projectDirPath = "";
|
projectDirPath = "";
|
||||||
|
@ -1664,6 +1671,14 @@
|
||||||
minimumVersion = 5.10.4;
|
minimumVersion = 5.10.4;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
D06FA32525F0659600C9639A /* XCRemoteSwiftPackageReference "blurhash" */ = {
|
||||||
|
isa = XCRemoteSwiftPackageReference;
|
||||||
|
repositoryURL = "https://github.com/metabolist/blurhash.git";
|
||||||
|
requirement = {
|
||||||
|
kind = upToNextMajorVersion;
|
||||||
|
minimumVersion = 1.0.0;
|
||||||
|
};
|
||||||
|
};
|
||||||
/* End XCRemoteSwiftPackageReference section */
|
/* End XCRemoteSwiftPackageReference section */
|
||||||
|
|
||||||
/* Begin XCSwiftPackageProductDependency section */
|
/* Begin XCSwiftPackageProductDependency section */
|
||||||
|
@ -1690,6 +1705,16 @@
|
||||||
isa = XCSwiftPackageProductDependency;
|
isa = XCSwiftPackageProductDependency;
|
||||||
productName = ViewModels;
|
productName = ViewModels;
|
||||||
};
|
};
|
||||||
|
D06FA32625F0659600C9639A /* BlurHash */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = D06FA32525F0659600C9639A /* XCRemoteSwiftPackageReference "blurhash" */;
|
||||||
|
productName = BlurHash;
|
||||||
|
};
|
||||||
|
D0D4301325F067D600BE5504 /* BlurHash */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = D06FA32525F0659600C9639A /* XCRemoteSwiftPackageReference "blurhash" */;
|
||||||
|
productName = BlurHash;
|
||||||
|
};
|
||||||
D0E2C1D024FD97F000854680 /* ViewModels */ = {
|
D0E2C1D024FD97F000854680 /* ViewModels */ = {
|
||||||
isa = XCSwiftPackageProductDependency;
|
isa = XCSwiftPackageProductDependency;
|
||||||
productName = ViewModels;
|
productName = ViewModels;
|
||||||
|
|
|
@ -10,6 +10,15 @@
|
||||||
"version": "1.0.0"
|
"version": "1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"package": "BlurHash",
|
||||||
|
"repositoryURL": "https://github.com/metabolist/blurhash.git",
|
||||||
|
"state": {
|
||||||
|
"branch": null,
|
||||||
|
"revision": "4d86c470d866b2d8989adc5a65b121221e40df54",
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"package": "CodableBloomFilter",
|
"package": "CodableBloomFilter",
|
||||||
"repositoryURL": "https://github.com/metabolist/codable-bloom-filter.git",
|
"repositoryURL": "https://github.com/metabolist/codable-bloom-filter.git",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright © 2020 Metabolist. All rights reserved.
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||||||
|
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
|
import BlurHash
|
||||||
import Mastodon
|
import Mastodon
|
||||||
import SDWebImage
|
import SDWebImage
|
||||||
import UIKit
|
import UIKit
|
||||||
|
@ -111,11 +112,16 @@ final class ImageViewController: UIViewController {
|
||||||
imageView.tag = viewModel.tag
|
imageView.tag = viewModel.tag
|
||||||
playerView.isHidden = true
|
playerView.isHidden = true
|
||||||
|
|
||||||
let placeholderKey = viewModel.attachment.previewUrl?.absoluteString
|
let placeholderImage: UIImage?
|
||||||
let placeholderImage = SDImageCache.shared.imageFromCache(forKey: placeholderKey)
|
let cachedImageKey = viewModel.attachment.previewUrl?.absoluteString
|
||||||
|
let cachedImage = SDImageCache.shared.imageFromCache(forKey: cachedImageKey)
|
||||||
|
|
||||||
if placeholderImage != nil {
|
if cachedImage != nil {
|
||||||
imageView.sd_imageIndicator = nil
|
placeholderImage = cachedImage
|
||||||
|
} else if let blurHash = viewModel.attachment.blurhash {
|
||||||
|
placeholderImage = UIImage(blurHash: blurHash, size: .blurHashSize)
|
||||||
|
} else {
|
||||||
|
placeholderImage = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
imageView.sd_setImage(with: viewModel.attachment.url, placeholderImage: placeholderImage)
|
imageView.sd_setImage(with: viewModel.attachment.url, placeholderImage: placeholderImage)
|
||||||
|
|
|
@ -22,6 +22,7 @@ struct AcknowledgmentsView: View {
|
||||||
|
|
||||||
private extension AcknowledgmentsView {
|
private extension AcknowledgmentsView {
|
||||||
enum Acknowledgment: CaseIterable {
|
enum Acknowledgment: CaseIterable {
|
||||||
|
case blurHash
|
||||||
case combineExpectations
|
case combineExpectations
|
||||||
case grdb
|
case grdb
|
||||||
case sdwebimage
|
case sdwebimage
|
||||||
|
@ -32,6 +33,8 @@ private extension AcknowledgmentsView {
|
||||||
extension AcknowledgmentsView.Acknowledgment {
|
extension AcknowledgmentsView.Acknowledgment {
|
||||||
var name: String {
|
var name: String {
|
||||||
switch self {
|
switch self {
|
||||||
|
case .blurHash:
|
||||||
|
return "BlurHash"
|
||||||
case .combineExpectations:
|
case .combineExpectations:
|
||||||
return "CombineExpectations"
|
return "CombineExpectations"
|
||||||
case .grdb:
|
case .grdb:
|
||||||
|
@ -45,6 +48,8 @@ extension AcknowledgmentsView.Acknowledgment {
|
||||||
|
|
||||||
var url: URL {
|
var url: URL {
|
||||||
switch self {
|
switch self {
|
||||||
|
case .blurHash:
|
||||||
|
return URL(string: "https://github.com/woltapp/blurhash")!
|
||||||
case .combineExpectations:
|
case .combineExpectations:
|
||||||
return URL(string: "https://github.com/groue/CombineExpectations")!
|
return URL(string: "https://github.com/groue/CombineExpectations")!
|
||||||
case .grdb:
|
case .grdb:
|
||||||
|
@ -59,6 +64,16 @@ extension AcknowledgmentsView.Acknowledgment {
|
||||||
// swiftlint:disable line_length
|
// swiftlint:disable line_length
|
||||||
var license: String {
|
var license: String {
|
||||||
switch self {
|
switch self {
|
||||||
|
case .blurHash:
|
||||||
|
return """
|
||||||
|
Copyright (c) 2018 Wolt Enterprises
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
"""
|
||||||
case .combineExpectations:
|
case .combineExpectations:
|
||||||
return """
|
return """
|
||||||
Copyright (C) 2019 Gwendal Roué
|
Copyright (C) 2019 Gwendal Roué
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright © 2020 Metabolist. All rights reserved.
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||||||
|
|
||||||
import AVKit
|
import AVKit
|
||||||
|
import BlurHash
|
||||||
import Combine
|
import Combine
|
||||||
import SDWebImage
|
import SDWebImage
|
||||||
import UIKit
|
import UIKit
|
||||||
|
@ -169,7 +170,17 @@ private extension AttachmentView {
|
||||||
|
|
||||||
switch viewModel.attachment.type {
|
switch viewModel.attachment.type {
|
||||||
case .image, .video, .gifv:
|
case .image, .video, .gifv:
|
||||||
imageView.sd_setImage(with: viewModel.attachment.previewUrl) { [weak self] _, _, _, _ in
|
let placeholderImage: UIImage?
|
||||||
|
|
||||||
|
if let blurHash = viewModel.attachment.blurhash {
|
||||||
|
placeholderImage = UIImage(blurHash: blurHash, size: .blurHashSize)
|
||||||
|
} else {
|
||||||
|
placeholderImage = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
imageView.sd_setImage(
|
||||||
|
with: viewModel.attachment.previewUrl,
|
||||||
|
placeholderImage: placeholderImage) { [weak self] _, _, _, _ in
|
||||||
self?.layoutSubviews()
|
self?.layoutSubviews()
|
||||||
}
|
}
|
||||||
case .audio:
|
case .audio:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// Copyright © 2021 Metabolist. All rights reserved.
|
// Copyright © 2021 Metabolist. All rights reserved.
|
||||||
|
|
||||||
|
import BlurHash
|
||||||
import Combine
|
import Combine
|
||||||
import SDWebImage
|
import SDWebImage
|
||||||
import UIKit
|
import UIKit
|
||||||
|
@ -142,15 +143,15 @@ private extension EditThumbnailView {
|
||||||
switch viewModel.attachment.type {
|
switch viewModel.attachment.type {
|
||||||
case .image:
|
case .image:
|
||||||
playerView.isHidden = true
|
playerView.isHidden = true
|
||||||
|
let placeholderImage: UIImage?
|
||||||
|
|
||||||
let placeholderKey = viewModel.attachment.previewUrl?.absoluteString
|
if let blurHash = viewModel.attachment.blurhash {
|
||||||
let placeholderImage = SDImageCache.shared.imageFromCache(forKey: placeholderKey)
|
placeholderImage = UIImage(blurHash: blurHash, size: .blurHashSize)
|
||||||
|
} else {
|
||||||
if placeholderImage != nil {
|
placeholderImage = nil
|
||||||
imageView.sd_imageIndicator = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imageView.sd_setImage(with: viewModel.attachment.url, placeholderImage: placeholderImage)
|
imageView.sd_setImage(with: viewModel.attachment.previewUrl, placeholderImage: placeholderImage)
|
||||||
case .gifv:
|
case .gifv:
|
||||||
imageView.isHidden = true
|
imageView.isHidden = true
|
||||||
let player = PlayerCache.shared.player(url: viewModel.attachment.url)
|
let player = PlayerCache.shared.player(url: viewModel.attachment.url)
|
||||||
|
|
|
@ -21,6 +21,10 @@ extension Float {
|
||||||
static let defaultShadowOpacity: Self = 0.25
|
static let defaultShadowOpacity: Self = 0.25
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension CGSize {
|
||||||
|
static let blurHashSize = Self(width: 32, height: 32)
|
||||||
|
}
|
||||||
|
|
||||||
extension CGRect {
|
extension CGRect {
|
||||||
static let defaultContentsRect = Self(origin: .zero, size: .init(width: 1, height: 1))
|
static let defaultContentsRect = Self(origin: .zero, size: .init(width: 1, height: 1))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue