diff --git a/Podfile b/Podfile index 357a4d8..730d1cb 100644 --- a/Podfile +++ b/Podfile @@ -12,6 +12,7 @@ target 'librx' do pod 'SDWebImage', '~>3.7' pod 'WeiboSDK', :git => 'https://github.com/sinaweibosdk/weibo_ios_sdk.git', :tag => '3.1.3' pod 'SwiftColors' + pod 'HanekeSwift' # pod 'WebViewJavascriptBridge', '~> 4.0.1' # pod 'Toast', '~> 2.4’ end diff --git a/Podfile.lock b/Podfile.lock index 3e234ab..4304978 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -2,6 +2,7 @@ PODS: - Alamofire (2.0.2) - Appirater (2.0.5) - CryptoSwift (0.0.14) + - HanekeSwift (0.10.0) - JSONWebToken (1.4.1): - CryptoSwift (= 0.0.14) - RESideMenu (4.0.7) @@ -16,6 +17,7 @@ PODS: DEPENDENCIES: - Alamofire (~> 2.0) - Appirater + - HanekeSwift - JSONWebToken (~> 1.4.0) - RESideMenu (~> 4.0.7) - SDWebImage (~> 3.7) @@ -44,6 +46,7 @@ SPEC CHECKSUMS: Alamofire: 8edbab00802a752bb5240cc2abe70e7e881488ad Appirater: e7c0a47fb67ee5041ce8479e6ba960927fb40264 CryptoSwift: 5a6b725e2ad65a789f5f435dd434d38eb2c40b46 + HanekeSwift: d6f5bdf9dbdbbc09d59623b2c1d533e46463dd4d JSONWebToken: cf8b58850dc4cf38ce777a08753a2ea1620d960e RESideMenu: f24c508404b49c667344c54aba7e590883533958 SDWebImage: 1d2b1a1efda1ade1b00b6f8498865f8ddedc8a84 diff --git a/librx.xcodeproj/project.pbxproj b/librx.xcodeproj/project.pbxproj index 1b607f5..309a65e 100644 --- a/librx.xcodeproj/project.pbxproj +++ b/librx.xcodeproj/project.pbxproj @@ -58,6 +58,7 @@ 456F1A171B6FD3D6007F9ACF /* MenuTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 456F1A161B6FD3D6007F9ACF /* MenuTableViewController.swift */; }; 456F1A1E1B6FD4D0007F9ACF /* MenuTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 456F1A1D1B6FD4D0007F9ACF /* MenuTableViewCell.swift */; }; 457BF0E11B9C905B00A491D6 /* ExploreCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 457BF0E01B9C905B00A491D6 /* ExploreCollectionReusableView.swift */; }; + 4599CCE11BFCAC7E00F263BC /* PostsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4599CCE01BFCAC7E00F263BC /* PostsStore.swift */; }; 45A50FC01BC96608009897FF /* Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45A50FBF1BC96608009897FF /* Profile.swift */; }; 45AD0E2E1B857EA600283FCC /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45AD0E2D1B857EA600283FCC /* WebViewController.swift */; }; 45B11CD81B6FD12A008D6049 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 45B11CD71B6FD12A008D6049 /* Images.xcassets */; }; @@ -216,6 +217,7 @@ 456F1A161B6FD3D6007F9ACF /* MenuTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuTableViewController.swift; sourceTree = ""; }; 456F1A1D1B6FD4D0007F9ACF /* MenuTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuTableViewCell.swift; sourceTree = ""; }; 457BF0E01B9C905B00A491D6 /* ExploreCollectionReusableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExploreCollectionReusableView.swift; sourceTree = ""; }; + 4599CCE01BFCAC7E00F263BC /* PostsStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostsStore.swift; sourceTree = ""; }; 45A50FBF1BC96608009897FF /* Profile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Profile.swift; sourceTree = ""; }; 45AD0E2D1B857EA600283FCC /* WebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = ""; }; 45B11CD71B6FD12A008D6049 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; @@ -523,6 +525,7 @@ 45CF5AD01B8DFD63001E5CFC /* LoginService.swift */, 453B01521BAADC2400E285A3 /* JsonPaser.swift */, 45CE21A41BC35D7800642186 /* DateUtil.swift */, + 4599CCE01BFCAC7E00F263BC /* PostsStore.swift */, ); name = services; sourceTree = ""; @@ -904,6 +907,7 @@ 45E713741B9F39A8002FFCBB /* ExploreCell.swift in Sources */, 45D77BB81BAD14C300618CAC /* RootViewController.swift in Sources */, 45517B141BCBE743004C6D10 /* ContainerViewController.swift in Sources */, + 4599CCE11BFCAC7E00F263BC /* PostsStore.swift in Sources */, 451281D41B6F926500C59C6B /* CustomTableCell.swift in Sources */, 45D8E7241B71E3BA00A33659 /* ProfileViewController.swift in Sources */, 453EF3A31B81AE5200ADD33D /* PostsLoader.swift in Sources */, diff --git a/librx/LibrxService.swift b/librx/LibrxService.swift index e7df276..6c6f977 100644 --- a/librx/LibrxService.swift +++ b/librx/LibrxService.swift @@ -103,7 +103,6 @@ struct LibrxService { response(explores) } - } static func postsBySection(page: Int, keyword: String? = nil, section: PostsLoader.PostSection = .Default, response: ([Post], error: String?) -> ()) { @@ -119,64 +118,61 @@ struct LibrxService { } let headers: [String:String] = buildHttpRequestHeader() - loadPostsByUrl(urlString, headers: headers, response: response) + loadPostsByUrl(urlString, headers: headers, section: section, response: response) } - static func postsForUrl(url: String, response: ([Post], error: String?) -> ()) { + static func postsForUrl(url: String, section: PostsLoader.PostSection = .Default, response: ([Post], error: String?) -> ()) { let headers: [String:String] = buildHttpRequestHeader() - loadPostsByUrl(url, headers: headers, response: response) + loadPostsByUrl(url, headers: headers, section: section, response: response) } - static func postsForUser(page: Int, userId: Int, response: ([Post], error: String?) -> ()) { + static func postsForUser(page: Int, userId: Int, section: PostsLoader.PostSection = .Default, response: ([Post], error: String?) -> ()) { let urlString = baseURL + ResourcePath.UserPosts(page: page, userId: userId).description let headers: [String:String] = buildHttpRequestHeader() - loadPostsByUrl(urlString, headers: headers, response: response) + loadPostsByUrl(urlString, headers: headers, section: section, response: response) } - static func postsForUserBookMark(page: Int, userId: Int, response: ([Post], error: String?) -> ()) { + static func postsForUserBookMark(page: Int, userId: Int, section: PostsLoader.PostSection = .Default, response: ([Post], error: String?) -> ()) { let urlString = baseURL + ResourcePath.UserBookMarkPosts(page: page, userId: userId).description let headers: [String:String] = buildHttpRequestHeader() - loadPostsByUrl(urlString, headers: headers, response: response) + loadPostsByUrl(urlString, headers: headers, section: section, response: response) } - static func postsForUserLiked(page: Int, userId: Int, response: ([Post], error: String?) -> ()) { - + static func postsForUserLiked(page: Int, userId: Int, section: PostsLoader.PostSection = .Default, response: ([Post], error: String?) -> ()) { + let urlString = baseURL + ResourcePath.UserLikedPosts(page: page, userId: userId).description - print(urlString) let headers: [String:String] = buildHttpRequestHeader() - loadPostsByUrl(urlString, headers: headers, response: response) + loadPostsByUrl(urlString, headers: headers, section: section, response: response) } - static func postsForMyPosts(page: Int=1, response: ([Post], error: String?) -> ()) { + static func postsForMyPosts(page: Int=1, section: PostsLoader.PostSection = .Default, response: ([Post], error: String?) -> ()) { if let _ = LocalStore.accessToken() { let urlString = baseURL + ResourcePath.Posts(page: page).description let headers: [String:String] = buildHttpRequestHeader() - loadPostsByUrl(urlString, headers: headers, response: response) + loadPostsByUrl(urlString, headers: headers, section: section, response: response) } } - - static func postsForIndex(page: Int, keyword: String? = nil, response: ([Post], error: String?) -> ()){ + static func postsForIndex(page: Int, keyword: String? = nil, section: PostsLoader.PostSection = .Default, response: ([Post], error: String?) -> ()){ let urlString = baseURL + ResourcePath.Posts(page: page).description let headers: [String:String] = buildHttpRequestHeader() - - loadPostsByUrl(urlString, headers: headers, response: response) + loadPostsByUrl(urlString, headers: headers, section: section, response: response) } - static func loadPostsByUrl(urlString: String, headers:[String:String], response: ([Post], error: String?) ->()) { + static func loadPostsByUrl(urlString: String, headers:[String:String], section: PostsLoader.PostSection, response: ([Post], error: String?) ->()) { Alamofire.request(.GET, urlString, headers: headers) .response{ (request, res, data, error) in @@ -186,11 +182,9 @@ struct LibrxService { return response(posts, error: "Libr失联了,请稍候再试...") } else{ - LocalStore.setLocalCachePosts(data!) + PostsStore.setPostsCacheBySection(section, posts: data!) let json = JSON(data: data!) - print(json) - if json != nil { for index in 0.. NSData?{ + return userDefaults.objectForKey(section.cacheKey) as? NSData + } + +} diff --git a/librx/StorysTableViewController.swift b/librx/StorysTableViewController.swift index 4d27e23..a1385ea 100644 --- a/librx/StorysTableViewController.swift +++ b/librx/StorysTableViewController.swift @@ -52,7 +52,9 @@ class StorysTableViewController: UITableViewController { self.tableView.estimatedRowHeight = 100 self.tableView.rowHeight = UITableViewAutomaticDimension self.tableView.backgroundColor = UIColor(white: 0.97, alpha: 1) - + + self.posts = self.getLocalCachePosts() + self.tableView.reloadData() } @@ -60,6 +62,7 @@ class StorysTableViewController: UITableViewController { super.viewDidAppear(false) if self.refreshControl?.refreshing == false{ self.refreshControl?.beginRefreshing() + refresh() } // reload data from cache @@ -70,9 +73,7 @@ class StorysTableViewController: UITableViewController { // mark start refreshing self.refreshControl?.beginRefreshing() refresh() - } - } @@ -151,7 +152,7 @@ class StorysTableViewController: UITableViewController { var posts: [Post] = [] - if let data = LocalStore.getLocalCachePosts() { + if let data = PostsStore.getPostsCacheBySection(postSection) { let json = JSON(data: data) for index in 0..