From 842990ac65de6fd61e027c8a9cff48d30aaf3a60 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 16 Oct 2018 23:04:01 +0300 Subject: Content loading --- Juick.xcodeproj/project.pbxproj | 10 +++ Juick/Supporting Files/Juick-Prefix.pch | 1 + Juick/ViewControllers/DiscoverViewController.m | 10 ++- Juick/ViewControllers/MessagesViewController.m | 37 ++++++++---- Juick/Views/ContentLoadingCell.h | 17 ++++++ Juick/Views/ContentLoadingCell.m | 22 +++++++ Juick/Views/ContentLoadingCell.xib | 84 ++++++++++++++++++++++++++ Podfile | 1 + Podfile.lock | 6 +- 9 files changed, 172 insertions(+), 16 deletions(-) create mode 100644 Juick/Views/ContentLoadingCell.h create mode 100644 Juick/Views/ContentLoadingCell.m create mode 100644 Juick/Views/ContentLoadingCell.xib diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index 0ae0559..e695258 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -33,6 +33,8 @@ 77418CBD182FB9B6004111B7 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77418CBC182FB9B6004111B7 /* ImageIO.framework */; }; 774528C21F930C06004D110B /* Attachment.m in Sources */ = {isa = PBXBuildFile; fileRef = 774528C11F930C06004D110B /* Attachment.m */; }; 774528C51F93AC0F004D110B /* CoreDataStack.m in Sources */ = {isa = PBXBuildFile; fileRef = 774528C41F93AC0F004D110B /* CoreDataStack.m */; }; + 7761133821766A3000D350CD /* ContentLoadingCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7761133621766A3000D350CD /* ContentLoadingCell.m */; }; + 7761133921766A3000D350CD /* ContentLoadingCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7761133721766A3000D350CD /* ContentLoadingCell.xib */; }; 776C41BD1FD3EF180063B82E /* MessageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 776C41BB1FD3EF180063B82E /* MessageCell.m */; }; 776C41BE1FD3EF180063B82E /* MessageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 776C41BC1FD3EF180063B82E /* MessageCell.xib */; }; 776C41C11FD3FF6E0063B82E /* DiscoverViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 776C41C01FD3FF6E0063B82E /* DiscoverViewController.m */; }; @@ -105,6 +107,9 @@ 774528C91F93EE83004D110B /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; }; 774528CB1F93EE9F004D110B /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 774528CD1F96B39C004D110B /* Juick.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Juick.entitlements; sourceTree = ""; }; + 7761133521766A3000D350CD /* ContentLoadingCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentLoadingCell.h; sourceTree = ""; }; + 7761133621766A3000D350CD /* ContentLoadingCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ContentLoadingCell.m; sourceTree = ""; }; + 7761133721766A3000D350CD /* ContentLoadingCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ContentLoadingCell.xib; sourceTree = ""; }; 776C41BA1FD3EF180063B82E /* MessageCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MessageCell.h; sourceTree = ""; }; 776C41BB1FD3EF180063B82E /* MessageCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MessageCell.m; sourceTree = ""; }; 776C41BC1FD3EF180063B82E /* MessageCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MessageCell.xib; sourceTree = ""; }; @@ -333,6 +338,9 @@ 77B8B398207A52BD005CB20C /* MessageInputView.xib */, 77B8B39A207A5629005CB20C /* MessageInputView.h */, 77B8B39B207A5629005CB20C /* MessageInputView.m */, + 7761133521766A3000D350CD /* ContentLoadingCell.h */, + 7761133621766A3000D350CD /* ContentLoadingCell.m */, + 7761133721766A3000D350CD /* ContentLoadingCell.xib */, ); path = Views; sourceTree = ""; @@ -419,6 +427,7 @@ 77B8B399207A52BD005CB20C /* MessageInputView.xib in Resources */, 77C6ADDE1F770EB2000AEA8C /* Main.storyboard in Resources */, 773F23381F76ED5E00B5B0DF /* Splash@2x.png in Resources */, + 7761133921766A3000D350CD /* ContentLoadingCell.xib in Resources */, 776C41BE1FD3EF180063B82E /* MessageCell.xib in Resources */, 773F23371F76ED5E00B5B0DF /* Splash.png in Resources */, 773F231C1F76DD0B00B5B0DF /* SerpentineBoldItalic.ttf in Resources */, @@ -482,6 +491,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7761133821766A3000D350CD /* ContentLoadingCell.m in Sources */, 77E61A5E1FD4682B00B4E304 /* QuoteView.m in Sources */, 77317BBC181BBE8500D60005 /* AppDelegate.m in Sources */, 776C41C11FD3FF6E0063B82E /* DiscoverViewController.m in Sources */, diff --git a/Juick/Supporting Files/Juick-Prefix.pch b/Juick/Supporting Files/Juick-Prefix.pch index 0f3a8e7..2123166 100644 --- a/Juick/Supporting Files/Juick-Prefix.pch +++ b/Juick/Supporting Files/Juick-Prefix.pch @@ -27,4 +27,5 @@ #import #import #import + #import #endif diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m index 67036c6..b09e1df 100644 --- a/Juick/ViewControllers/DiscoverViewController.m +++ b/Juick/ViewControllers/DiscoverViewController.m @@ -56,9 +56,13 @@ [self performSegueWithIdentifier:@"threadViewSegue" sender:cell]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - MessageCell *cell = (MessageCell *)[super tableView:tableView cellForRowAtIndexPath:indexPath]; - cell.delegate = self; - return cell; + if (!self.dataLoading) { + MessageCell *cell = (MessageCell *)[super tableView:tableView cellForRowAtIndexPath:indexPath]; + cell.delegate = self; + return cell; + } else { + return [super tableView:tableView cellForRowAtIndexPath:indexPath]; + } } -(void)avatarClicked:(NSString *)uname { diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index 957fce5..3fa6642 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -29,6 +29,9 @@ -(void) refreshData:(BOOL)scrollToBottom { self.dataLoading = YES; + if (self.messages.count == 0) { + [self.tableView reloadData]; + } [[APIClient sharedClient] pullNextFromPath:self.path params:self.params callback:^(NSArray *next, NSError *err) { NSArray *newMsgs = next; if ([self isAtTop:self.params]) { @@ -47,16 +50,19 @@ } } } + self.dataLoading = NO; + if (self.messages.count == 0) { + [self.tableView reloadData]; + } [self.messages addObjectsFromArray:newMsgs]; NSMutableArray *indexPaths = [NSMutableArray new]; for (NSUInteger index = oldCount; index <= oldCount + [newMsgs count] - 1; index++) { [indexPaths addObject:[NSIndexPath indexPathForRow:index inSection: 0]]; } [self.tableView beginUpdates]; - [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES]; + [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:NO]; [self.tableView endUpdates]; [self.refreshControl endRefreshing]; - self.dataLoading = NO; if (scrollToBottom) { NSIndexPath *lastRow = [NSIndexPath indexPathForRow:self.messages.count - 1 inSection:0]; [self.tableView scrollToRowAtIndexPath:lastRow atScrollPosition:UITableViewScrollPositionBottom animated:NO]; @@ -75,16 +81,15 @@ - (void)viewDidLoad { - [super viewDidLoad]; - - self.dataLoading = NO; + self.dataLoading = YES; [self.view setBackgroundColor:[ColorScheme mainBackground]]; [self.tableView registerNib:[UINib nibWithNibName:@"MessageCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"messageCell"]; + [self.tableView registerNib:[UINib nibWithNibName:@"ContentLoadingCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"contentLoadingCell"]; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 500.0f; self.messages = [NSMutableArray array]; self.refreshControl = [UIRefreshControl new]; - [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; + [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; } - (void) composePressed { @@ -96,15 +101,23 @@ } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return self.messages.count; + return self.dataLoading && self.messages.count == 0 ? 4 : self.messages.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - Message *msg = [self.messages objectAtIndex:indexPath.row]; - NSString * cellIdentifier = @"messageCell"; - MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; - [cell configureWithMessage:msg]; - return cell; + if (self.dataLoading && self.messages.count == 0) { + return [tableView dequeueReusableCellWithIdentifier:@"contentLoadingCell"]; + } else { + Message *msg = [self.messages objectAtIndex:indexPath.row]; + NSString * cellIdentifier = @"messageCell"; + MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; + [cell configureWithMessage:msg]; + return cell; + } +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + return self.dataLoading && self.messages.count == 0 ? 200.0f : [super tableView:tableView heightForRowAtIndexPath:indexPath]; } -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView_ { diff --git a/Juick/Views/ContentLoadingCell.h b/Juick/Views/ContentLoadingCell.h new file mode 100644 index 0000000..d9a8f6f --- /dev/null +++ b/Juick/Views/ContentLoadingCell.h @@ -0,0 +1,17 @@ +// +// ContentLoadingCell.h +// Juick +// +// Created by Vitaly Takmazov on 16/10/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface ContentLoadingCell : UITableViewCell + +@end + +NS_ASSUME_NONNULL_END diff --git a/Juick/Views/ContentLoadingCell.m b/Juick/Views/ContentLoadingCell.m new file mode 100644 index 0000000..5ec67b3 --- /dev/null +++ b/Juick/Views/ContentLoadingCell.m @@ -0,0 +1,22 @@ +// +// ContentLoadingCell.m +// Juick +// +// Created by Vitaly Takmazov on 16/10/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import "ContentLoadingCell.h" + +@implementation ContentLoadingCell + +- (void)awakeFromNib { + [super awakeFromNib]; +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated { + [super setSelected:selected animated:animated]; + [self.contentView startShimmering]; +} + +@end diff --git a/Juick/Views/ContentLoadingCell.xib b/Juick/Views/ContentLoadingCell.xib new file mode 100644 index 0000000..e58af72 --- /dev/null +++ b/Juick/Views/ContentLoadingCell.xib @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Podfile b/Podfile index d223931..61ba285 100644 --- a/Podfile +++ b/Podfile @@ -10,5 +10,6 @@ target "Juick" do pod 'DateTools' pod 'TagListView-ObjC' pod 'PHFComposeBarView' + pod 'UIView+Shimmer' end diff --git a/Podfile.lock b/Podfile.lock index b4a9307..a43be6b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -30,6 +30,7 @@ PODS: - PHFDelegateChain (1.0.1) - TagListView-ObjC (0.1.1) - TTTAttributedLabel (2.0.0) + - "UIView+Shimmer (1.0.0)" - YYModel (1.0.4) DEPENDENCIES: @@ -40,6 +41,7 @@ DEPENDENCIES: - PHFComposeBarView - TagListView-ObjC - TTTAttributedLabel + - "UIView+Shimmer" - YYModel SPEC REPOS: @@ -52,6 +54,7 @@ SPEC REPOS: - PHFDelegateChain - TagListView-ObjC - TTTAttributedLabel + - "UIView+Shimmer" - YYModel SPEC CHECKSUMS: @@ -63,8 +66,9 @@ SPEC CHECKSUMS: PHFDelegateChain: 491f9cd8a3fb8761f390ff05f74a0e168d48d285 TagListView-ObjC: 432991e24c5177eb4fa7d721de7084f09f39a0b8 TTTAttributedLabel: 8cffe8e127e4e82ff3af1e5386d4cd0ad000b656 + "UIView+Shimmer": ed634f95e8f4bda666b28b47bd85a4336a4117d8 YYModel: 2a7fdd96aaa4b86a824e26d0c517de8928c04b30 -PODFILE CHECKSUM: a4dae3ca80591a5eedeac58df020463fdd94bb0e +PODFILE CHECKSUM: 4e2ec6ba0e314243295aab124ee21ea241447fd8 COCOAPODS: 1.5.3 -- cgit v1.2.3