diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 438a0725..49955cd9 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -195,6 +195,7 @@ 50894D0C1AEE0177000981AF /* EditProfileColoredTitleCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50894D0A1AEE0177000981AF /* EditProfileColoredTitleCell.swift */; }; 50894D0D1AEE0177000981AF /* EditProfileColoredTitleCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50894D0B1AEE0177000981AF /* EditProfileColoredTitleCell.xib */; }; 50894D101AEE3C25000981AF /* YepHUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50894D0F1AEE3C25000981AF /* YepHUD.swift */; }; + 508A084E1C166EBA000A3305 /* CLPlacemark+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A084D1C166EBA000A3305 /* CLPlacemark+Yep.swift */; }; 508B717D1B1FE9B6006BDDB3 /* ChatRightBaseCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508B717C1B1FE9B6006BDDB3 /* ChatRightBaseCell.swift */; }; 508C2AA41AD661B3002B8097 /* UserStateCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508C2AA21AD661B3002B8097 /* UserStateCell.swift */; }; 508C2AA51AD661B3002B8097 /* UserStateCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 508C2AA31AD661B3002B8097 /* UserStateCell.xib */; }; @@ -549,6 +550,7 @@ 50894D0A1AEE0177000981AF /* EditProfileColoredTitleCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EditProfileColoredTitleCell.swift; path = Views/Cells/EditProfileColoredTitle/EditProfileColoredTitleCell.swift; sourceTree = ""; }; 50894D0B1AEE0177000981AF /* EditProfileColoredTitleCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = EditProfileColoredTitleCell.xib; path = Views/Cells/EditProfileColoredTitle/EditProfileColoredTitleCell.xib; sourceTree = ""; }; 50894D0F1AEE3C25000981AF /* YepHUD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepHUD.swift; path = Helpers/YepHUD.swift; sourceTree = ""; }; + 508A084D1C166EBA000A3305 /* CLPlacemark+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "CLPlacemark+Yep.swift"; path = "Extensions/CLPlacemark+Yep.swift"; sourceTree = ""; }; 508B717C1B1FE9B6006BDDB3 /* ChatRightBaseCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatRightBaseCell.swift; path = Views/Cells/ChatRightBase/ChatRightBaseCell.swift; sourceTree = ""; }; 508C2AA21AD661B3002B8097 /* UserStateCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UserStateCell.swift; path = Views/Cells/UserState/UserStateCell.swift; sourceTree = ""; }; 508C2AA31AD661B3002B8097 /* UserStateCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = UserStateCell.xib; path = Views/Cells/UserState/UserStateCell.xib; sourceTree = ""; }; @@ -1131,6 +1133,7 @@ 50DEE03C1BE70E1500015741 /* UIScrollView+Yep.swift */, 500EED951BF06AC900C6BABC /* NSURL+Yep.swift */, 502C24821C1034000074A1BA /* UIImageView+Yep.swift */, + 508A084D1C166EBA000A3305 /* CLPlacemark+Yep.swift */, ); name = Extensions; sourceTree = ""; @@ -2623,6 +2626,7 @@ 50894CFA1AEA54BA000981AF /* SettingsMoreCell.swift in Sources */, 50AFBF4B1BB2A44C007D19DA /* InfoView.swift in Sources */, 50DEE03D1BE70E1500015741 /* UIScrollView+Yep.swift in Sources */, + 508A084E1C166EBA000A3305 /* CLPlacemark+Yep.swift in Sources */, 50535D281BCE4A71002FE1A4 /* PhotoCell.swift in Sources */, 508F8FCC1B01C7FC00461B0B /* SocialWorkGithubViewController.swift in Sources */, 503ED23A1B8ADCE70072187D /* BlackListViewController.swift in Sources */, diff --git a/Yep/Extensions/CLPlacemark+Yep.swift b/Yep/Extensions/CLPlacemark+Yep.swift new file mode 100644 index 00000000..a683e1e5 --- /dev/null +++ b/Yep/Extensions/CLPlacemark+Yep.swift @@ -0,0 +1,26 @@ +// +// CLPlacemark+Yep.swift +// Yep +// +// Created by nixzhu on 15/12/8. +// Copyright © 2015年 Catch Inc. All rights reserved. +// + +import CoreLocation + +extension CLPlacemark { + + var yep_autoName: String? { + + if let a = areasOfInterest?.first { + return a + } + + if let locality = locality, thoroughfare = thoroughfare { + return locality + NSLocalizedString(", ", comment: "") + thoroughfare + } + + return name ?? administrativeArea + } +} + diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index f2f97989..90c4a01a 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -300,6 +300,7 @@ class FeedsViewController: BaseViewController { if let realm = try? Realm(), offlineJSON = OfflineJSON.withName(.Feeds, inRealm: realm) { if let JSON = offlineJSON.JSON, feeds = parseFeeds(JSON) { self.feeds = feeds + activityIndicator.stopAnimating() } } } @@ -399,7 +400,7 @@ class FeedsViewController: BaseViewController { isFetchingFeeds = true - if !isLoadMore { + if !isLoadMore && feeds.isEmpty { activityIndicator.startAnimating() } diff --git a/Yep/ViewControllers/MediaPreview/MediaPreviewViewController.swift b/Yep/ViewControllers/MediaPreview/MediaPreviewViewController.swift index 680b3475..27470333 100644 --- a/Yep/ViewControllers/MediaPreview/MediaPreviewViewController.swift +++ b/Yep/ViewControllers/MediaPreview/MediaPreviewViewController.swift @@ -48,6 +48,25 @@ class MediaPreviewViewController: UIViewController { } } + private struct AttachmentImagePool { + var imagesDic = [String: UIImage]() + + mutating func addImage(image: UIImage, forKey key: String) { + guard !key.isEmpty else { + return + } + + if imagesDic[key] == nil { + imagesDic[key] = image + } + } + + func imageWithKey(key: String) -> UIImage? { + return imagesDic[key] + } + } + private var attachmentImagePool = AttachmentImagePool() + var currentPlayer: AVPlayer? @IBOutlet weak var mediasCollectionView: UICollectionView! @@ -174,6 +193,8 @@ class MediaPreviewViewController: UIViewController { view.addGestureRecognizer(swipeDown) currentIndex = startIndex + + prepareInAdvance() } var isFirstLayoutSubviews = true @@ -205,6 +226,23 @@ class MediaPreviewViewController: UIViewController { isFirstLayoutSubviews = false } + // MARK: Private + + private func prepareInAdvance() { + + for previewMedia in previewMedias { + + if case let .AttachmentType(attachment) = previewMedia { + + ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: nil, completion: { [weak self] (url, image, _) in + if let image = image { + self?.attachmentImagePool.addImage(image, forKey: attachment.URLString) + } + }) + } + } + } + // MARK: Actions func dismiss() { @@ -383,12 +421,21 @@ extension MediaPreviewViewController: UICollectionViewDataSource, UICollectionVi mediaControlView.type = .Image - ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: nil, completion: { (url, image, _) in - guard url.absoluteString == attachment.URLString else { - return - } + if let image = attachmentImagePool.imageWithKey(attachment.URLString) { cell.mediaView.image = image - }) + + } else { + ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: nil, completion: { [weak self] (url, image, _) in + guard url.absoluteString == attachment.URLString else { + return + } + cell.mediaView.image = image + + if let image = image { + self?.attachmentImagePool.addImage(image, forKey: attachment.URLString) + } + }) + } case .WebImage(let imageURL, _): @@ -408,10 +455,6 @@ extension MediaPreviewViewController: UICollectionViewDataSource, UICollectionVi func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier(mediaViewCellID, forIndexPath: indexPath) as! MediaViewCell - -// let previewMedia = previewMedias[indexPath.item] -// configureCell(cell, withPreviewMedia: previewMedia) - return cell } diff --git a/Yep/ViewControllers/PickLocation/PickLocationViewController.swift b/Yep/ViewControllers/PickLocation/PickLocationViewController.swift index 060e0345..cd041046 100644 --- a/Yep/ViewControllers/PickLocation/PickLocationViewController.swift +++ b/Yep/ViewControllers/PickLocation/PickLocationViewController.swift @@ -53,7 +53,7 @@ class PickLocationViewController: UIViewController { if let location = self.location { if case .Default = location { var info = location.info - info.name = placemark.name + info.name = placemark.yep_autoName self.location = .Default(info: info) } } @@ -69,7 +69,7 @@ class PickLocationViewController: UIViewController { if let location = self.location { if case .Picked = location { var info = location.info - info.name = placemark.name + info.name = placemark.yep_autoName self.location = .Picked(info: info) } } @@ -250,7 +250,7 @@ class PickLocationViewController: UIViewController { return } - let _location = Location.Default(info: Location.Info(coordinate: location.coordinate, name: userLocationPlacemarks.first?.name)) + let _location = Location.Default(info: Location.Info(coordinate: location.coordinate, name: userLocationPlacemarks.first?.yep_autoName)) performSegueWithIdentifier("showNewFeed", sender: Box(_location)) } @@ -569,12 +569,12 @@ extension PickLocationViewController: UITableViewDataSource, UITableViewDelegate case Section.CurrentLocation.rawValue: if let _location = mapView.userLocation.location { - location = .Selected(info: Location.Info(coordinate: _location.coordinate, name: userLocationPlacemarks.first?.name ?? NSLocalizedString("My Current Location", comment: ""))) + location = .Selected(info: Location.Info(coordinate: _location.coordinate, name: userLocationPlacemarks.first?.yep_autoName ?? NSLocalizedString("My Current Location", comment: ""))) } case Section.UserPickedLocation.rawValue: if let coordinate = locationPin?.coordinate { - location = .Picked(info: Location.Info(coordinate: coordinate, name: pickedLocationPlacemarks.first?.name ?? NSLocalizedString("Picked Location", comment: ""))) + location = .Picked(info: Location.Info(coordinate: coordinate, name: pickedLocationPlacemarks.first?.yep_autoName ?? NSLocalizedString("Picked Location", comment: ""))) } case Section.UserLocationPlacemarks.rawValue: diff --git a/Yep/zh-Hans.lproj/Localizable.strings b/Yep/zh-Hans.lproj/Localizable.strings index 08f9590b..c867a80d 100644 --- a/Yep/zh-Hans.lproj/Localizable.strings +++ b/Yep/zh-Hans.lproj/Localizable.strings @@ -708,3 +708,4 @@ "Subscribe" = "订阅"; +", " = ",";