Scale images always on a background queue. Fix #642.
This commit is contained in:
parent
fb79309f95
commit
f5f8d67411
|
@ -101,7 +101,6 @@
|
|||
51C4529E22650A1900C03939 /* ImageDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845213221FCA5B10003B6E93 /* ImageDownloader.swift */; };
|
||||
51C4529F22650A1900C03939 /* AuthorAvatarDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E850851FCB60CE0072EA88 /* AuthorAvatarDownloader.swift */; };
|
||||
51C452A022650A1900C03939 /* FeedIconDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842611891FCB67AA0086A189 /* FeedIconDownloader.swift */; };
|
||||
51C452A122650A1900C03939 /* FeaturedImageDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8426119F1FCB72600086A189 /* FeaturedImageDownloader.swift */; };
|
||||
51C452A222650A1900C03939 /* RSHTMLMetadata+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842611A11FCB769D0086A189 /* RSHTMLMetadata+Extension.swift */; };
|
||||
51C452A322650A1E00C03939 /* HTMLMetadataDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8426119D1FCB6ED40086A189 /* HTMLMetadataDownloader.swift */; };
|
||||
51C452A422650A2D00C03939 /* ArticleUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97581ED9EB0D007D329B /* ArticleUtilities.swift */; };
|
||||
|
@ -159,7 +158,6 @@
|
|||
84216D0322128B9D0049B9B9 /* DetailWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84216D0222128B9D0049B9B9 /* DetailWebViewController.swift */; };
|
||||
8426118A1FCB67AA0086A189 /* FeedIconDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842611891FCB67AA0086A189 /* FeedIconDownloader.swift */; };
|
||||
8426119E1FCB6ED40086A189 /* HTMLMetadataDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8426119D1FCB6ED40086A189 /* HTMLMetadataDownloader.swift */; };
|
||||
842611A01FCB72600086A189 /* FeaturedImageDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8426119F1FCB72600086A189 /* FeaturedImageDownloader.swift */; };
|
||||
842611A21FCB769D0086A189 /* RSHTMLMetadata+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842611A11FCB769D0086A189 /* RSHTMLMetadata+Extension.swift */; };
|
||||
842E45CE1ED8C308000A8B52 /* AppNotifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842E45CD1ED8C308000A8B52 /* AppNotifications.swift */; };
|
||||
842E45DD1ED8C54B000A8B52 /* Browser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842E45DC1ED8C54B000A8B52 /* Browser.swift */; };
|
||||
|
@ -1921,12 +1919,12 @@
|
|||
ORGANIZATIONNAME = "Ranchero Software";
|
||||
TargetAttributes = {
|
||||
6581C73220CED60000F4AD34 = {
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
DevelopmentTeam = M8L2WTLA8W;
|
||||
ProvisioningStyle = Manual;
|
||||
};
|
||||
840D617B2029031C009BC708 = {
|
||||
CreatedOnToolsVersion = 9.3;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
DevelopmentTeam = M8L2WTLA8W;
|
||||
ProvisioningStyle = Automatic;
|
||||
SystemCapabilities = {
|
||||
com.apple.BackgroundModes = {
|
||||
|
@ -1942,7 +1940,7 @@
|
|||
};
|
||||
849C645F1ED37A5D003D8FC0 = {
|
||||
CreatedOnToolsVersion = 8.2.1;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
DevelopmentTeam = M8L2WTLA8W;
|
||||
ProvisioningStyle = Manual;
|
||||
SystemCapabilities = {
|
||||
com.apple.HardenedRuntime = {
|
||||
|
@ -1952,7 +1950,7 @@
|
|||
};
|
||||
849C64701ED37A5D003D8FC0 = {
|
||||
CreatedOnToolsVersion = 8.2.1;
|
||||
DevelopmentTeam = SHJK2V3AJG;
|
||||
DevelopmentTeam = 9C84TZ7Q6Z;
|
||||
ProvisioningStyle = Automatic;
|
||||
TestTargetID = 849C645F1ED37A5D003D8FC0;
|
||||
};
|
||||
|
@ -2308,7 +2306,6 @@
|
|||
5183CCDD226F1F5C0010922C /* NavigationProgressView.swift in Sources */,
|
||||
51C452772265091600C03939 /* MultilineUILabelSizer.swift in Sources */,
|
||||
51C452A522650A2D00C03939 /* SmallIconProvider.swift in Sources */,
|
||||
51C452A122650A1900C03939 /* FeaturedImageDownloader.swift in Sources */,
|
||||
51D5948722668EFA00DFC836 /* MarkStatusCommand.swift in Sources */,
|
||||
51C4525C226508DF00C03939 /* String-Extensions.swift in Sources */,
|
||||
51C452792265091600C03939 /* MasterTimelineTableViewCell.swift in Sources */,
|
||||
|
@ -2473,7 +2470,6 @@
|
|||
D5E4CC54202C1361009B4FFC /* AppDelegate+Scriptability.swift in Sources */,
|
||||
D5F4EDB5200744A700B9E363 /* ScriptingObject.swift in Sources */,
|
||||
D5F4EDB920074D7C00B9E363 /* Folder+Scriptability.swift in Sources */,
|
||||
842611A01FCB72600086A189 /* FeaturedImageDownloader.swift in Sources */,
|
||||
849A97781ED9EC04007D329B /* TimelineCellLayout.swift in Sources */,
|
||||
84E8E0EB202F693600562D8F /* DetailWebView.swift in Sources */,
|
||||
849A976C1ED9EBC8007D329B /* TimelineTableRowView.swift in Sources */,
|
||||
|
|
|
@ -21,9 +21,11 @@ extension RSImage {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension RSImage {
|
||||
|
||||
static func scaledForAvatar(_ data: Data) -> RSImage? {
|
||||
|
||||
let scaledMaxPixelSize = Int(ceil(CGFloat(RSImage.avatarSize) * RSScreen.mainScreenScale))
|
||||
guard let cgImage = RSImage.scaleImage(data, maxPixelSize: scaledMaxPixelSize) else {
|
||||
return nil
|
||||
|
|
|
@ -38,11 +38,9 @@ final class AuthorAvatarDownloader {
|
|||
}
|
||||
|
||||
if let imageData = imageDownloader.image(for: avatarURL) {
|
||||
if let image = RSImage.scaledForAvatar(imageData) {
|
||||
handleImageDidBecomeAvailable(avatarURL, image)
|
||||
return image
|
||||
}
|
||||
} else {
|
||||
scaleAndCacheImageData(imageData, avatarURL)
|
||||
}
|
||||
else {
|
||||
waitingForAvatarURLs.insert(avatarURL)
|
||||
}
|
||||
|
||||
|
@ -50,29 +48,30 @@ final class AuthorAvatarDownloader {
|
|||
}
|
||||
|
||||
@objc func imageDidBecomeAvailable(_ note: Notification) {
|
||||
|
||||
guard let avatarURL = note.userInfo?[UserInfoKey.url] as? String else {
|
||||
return
|
||||
}
|
||||
|
||||
guard waitingForAvatarURLs.contains(avatarURL) else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let imageData = imageDownloader.image(for: avatarURL),
|
||||
let image = RSImage.scaledForAvatar(imageData) else {
|
||||
guard let imageData = imageDownloader.image(for: avatarURL) else {
|
||||
return
|
||||
}
|
||||
|
||||
handleImageDidBecomeAvailable(avatarURL, image)
|
||||
|
||||
scaleAndCacheImageData(imageData, avatarURL)
|
||||
}
|
||||
}
|
||||
|
||||
private extension AuthorAvatarDownloader {
|
||||
|
||||
func handleImageDidBecomeAvailable(_ avatarURL: String, _ image: RSImage) {
|
||||
func scaleAndCacheImageData(_ imageData: Data, _ avatarURL: String) {
|
||||
RSImage.scaledForAvatar(imageData) { (image) in
|
||||
if let image = image {
|
||||
self.handleImageDidBecomeAvailable(avatarURL, image)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleImageDidBecomeAvailable(_ avatarURL: String, _ image: RSImage) {
|
||||
if cache[avatarURL] == nil {
|
||||
cache[avatarURL] = image
|
||||
}
|
||||
|
@ -83,7 +82,6 @@ private extension AuthorAvatarDownloader {
|
|||
}
|
||||
|
||||
func postAvatarDidBecomeAvailableNotification(_ avatarURL: String) {
|
||||
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(name: .AvatarDidBecomeAvailable, object: self, userInfo: [UserInfoKey.url: avatarURL])
|
||||
}
|
||||
|
|
|
@ -38,18 +38,26 @@ public final class FeedIconDownloader {
|
|||
}
|
||||
|
||||
if let iconURL = feed.iconURL {
|
||||
if let image = icon(forURL: iconURL) {
|
||||
postFeedIconDidBecomeAvailableNotification(feed)
|
||||
cache[feed] = image
|
||||
return image
|
||||
icon(forURL: iconURL) { (image) in
|
||||
if let image = image {
|
||||
self.postFeedIconDidBecomeAvailableNotification(feed)
|
||||
self.cache[feed] = image
|
||||
}
|
||||
else {
|
||||
checkHomePageURL()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let homePageURL = feed.homePageURL {
|
||||
if let image = icon(forHomePageURL: homePageURL) {
|
||||
postFeedIconDidBecomeAvailableNotification(feed)
|
||||
cache[feed] = image
|
||||
return image
|
||||
func checkHomePageURL() {
|
||||
guard let homePageURL = feed.homePageURL else {
|
||||
return
|
||||
}
|
||||
icon(forHomePageURL: homePageURL) { (image) in
|
||||
if let image = image {
|
||||
self.postFeedIconDidBecomeAvailableNotification(feed)
|
||||
self.cache[feed] = image
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,25 +67,27 @@ public final class FeedIconDownloader {
|
|||
|
||||
private extension FeedIconDownloader {
|
||||
|
||||
func icon(forHomePageURL homePageURL: String) -> RSImage? {
|
||||
func icon(forHomePageURL homePageURL: String, _ imageResultBlock: @escaping (RSImage?) -> Void) {
|
||||
|
||||
if homePagesWithNoIconURL.contains(homePageURL) {
|
||||
return nil
|
||||
imageResultBlock(nil)
|
||||
return
|
||||
}
|
||||
|
||||
if let iconURL = cachedIconURL(for: homePageURL) {
|
||||
return icon(forURL: iconURL)
|
||||
icon(forURL: iconURL, imageResultBlock)
|
||||
return
|
||||
}
|
||||
|
||||
findIconURLForHomePageURL(homePageURL)
|
||||
return nil
|
||||
}
|
||||
|
||||
func icon(forURL url: String) -> RSImage? {
|
||||
if let imageData = imageDownloader.image(for: url), let image = RSImage.scaledForAvatar(imageData) {
|
||||
return image
|
||||
func icon(forURL url: String, _ imageResultBlock: @escaping (RSImage?) -> Void) {
|
||||
guard let imageData = imageDownloader.image(for: url) else {
|
||||
imageResultBlock(nil)
|
||||
return
|
||||
}
|
||||
return nil
|
||||
RSImage.scaledForAvatar(imageData, imageResultBlock: imageResultBlock)
|
||||
}
|
||||
|
||||
func postFeedIconDidBecomeAvailableNotification(_ feed: Feed) {
|
||||
|
@ -120,7 +130,8 @@ private extension FeedIconDownloader {
|
|||
|
||||
if let url = metadata.bestWebsiteIconURL() {
|
||||
cacheIconURL(for: homePageURL, url)
|
||||
let _ = icon(forURL: url)
|
||||
icon(forURL: url) { (image) in
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue