Merge branch 'develop' of https://github.com/CatchChat/Yep into develop

This commit is contained in:
kevinzhow
2015-12-07 19:25:22 +08:00
7 changed files with 64 additions and 21 deletions
+7 -7
View File
@@ -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)
}
}
})
+10 -3
View File
@@ -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)")
})
}
+8 -5
View File
@@ -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