Skip to content

Commit

Permalink
DZNEmptyDataSet "Loading Events" added
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHenryIE committed Mar 29, 2017
1 parent 12b42ce commit ee4b9c3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def common_pods
pod 'Fabric'
pod 'Crashlytics'
pod 'ReachabilitySwift', '~> 3'
pod 'DZNEmptyDataSet'
# Mofified and added to project
# pod 'SLPagingViewSwift-Swift3', :git => 'https://github.com/davidseek/SLPagingViewSwift-Swift-3-Tinder-Twitter.git'
end
Expand Down
5 changes: 4 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PODS:
- ObjectMapper (~> 2.0)
- Crashlytics (3.8.3):
- Fabric (~> 1.6.3)
- DZNEmptyDataSet (1.8.1)
- Fabric (1.6.11)
- Mockingjay (2.0.0):
- Mockingjay/Core (= 2.0.0)
Expand All @@ -24,6 +25,7 @@ DEPENDENCIES:
- AlamofireImage (from `https://github.com/Alamofire/AlamofireImage.git`)
- AlamofireObjectMapper (from `https://github.com/tristanhimmelman/AlamofireObjectMapper`)
- Crashlytics
- DZNEmptyDataSet
- Fabric
- Mockingjay (from `https://github.com/kylef/Mockingjay.git`)
- ObjectMapper (from `https://github.com/Hearst-DD/ObjectMapper.git`)
Expand Down Expand Up @@ -63,12 +65,13 @@ SPEC CHECKSUMS:
AlamofireImage: 0ff319da83d6abb78a661d7296e742e7f65e15f5
AlamofireObjectMapper: 842d2eed43a4d0593ff0110d54ac86a170c4519c
Crashlytics: 2b6dbe138a42395577cfa73dfa1aa7248cadf39e
DZNEmptyDataSet: 9525833b9e68ac21c30253e1d3d7076cc828eaa7
Fabric: 5911403591946b8228ab1c51d98f1d7137e863c6
Mockingjay: 95a5fbe594f963f7536d3975739df39f1366f4d1
ObjectMapper: 9e385c2295bcc4e16eabbcfc85db801442bba545
ReachabilitySwift: f5b9bb30a0777fac8f09ce8b067e32faeb29bb64
URITemplate: a5acb3f76c6a2338116fde88b658d83f91bbac45

PODFILE CHECKSUM: 81d21697db92927c0f296256ebc12d672be17809
PODFILE CHECKSUM: fe7a7cdb6dabf74947bc87fb5e820f8c0c94c20b

COCOAPODS: 1.2.0
11 changes: 7 additions & 4 deletions SortonsEvents/ListEvents.storyboard
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="msU-ZY-gOw">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="msU-ZY-gOw">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--List Events Table View Controller-->
<!--List Events-->
<scene sceneID="qAl-du-ZgQ">
<objects>
<tableViewController storyboardIdentifier="ListEvents" id="msU-ZY-gOw" customClass="ListEventsTableViewController" customModule="SortonsEvents" customModuleProvider="target" sceneMemberID="viewController">
<tableViewController storyboardIdentifier="ListEvents" id="msU-ZY-gOw" userLabel="List Events" customClass="ListEventsTableViewController" customModule="SortonsEvents" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="118" sectionHeaderHeight="28" sectionFooterHeight="28" id="Tj3-QP-mGP">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -81,10 +81,13 @@
<connections>
<outlet property="dataSource" destination="msU-ZY-gOw" id="Uf5-gT-EqZ"/>
<outlet property="delegate" destination="msU-ZY-gOw" id="qak-R4-dUm"/>
<outlet property="emptyDataSetDelegate" destination="msU-ZY-gOw" id="PNL-qA-xHh"/>
<outlet property="emptyDataSetSource" destination="msU-ZY-gOw" id="fXd-xo-zRB"/>
</connections>
</tableView>
<extendedEdge key="edgesForExtendedLayout"/>
<refreshControl key="refreshControl" opaque="NO" multipleTouchEnabled="YES" contentMode="center" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="8H8-wR-E7F">
<rect key="frame" x="0.0" y="0.0" width="1000" height="1000"/>
<autoresizingMask key="autoresizingMask"/>
</refreshControl>
</tableViewController>
Expand Down
30 changes: 30 additions & 0 deletions SortonsEvents/ListEventsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//

import UIKit
import DZNEmptyDataSet

protocol ListEventsTableViewControllerOutputProtocol {
func fetchFromCache()
Expand All @@ -19,6 +20,7 @@ protocol ListEventsTableViewControllerOutputProtocol {
}

class ListEventsTableViewController: UITableViewController, ListEventsPresenterOutputProtocol {

var output: ListEventsTableViewControllerOutputProtocol?
var data: [ListEvents.ViewModel.Cell]?

Expand Down Expand Up @@ -49,6 +51,8 @@ class ListEventsTableViewController: UITableViewController, ListEventsPresenterO
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 140

self.tableView.tableFooterView = UIView()

refreshControl?.addTarget(self,
action: #selector(refresh(_:)),
for: UIControlEvents.valueChanged)
Expand Down Expand Up @@ -132,3 +136,29 @@ extension ListEventsTableViewController {
tableView.deselectRow(at: indexPath, animated: true)
}
}

extension ListEventsTableViewController: DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {

func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {

return UIImage(named: "ListEventsTabBarIconFilled")
}

func title(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {

let title = "FOMO UCD"

return NSAttributedString(string: title)
}

func description(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {

let description = "Loading events"

return NSAttributedString(string: description)
}

func emptyDataSet(_ scrollView: UIScrollView, didTap view: UIView) {
fetchFromNetwork()
}
}
22 changes: 15 additions & 7 deletions SortonsEvents/RootInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum SortonsNotifications {

// var for testing
var reachability = Reachability()
var lastOnlineDate = Date()
var lastOnlineDate: Date?

init(output: RootInteractorOutput) {

Expand Down Expand Up @@ -63,13 +63,21 @@ enum SortonsNotifications {
}

func refetchData() {
let now = Date()
let timeSinceLastOpened = now.timeIntervalSince(lastOnlineDate)
if timeSinceLastOpened > TimeInterval(15*60) {
DispatchQueue.main.async {
NotificationCenter.default.post(name: SortonsNotifications.Reload,
object: self)
if let lastOnlineDate = lastOnlineDate {
let now = Date()
let timeSinceLastOpened = now.timeIntervalSince(lastOnlineDate)
if timeSinceLastOpened > TimeInterval(15*60) {
sendReloadNotification()
}
} else {
sendReloadNotification()
}
}

func sendReloadNotification() {
DispatchQueue.main.async {
NotificationCenter.default.post(name: SortonsNotifications.Reload,
object: self)
}
}
}

0 comments on commit ee4b9c3

Please sign in to comment.