mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
More photo upload fixes
This commit is contained in:
@@ -476,9 +476,19 @@ public class CheckLayer: CALayer {
|
|||||||
|
|
||||||
context.strokePath()
|
context.strokePath()
|
||||||
case let .counter(number):
|
case let .counter(number):
|
||||||
let text = NSAttributedString(string: "\(number)", font: Font.with(size: 16.0, design: .round, weight: .regular, traits: []), textColor: parameters.theme.strokeColor.withMultipliedAlpha(parameters.animationProgress))
|
let fontSize: CGFloat
|
||||||
|
let string = "\(number)"
|
||||||
|
switch string.count {
|
||||||
|
case 1:
|
||||||
|
fontSize = 16.0
|
||||||
|
case 2:
|
||||||
|
fontSize = 15.0
|
||||||
|
default:
|
||||||
|
fontSize = 13.0
|
||||||
|
}
|
||||||
|
let text = NSAttributedString(string: string, font: Font.with(size: fontSize, design: .round, weight: .medium, traits: []), textColor: parameters.theme.strokeColor.withMultipliedAlpha(parameters.animationProgress))
|
||||||
let textRect = text.boundingRect(with: CGSize(width: 100.0, height: 100.0), options: [.usesLineFragmentOrigin], context: nil)
|
let textRect = text.boundingRect(with: CGSize(width: 100.0, height: 100.0), options: [.usesLineFragmentOrigin], context: nil)
|
||||||
text.draw(at: CGPoint(x: UIScreenPixel + textRect.minX + floor((size.width - textRect.width) * 0.5), y: textRect.minY + floorToScreenPixels((size.height - textRect.height) * 0.5)))
|
text.draw(at: CGPoint(x: textRect.minX + floorToScreenPixels((size.width - textRect.width) * 0.5), y: textRect.minY + floorToScreenPixels((size.height - textRect.height) * 0.5)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,29 +83,25 @@ extension UIImage.Orientation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private let fetchPhotoWorkers = ThreadPool(threadCount: 3, threadPriority: 0.2)
|
private let fetchPhotoWorkers = ThreadPool(threadCount: 3, threadPriority: 0.2)
|
||||||
private let fetchPhotoQueue = ThreadPoolQueue(threadPool: fetchPhotoWorkers)
|
|
||||||
|
|
||||||
public func fetchPhotoLibraryResource(localIdentifier: String) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> {
|
public func fetchPhotoLibraryResource(localIdentifier: String) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> {
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
|
let queue = ThreadPoolQueue(threadPool: fetchPhotoWorkers)
|
||||||
|
|
||||||
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [localIdentifier], options: nil)
|
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [localIdentifier], options: nil)
|
||||||
let requestId = Atomic<RequestId>(value: RequestId())
|
let requestId = Atomic<RequestId>(value: RequestId())
|
||||||
if fetchResult.count != 0 {
|
if fetchResult.count != 0 {
|
||||||
let asset = fetchResult.object(at: 0)
|
let asset = fetchResult.object(at: 0)
|
||||||
let option = PHImageRequestOptions()
|
let option = PHImageRequestOptions()
|
||||||
option.deliveryMode = .opportunistic
|
option.deliveryMode = .highQualityFormat
|
||||||
option.isNetworkAccessAllowed = true
|
option.isNetworkAccessAllowed = true
|
||||||
option.isSynchronous = false
|
option.isSynchronous = false
|
||||||
let madeProgress = Atomic<Bool>(value: false)
|
|
||||||
option.progressHandler = { progress, error, _, _ in
|
|
||||||
if !madeProgress.swap(true) {
|
|
||||||
//subscriber.putNext(.reset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let size = CGSize(width: 1280.0, height: 1280.0)
|
let size = CGSize(width: 1280.0, height: 1280.0)
|
||||||
|
|
||||||
|
queue.addTask(ThreadPoolTask({ _ in
|
||||||
let startTime = CACurrentMediaTime()
|
let startTime = CACurrentMediaTime()
|
||||||
|
|
||||||
fetchPhotoQueue.addTask(ThreadPoolTask({ _ in
|
|
||||||
let semaphore = DispatchSemaphore(value: 0)
|
let semaphore = DispatchSemaphore(value: 0)
|
||||||
let requestIdValue = PHImageManager.default().requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .aspectFit, options: option, resultHandler: { (image, info) -> Void in
|
let requestIdValue = PHImageManager.default().requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .aspectFit, options: option, resultHandler: { (image, info) -> Void in
|
||||||
Queue.concurrentDefaultQueue().async {
|
Queue.concurrentDefaultQueue().async {
|
||||||
@@ -117,16 +113,12 @@ public func fetchPhotoLibraryResource(localIdentifier: String) -> Signal<MediaRe
|
|||||||
}
|
}
|
||||||
if let image = image {
|
if let image = image {
|
||||||
if let info = info, let degraded = info[PHImageResultIsDegradedKey], (degraded as AnyObject).boolValue!{
|
if let info = info, let degraded = info[PHImageResultIsDegradedKey], (degraded as AnyObject).boolValue!{
|
||||||
if !madeProgress.swap(true) {
|
|
||||||
//subscriber.putNext(.reset)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
print("load completion \((CACurrentMediaTime() - startTime) * 1000.0) ms")
|
print("load completion \((CACurrentMediaTime() - startTime) * 1000.0) ms")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_ = madeProgress.swap(true)
|
|
||||||
|
|
||||||
let scale = min(1.0, min(size.width / max(1.0, image.size.width), size.height / max(1.0, image.size.height)))
|
let scale = min(1.0, min(size.width / max(1.0, image.size.width), size.height / max(1.0, image.size.height)))
|
||||||
let scaledSize = CGSize(width: floor(image.size.width * scale), height: floor(image.size.height * scale))
|
let scaledSize = CGSize(width: floor(image.size.width * scale), height: floor(image.size.height * scale))
|
||||||
let scaledImage = resizedImage(image, for: scaledSize)
|
let scaledImage = resizedImage(image, for: scaledSize)
|
||||||
@@ -144,14 +136,12 @@ public func fetchPhotoLibraryResource(localIdentifier: String) -> Signal<MediaRe
|
|||||||
} else {
|
} else {
|
||||||
subscriber.putCompletion()
|
subscriber.putCompletion()
|
||||||
}
|
}
|
||||||
|
semaphore.signal()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !madeProgress.swap(true) {
|
|
||||||
//subscriber.putNext(.reset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
semaphore.signal()
|
semaphore.signal()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
requestId.with { current -> Void in
|
requestId.with { current -> Void in
|
||||||
if !current.invalidated {
|
if !current.invalidated {
|
||||||
|
|||||||
@@ -207,13 +207,6 @@ private final class FetchVideoLibraryMediaResourceContext {
|
|||||||
private let throttlingContext = FetchVideoLibraryMediaResourceContext()
|
private let throttlingContext = FetchVideoLibraryMediaResourceContext()
|
||||||
|
|
||||||
public func fetchVideoLibraryMediaResource(account: Account, resource: VideoLibraryMediaResource) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> {
|
public func fetchVideoLibraryMediaResource(account: Account, resource: VideoLibraryMediaResource) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> {
|
||||||
return account.postbox.preferencesView(keys: [PreferencesKeys.appConfiguration])
|
|
||||||
|> take(1)
|
|
||||||
|> map { view in
|
|
||||||
return view.values[PreferencesKeys.appConfiguration]?.get(AppConfiguration.self) ?? .defaultValue
|
|
||||||
}
|
|
||||||
|> castError(MediaResourceDataFetchError.self)
|
|
||||||
|> mapToSignal { appConfiguration -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> in
|
|
||||||
let signal = Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> { subscriber in
|
let signal = Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> { subscriber in
|
||||||
subscriber.putNext(.reset)
|
subscriber.putNext(.reset)
|
||||||
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [resource.localIdentifier], options: nil)
|
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [resource.localIdentifier], options: nil)
|
||||||
@@ -319,17 +312,9 @@ public func fetchVideoLibraryMediaResource(account: Account, resource: VideoLibr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return throttlingContext.wrap(priority: .default, signal: signal)
|
return throttlingContext.wrap(priority: .default, signal: signal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchLocalFileVideoMediaResource(account: Account, resource: LocalFileVideoMediaResource) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> {
|
func fetchLocalFileVideoMediaResource(account: Account, resource: LocalFileVideoMediaResource) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> {
|
||||||
return account.postbox.preferencesView(keys: [PreferencesKeys.appConfiguration])
|
|
||||||
|> take(1)
|
|
||||||
|> map { view in
|
|
||||||
return view.values[PreferencesKeys.appConfiguration]?.get(AppConfiguration.self) ?? .defaultValue
|
|
||||||
}
|
|
||||||
|> castError(MediaResourceDataFetchError.self)
|
|
||||||
|> mapToSignal { appConfiguration -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> in
|
|
||||||
let signal = Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> { subscriber in
|
let signal = Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError> { subscriber in
|
||||||
subscriber.putNext(.reset)
|
subscriber.putNext(.reset)
|
||||||
|
|
||||||
@@ -452,7 +437,6 @@ func fetchLocalFileVideoMediaResource(account: Account, resource: LocalFileVideo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return throttlingContext.wrap(priority: .default, signal: signal)
|
return throttlingContext.wrap(priority: .default, signal: signal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func fetchVideoLibraryMediaResourceHash(resource: VideoLibraryMediaResource) -> Signal<Data?, NoError> {
|
public func fetchVideoLibraryMediaResourceHash(resource: VideoLibraryMediaResource) -> Signal<Data?, NoError> {
|
||||||
|
|||||||
Reference in New Issue
Block a user