summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-16 23:04:01 +0300
committerGravatar Vitaly Takmazov2018-10-16 23:04:01 +0300
commit842990ac65de6fd61e027c8a9cff48d30aaf3a60 (patch)
tree2150701f1c32ec69b9d254a4c96dedb0573737d5 /Juick
parenta7cb4ab3f629b423099afad204c7ae1bf8df9677 (diff)
Content loading
Diffstat (limited to 'Juick')
-rw-r--r--Juick/Supporting Files/Juick-Prefix.pch1
-rw-r--r--Juick/ViewControllers/DiscoverViewController.m10
-rw-r--r--Juick/ViewControllers/MessagesViewController.m37
-rw-r--r--Juick/Views/ContentLoadingCell.h17
-rw-r--r--Juick/Views/ContentLoadingCell.m22
-rw-r--r--Juick/Views/ContentLoadingCell.xib84
6 files changed, 156 insertions, 15 deletions
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 <DateTools/DateTools.h>
#import <TagListView-ObjC/TagListView.h>
#import <PHFComposeBarView/PHFComposeBarView.h>
+ #import <UIView+Shimmer.h>
#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 <UIKit/UIKit.h>
+
+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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
+ <device id="retina4_7" orientation="portrait">
+ <adaptation id="fullscreen"/>
+ </device>
+ <dependencies>
+ <deployment identifier="iOS"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
+ <capability name="Safe area layout guides" minToolsVersion="9.0"/>
+ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+ </dependencies>
+ <objects>
+ <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
+ <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="contentLoadingCell" rowHeight="230" id="KGk-i7-Jjw" customClass="ContentLoadingCell">
+ <rect key="frame" x="0.0" y="0.0" width="310" height="230"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+ <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
+ <rect key="frame" x="0.0" y="0.0" width="310" height="229.5"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <subviews>
+ <stackView opaque="NO" contentMode="scaleToFill" verticalCompressionResistancePriority="751" axis="vertical" spacing="24" translatesAutoresizingMaskIntoConstraints="NO" id="33o-rP-dfk">
+ <rect key="frame" x="24" y="12" width="262" height="205.5"/>
+ <subviews>
+ <stackView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="255" verticalCompressionResistancePriority="748" alignment="center" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="Bqm-4Y-1yg">
+ <rect key="frame" x="0.0" y="0.0" width="262" height="48"/>
+ <subviews>
+ <view contentMode="scaleToFill" verticalCompressionResistancePriority="748" translatesAutoresizingMaskIntoConstraints="NO" id="Xfd-wK-nGQ">
+ <rect key="frame" x="0.0" y="0.0" width="48" height="48"/>
+ <color key="backgroundColor" red="0.97254901960784312" green="0.97254901960784312" blue="0.97254901960784312" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+ <constraints>
+ <constraint firstAttribute="height" constant="48" id="gWm-7q-ure"/>
+ <constraint firstAttribute="width" constant="48" id="paR-BH-BPq"/>
+ </constraints>
+ </view>
+ <view contentMode="scaleToFill" verticalCompressionResistancePriority="748" translatesAutoresizingMaskIntoConstraints="NO" id="RpL-2E-Dtt">
+ <rect key="frame" x="60" y="12" width="202" height="24"/>
+ <color key="backgroundColor" red="0.97254901960784312" green="0.97254901960784312" blue="0.97254901960784312" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+ <constraints>
+ <constraint firstAttribute="height" constant="24" id="jxf-Sb-SeH"/>
+ </constraints>
+ </view>
+ </subviews>
+ </stackView>
+ <stackView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="249" verticalCompressionResistancePriority="752" axis="vertical" distribution="fillEqually" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="WY4-IV-5wO">
+ <rect key="frame" x="0.0" y="72" width="262" height="133.5"/>
+ <subviews>
+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="TF4-pH-jy5">
+ <rect key="frame" x="0.0" y="0.0" width="262" height="17"/>
+ <color key="backgroundColor" red="0.97254901960784312" green="0.97254901960784312" blue="0.97254901960784312" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+ </view>
+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="iLC-oW-h16">
+ <rect key="frame" x="0.0" y="29" width="262" height="17"/>
+ <color key="backgroundColor" red="0.97254901960784312" green="0.97254901960784312" blue="0.97254901960784312" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+ </view>
+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="e26-WV-V2J">
+ <rect key="frame" x="0.0" y="58" width="262" height="17.5"/>
+ <color key="backgroundColor" red="0.97254901960784312" green="0.97254901960784312" blue="0.97254901960784312" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+ </view>
+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5HE-g4-DHe">
+ <rect key="frame" x="0.0" y="87.5" width="262" height="17"/>
+ <color key="backgroundColor" red="0.97254901960784312" green="0.97254901960784312" blue="0.97254901960784312" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+ </view>
+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="O0R-kH-hzS">
+ <rect key="frame" x="0.0" y="116.5" width="262" height="17"/>
+ <color key="backgroundColor" red="0.97254901960784312" green="0.97254901960784312" blue="0.97254901960784312" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+ </view>
+ </subviews>
+ </stackView>
+ </subviews>
+ </stackView>
+ </subviews>
+ <constraints>
+ <constraint firstItem="33o-rP-dfk" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="12" id="Fdp-wO-B2U"/>
+ <constraint firstAttribute="bottom" secondItem="33o-rP-dfk" secondAttribute="bottom" constant="12" id="PBl-xt-lLN"/>
+ <constraint firstAttribute="trailing" secondItem="33o-rP-dfk" secondAttribute="trailing" constant="24" id="kae-JF-BnF"/>
+ <constraint firstItem="33o-rP-dfk" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="24" id="oli-Q3-Y7U"/>
+ </constraints>
+ </tableViewCellContentView>
+ <viewLayoutGuide key="safeArea" id="aW0-zy-SZf"/>
+ <point key="canvasLocation" x="139.19999999999999" y="226.6866566716642"/>
+ </tableViewCell>
+ </objects>
+</document>