mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-13 14:56:03 +10:00
Merge branch 'develop' of https://github.com/CatchChat/Yep into develop
This commit is contained in:
@@ -20,7 +20,7 @@ class ImageCache {
|
||||
let cacheAttachmentQueue = dispatch_queue_create("ImageCacheAttachmentQueue", DISPATCH_QUEUE_SERIAL)
|
||||
// let cacheQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)
|
||||
|
||||
func imageOfAttachment(attachment: DiscoveredAttachment, withSize: CGSize?, completion: (url: NSURL, image: UIImage?) -> Void) {
|
||||
func imageOfAttachment(attachment: DiscoveredAttachment, withSize: CGSize?, completion: (url: NSURL, image: UIImage?, cacheType: CacheType) -> Void) {
|
||||
|
||||
guard let attachmentURL = NSURL(string: attachment.URLString) else {
|
||||
return
|
||||
@@ -40,15 +40,15 @@ class ImageCache {
|
||||
let attachmentOriginKey = "attachment-0.0-0.0-\(attachmentURL.absoluteString)"
|
||||
|
||||
let attachmentSizeKey = "attachment-\(cacheSize.width)-\(cacheSize.height)-\(attachmentURL.absoluteString)"
|
||||
|
||||
|
||||
let OptionsInfos: KingfisherManager.Options = (forceRefresh: false, lowPriority: false, cacheMemoryOnly: false, shouldDecode: false, queue: cacheAttachmentQueue, scale: UIScreen.mainScreen().scale)
|
||||
//查找当前 Size 的 Cache
|
||||
|
||||
Kingfisher.ImageCache.defaultCache.retrieveImageForKey(attachmentSizeKey, options: OptionsInfos) { (image, type) -> () in
|
||||
|
||||
|
||||
if let image = image?.decodedImage() {
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
completion(url: attachmentURL, image: image)
|
||||
completion(url: attachmentURL, image: image, cacheType: type)
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -72,7 +72,7 @@ class ImageCache {
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
completion(url: attachmentURL, image: finalImage)
|
||||
completion(url: attachmentURL, image: finalImage, cacheType: type)
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -100,12 +100,12 @@ class ImageCache {
|
||||
println("Image Decode size \(storeImage.size)")
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
completion(url: attachmentURL, image: finalImage)
|
||||
completion(url: attachmentURL, image: finalImage, cacheType: .None)
|
||||
}
|
||||
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
completion(url: attachmentURL, image: nil)
|
||||
completion(url: attachmentURL, image: nil, cacheType: .None)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -30,15 +30,22 @@ extension UIImageView {
|
||||
|
||||
yep_setAttachmentURL(attachmentURL)
|
||||
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: size, completion: { [weak self] (url, image) in
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: size, completion: { [weak self] (url, image, cacheType) in
|
||||
|
||||
guard let strongSelf = self, yep_attachmentURL = strongSelf.yep_attachmentURL where yep_attachmentURL == url else {
|
||||
return
|
||||
}
|
||||
|
||||
UIView.transitionWithView(strongSelf, duration: imageFadeTransitionDuration, options: .TransitionCrossDissolve, animations: { () -> Void in
|
||||
if cacheType != .Memory {
|
||||
UIView.transitionWithView(strongSelf, duration: imageFadeTransitionDuration, options: .TransitionCrossDissolve, animations: { () -> Void in
|
||||
strongSelf.image = image
|
||||
}, completion: nil)
|
||||
|
||||
} else {
|
||||
strongSelf.image = image
|
||||
}, completion: nil)
|
||||
}
|
||||
|
||||
println("imageOfAttachment cacheType: \(cacheType)")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2860,13 +2860,16 @@ func discoverFeedsWithSortStyle(sortStyle: FeedSortStyle, skill: Skill?, pageInd
|
||||
//let parse = parseFeeds
|
||||
let parse: JSONDictionary -> [DiscoveredFeed]? = { data in
|
||||
|
||||
if let realm = try? Realm() {
|
||||
if let offlineData = try? NSJSONSerialization.dataWithJSONObject(data, options: []) {
|
||||
// 只离线第一页
|
||||
if pageIndex == 1 {
|
||||
if let realm = try? Realm() {
|
||||
if let offlineData = try? NSJSONSerialization.dataWithJSONObject(data, options: []) {
|
||||
|
||||
let offlineJSON = OfflineJSON(name: OfflineJSONName.Feeds.rawValue, data: offlineData)
|
||||
let offlineJSON = OfflineJSON(name: OfflineJSONName.Feeds.rawValue, data: offlineData)
|
||||
|
||||
let _ = try? realm.write {
|
||||
realm.add(offlineJSON, update: true)
|
||||
let _ = try? realm.write {
|
||||
realm.add(offlineJSON, update: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ class FeedsViewController: BaseViewController {
|
||||
filterBarItem?.title = feedSortStyle.nameWithArrow
|
||||
|
||||
updateFeeds()
|
||||
|
||||
|
||||
YepUserDefaults.feedSortStyle.value = feedSortStyle.rawValue
|
||||
}
|
||||
}
|
||||
@@ -287,6 +287,7 @@ class FeedsViewController: BaseViewController {
|
||||
|
||||
// 没有 profileUser 才设置 feedSortStyle 以请求服务器
|
||||
if profileUser == nil {
|
||||
|
||||
if let
|
||||
value = YepUserDefaults.feedSortStyle.value,
|
||||
_feedSortStyle = FeedSortStyle(rawValue: value) {
|
||||
@@ -438,16 +439,47 @@ class FeedsViewController: BaseViewController {
|
||||
|
||||
if let strongSelf = self {
|
||||
|
||||
let newFeeds = feeds
|
||||
let oldFeeds = strongSelf.feeds
|
||||
|
||||
var needReloadData = false
|
||||
|
||||
needReloadData = strongSelf.feeds.isEmpty
|
||||
|
||||
if isLoadMore {
|
||||
strongSelf.feeds += feeds
|
||||
|
||||
needReloadData = true
|
||||
|
||||
} else {
|
||||
strongSelf.feeds = feeds
|
||||
}
|
||||
|
||||
// 确保有新的才 reload
|
||||
if !feeds.isEmpty {
|
||||
strongSelf.feedsTableView.reloadData() // 服务端有新的排序算法,以及避免刷新后消息数字更新不及时的问题
|
||||
if !needReloadData && !newFeeds.isEmpty {
|
||||
|
||||
if newFeeds.count == oldFeeds.count {
|
||||
|
||||
var index = 0
|
||||
while index < newFeeds.count {
|
||||
let newFeed = newFeeds[index]
|
||||
let oldFeed = oldFeeds[index]
|
||||
|
||||
if newFeed.id != oldFeed.id {
|
||||
needReloadData = true
|
||||
break
|
||||
}
|
||||
|
||||
index += 1
|
||||
}
|
||||
|
||||
} else {
|
||||
needReloadData = true
|
||||
}
|
||||
}
|
||||
|
||||
if needReloadData {
|
||||
println("new feeds, reloadData")
|
||||
strongSelf.feedsTableView.reloadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ extension MediaPreviewViewController: UICollectionViewDataSource, UICollectionVi
|
||||
|
||||
mediaControlView.type = .Image
|
||||
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: nil, completion: { (url, image) in
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: nil, completion: { (url, image, _) in
|
||||
guard url.absoluteString == attachment.URLString else {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ extension MessageMediaViewController: UICollectionViewDataSource, UICollectionVi
|
||||
|
||||
mediaControlView.type = .Image
|
||||
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: nil, completion: { (url, image) in
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: nil, completion: { (url, image, _) in
|
||||
guard url.absoluteString == attachment.URLString else {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -340,6 +340,7 @@ class FeedSocialWorkCell: FeedBasicCell {
|
||||
locationMapImageView.maskView = socialWorkMaskImageView
|
||||
|
||||
socialWorkContainerViewHeightConstraint.constant = 110
|
||||
contentView.layoutIfNeeded()
|
||||
|
||||
default:
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user