Skip to content

Commit f11ff3a

Browse files
committed
Added empty dataset views
1 parent 083eeb9 commit f11ff3a

45 files changed

Lines changed: 4739 additions & 2605 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cluster.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
9D2EFA411BF6534400D91812 /* KlusterSearchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D2EFA401BF6534400D91812 /* KlusterSearchController.swift */; };
5858
9D63BB541C8DBD220094F5A2 /* MessagesNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D63BB531C8DBD220094F5A2 /* MessagesNavigationController.swift */; };
5959
9D63BB561C8DD0570094F5A2 /* PopoverHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D63BB551C8DD0570094F5A2 /* PopoverHeaderView.swift */; };
60+
9D7097251C987AB600DF5C8E /* Invite.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D7097241C987AB600DF5C8E /* Invite.swift */; };
6061
9D7CC5AB1C7E7958002D21D0 /* MessageTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D7CC5AA1C7E7958002D21D0 /* MessageTextView.swift */; };
6162
9D7CC5AD1C7E8EFB002D21D0 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D7CC5AC1C7E8EFB002D21D0 /* Message.swift */; };
6263
9D807F7F1C90834600FA5768 /* BLMultiColorLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D807F7E1C90834600FA5768 /* BLMultiColorLoader.m */; };
@@ -168,6 +169,7 @@
168169
9D2EFA401BF6534400D91812 /* KlusterSearchController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KlusterSearchController.swift; sourceTree = "<group>"; };
169170
9D63BB531C8DBD220094F5A2 /* MessagesNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessagesNavigationController.swift; sourceTree = "<group>"; };
170171
9D63BB551C8DD0570094F5A2 /* PopoverHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopoverHeaderView.swift; sourceTree = "<group>"; };
172+
9D7097241C987AB600DF5C8E /* Invite.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Invite.swift; sourceTree = "<group>"; };
171173
9D7CC5AA1C7E7958002D21D0 /* MessageTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageTextView.swift; sourceTree = "<group>"; };
172174
9D7CC5AC1C7E8EFB002D21D0 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
173175
9D807F7D1C90834600FA5768 /* BLMultiColorLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BLMultiColorLoader.h; sourceTree = "<group>"; };
@@ -383,6 +385,7 @@
383385
9D7CC5AC1C7E8EFB002D21D0 /* Message.swift */,
384386
9DFB7D611C86211C00EF3E62 /* KlusterStore.swift */,
385387
9D807F801C90B08D00FA5768 /* LocationStore.swift */,
388+
9D7097241C987AB600DF5C8E /* Invite.swift */,
386389
);
387390
name = Models;
388391
sourceTree = "<group>";
@@ -710,6 +713,7 @@
710713
28EE234B1BDF1F83009161AE /* DesignableTextField.swift in Sources */,
711714
28EE23711BDF1FF9009161AE /* ImagePreviewFlowLayout.swift in Sources */,
712715
28EE23511BDF1F83009161AE /* LoadingView.swift in Sources */,
716+
9D7097251C987AB600DF5C8E /* Invite.swift in Sources */,
713717
287147871BFAF00E007FDB36 /* NotificationsTableViewCell.swift in Sources */,
714718
CE0413501BD88B8300BED627 /* MembersTableViewController.swift in Sources */,
715719
28EE234A1BDF1F83009161AE /* DesignableTabBarController.swift in Sources */,

Cluster/Base.lproj/Main.storyboard

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<rect key="frame" x="0.0" y="0.0" width="600" height="119.5"/>
5151
<autoresizingMask key="autoresizingMask"/>
5252
<subviews>
53-
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="VUe-8O-jNl">
53+
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="VUe-8O-jNl" customClass="PFImageView">
5454
<rect key="frame" x="16" y="16" width="35" height="35"/>
5555
<constraints>
5656
<constraint firstAttribute="width" constant="35" id="gbE-1b-hDE"/>
@@ -141,7 +141,7 @@
141141
<outlet property="dateLabel" destination="zpR-vl-WTd" id="LlC-vu-4hp"/>
142142
<outlet property="declineButton" destination="8m8-xQ-0kn" id="yn3-vG-44h"/>
143143
<outlet property="invitationTypeLabel" destination="vRd-6C-yJj" id="jeU-0Y-Cfp"/>
144-
<outlet property="profileImage" destination="VUe-8O-jNl" id="2Fs-Nz-lpB"/>
144+
<outlet property="profileImageView" destination="VUe-8O-jNl" id="jLB-aM-oVS"/>
145145
<outlet property="userNameLabel" destination="30r-br-N8n" id="5HY-DI-g8Q"/>
146146
</connections>
147147
</tableViewCell>

Cluster/Cluster-Bridging-Header.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
#import <SlackTextViewController/SLKTextViewController.h>
1111

1212
#import "BLMultiColorLoader.h"
13-
#import "UITextView+Placeholder.h"
13+
#import "UIScrollView+EmptyDataSet.h"
14+
#import "UITextView+Placeholder.h"

Cluster/Invite.swift

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// Invite.swift
3+
// Cluster
4+
//
5+
// Created by Michael Fellows on 3/15/16.
6+
// Copyright © 2016 ImagineME. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
class Invite : NSObject {
12+
var fromUser: PFUser?
13+
var avatarFile: PFFile?
14+
var userName = ""
15+
var dateString = ""
16+
var accepted = false
17+
var kluster: Kluster?
18+
var declined = false
19+
var objectId = ""
20+
21+
init(object: PFObject?) {
22+
guard let object = object else {
23+
return
24+
}
25+
26+
guard let fromUser = object.objectForKey("fromUser") as? PFUser else {
27+
return
28+
}
29+
30+
if let id = object.objectId {
31+
self.objectId = id
32+
}
33+
34+
self.fromUser = fromUser
35+
if let file = fromUser.objectForKey("avatarThumbnail") as? PFFile {
36+
self.avatarFile = file
37+
}
38+
39+
if let firstName = fromUser.objectForKey("firstName") as? String, let lastName = fromUser.objectForKey("lastName") as? String {
40+
self.userName = "\(firstName) \(lastName)"
41+
}
42+
43+
if let k = object.objectForKey("kluster") as? PFObject {
44+
self.kluster = Kluster.init(object: k)
45+
}
46+
47+
if let accepted = object.objectForKey("accepted") as? Bool {
48+
self.accepted = accepted
49+
}
50+
}
51+
52+
func acceptKlusterInvite() {
53+
self.accepted = true
54+
}
55+
56+
func declineInvite() {
57+
self.declined = true
58+
}
59+
60+
func klusterInviteString() -> String {
61+
if let kluster = self.kluster {
62+
return "Invited you to join '\(kluster.title)'"
63+
} else {
64+
return "Invited you to a Kluster"
65+
}
66+
}
67+
}

Cluster/KlusterDataSource.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Foundation
1010

1111
class KlusterDataSource: NSObject {
12+
1213
class func createKlusterWithParams(params: [NSObject : AnyObject]?, completion:PFIdResultBlock) -> Void
1314
{
1415
PFCloud.callFunctionInBackground("createKluster", withParameters: params) { (object, error) -> Void in
@@ -92,4 +93,40 @@ class KlusterDataSource: NSObject {
9293
})
9394
}
9495
}
96+
97+
// Takes an array of user ids and invites user to the specified kluster
98+
class func inviteUsersToKluster(userIds: [String]?, klusterId: String?,completion: PFIdResultBlock) -> Void {
99+
if let userIds = userIds, let klusterId = klusterId where userIds.count > 0 && klusterId.length > 0 {
100+
let params = ["klusterId": klusterId, "userIds": userIds]
101+
PFCloud.callFunctionInBackground("inviteUsersToKluster", withParameters: params as [NSObject : AnyObject]) { (object, error) -> Void in
102+
completion(object, error)
103+
}
104+
}
105+
}
106+
107+
class func fetchInvites(completion: PFIdResultBlock) -> Void {
108+
PFCloud.callFunctionInBackground("fetchInvitationsForUser", withParameters: nil) { (object, error) -> Void in
109+
completion(object, error)
110+
}
111+
}
112+
113+
// Accepts an invitation to a Kluster
114+
class func acceptInvitation(klusterId: String?, invitationId: String?, completion: PFIdResultBlock) -> Void {
115+
if let klusterId = klusterId, let invitationId = invitationId {
116+
let params = ["klusterId": klusterId, "invitationId": invitationId]
117+
PFCloud.callFunctionInBackground("acceptInvitationToKluster", withParameters: params, block: { (object, error) -> Void in
118+
completion(object, error)
119+
})
120+
}
121+
}
122+
123+
// Declines an invitation to a Kluster
124+
class func declineKlusterInvitation(invitationId: String?, completion: PFIdResultBlock) -> Void {
125+
if let invitationId = invitationId {
126+
let params = ["invitationId": invitationId]
127+
PFCloud.callFunctionInBackground("declineKlusterInvitationToKluster", withParameters: params, block: { (object, error) -> Void in
128+
completion(object, error)
129+
})
130+
}
131+
}
95132
}

Cluster/KlusterInviteViewController.swift

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class KlusterInviteViewController : UITableViewController {
1313
var users = [PFUser]()
1414
var usersToInvite = [PFUser]()
1515
var kluster: Kluster!
16+
let hud = BLMultiColorLoader.init(frame: CGRectMake(0, 0, 40.0, 40.0))
1617

1718
override func viewDidLoad() {
1819
super.viewDidLoad()
@@ -25,6 +26,15 @@ class KlusterInviteViewController : UITableViewController {
2526
self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "Done", style: .Plain, target: self, action: "inviteDonePressed:")
2627
self.navigationItem.rightBarButtonItem?.enabled = false
2728

29+
// Add the hud before fetching friends..
30+
// Add progress HUD
31+
self.hud.center = self.view.center
32+
self.hud.lineWidth = 2.0
33+
self.hud.colorArray = [UIColor.klusterPurpleColor(), UIColor.lightGrayColor()]
34+
self.view.addSubview(hud)
35+
36+
self.hud.startAnimation()
37+
2838
self.fetchFacebookFriends()
2939
}
3040

@@ -93,6 +103,42 @@ class KlusterInviteViewController : UITableViewController {
93103
func inviteDonePressed(sender: UIBarButtonItem) {
94104
// TODO: Send invites...
95105

106+
var userIds = [String]()
107+
for user in self.usersToInvite {
108+
if let userId = user.objectId {
109+
userIds.append(userId)
110+
}
111+
}
112+
113+
// Disable the bar button item...
114+
if let barButtonItem = self.navigationItem.rightBarButtonItem {
115+
barButtonItem.enabled = false
116+
}
117+
118+
// Add hud - Already added to the view hierarchy
119+
self.hud.startAnimation()
120+
121+
KlusterDataSource.inviteUsersToKluster(userIds, klusterId: self.kluster.id) { (object, error) -> Void in
122+
123+
// Enable the bar button item...
124+
if let barButtonItem = self.navigationItem.rightBarButtonItem {
125+
barButtonItem.enabled = true
126+
}
127+
128+
// Stop animating the hud..
129+
self.hud.stopAnimation()
130+
131+
if error != nil {
132+
let alertController = UIAlertController.init(title: "Invite Error", message: "Something went wrong when inviting users to this Kluster. Please try again.", preferredStyle: .Alert)
133+
let okAction = UIAlertAction.init(title: "OK", style: .Default, handler: nil)
134+
alertController.addAction(okAction)
135+
self.presentViewController(alertController, animated: true, completion: nil)
136+
} else {
137+
if let navController = self.navigationController {
138+
navController.popViewControllerAnimated(true)
139+
}
140+
}
141+
}
96142
}
97143

98144

@@ -110,14 +156,6 @@ class KlusterInviteViewController : UITableViewController {
110156
}
111157

112158
private func fetchFacebookFriends() {
113-
// Add progress HUD
114-
let hud = BLMultiColorLoader.init(frame: CGRectMake(0, 0, 40.0, 40.0))
115-
hud.center = self.view.center
116-
hud.lineWidth = 2.0
117-
hud.colorArray = [UIColor.klusterPurpleColor(), UIColor.lightGrayColor()]
118-
self.view.addSubview(hud)
119-
hud.startAnimation()
120-
121159
// Fetch Facebook Friends
122160
let request = FBSDKGraphRequest.init(graphPath: "me/friends", parameters: nil, HTTPMethod: "GET")
123161
request.startWithCompletionHandler { (connection, result, error) -> Void in
@@ -142,7 +180,7 @@ class KlusterInviteViewController : UITableViewController {
142180
KlusterDataSource.fetchUsersWithFacebookIds(facebookUserIDs, kluster: self.kluster, completion: { (objects, error) -> Void in
143181

144182
// Remove the hud
145-
hud.stopAnimation()
183+
self.hud.stopAnimation()
146184

147185
if let objects = objects as? [PFUser] {
148186
self.users = objects
@@ -151,12 +189,12 @@ class KlusterInviteViewController : UITableViewController {
151189
})
152190
} else {
153191
// Remove the hud
154-
hud.stopAnimation()
192+
self.hud.stopAnimation()
155193
}
156194

157195
if let error = error {
158196
// Remove the hud
159-
hud.stopAnimation()
197+
self.hud.stopAnimation()
160198

161199
// Error fetching friends...
162200
self.showRequestError(error)

Cluster/MessagesTableViewController.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class MessagesTableViewController: UITableViewController {
2828
override func viewDidLoad() {
2929
super.viewDidLoad()
3030

31+
self.tableView.emptyDataSetDelegate = self
32+
self.tableView.emptyDataSetSource = self
33+
3134
// Set dynamic row height
3235
self.tableView.rowHeight = UITableViewAutomaticDimension
3336
self.tableView.estimatedRowHeight = 68.0
@@ -244,3 +247,45 @@ class MessagesTableViewController: UITableViewController {
244247
}
245248
}
246249
}
250+
251+
extension MessagesTableViewController : DZNEmptyDataSetDelegate {
252+
func emptyDataSetDidTapButton(scrollView: UIScrollView!) {
253+
self.textView.textField.becomeFirstResponder()
254+
}
255+
}
256+
257+
extension MessagesTableViewController : DZNEmptyDataSetSource {
258+
func descriptionForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString! {
259+
let text = "It's a little too quiet in here."
260+
261+
let paragraph = NSMutableParagraphStyle()
262+
paragraph.lineBreakMode = .ByWordWrapping
263+
paragraph.alignment = .Center
264+
265+
let attributes = [NSFontAttributeName : UIFont.systemFontOfSize(17.0),
266+
NSParagraphStyleAttributeName : paragraph]
267+
let attributedString = NSAttributedString.init(string: text, attributes: attributes)
268+
return attributedString
269+
}
270+
271+
func titleForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString! {
272+
let text = "Crickets..."
273+
let attributes = [NSFontAttributeName : UIFont.boldSystemFontOfSize(19.0),
274+
NSForegroundColorAttributeName: UIColor.darkGrayColor()]
275+
let attributedString = NSAttributedString.init(string: text, attributes: attributes)
276+
return attributedString
277+
}
278+
279+
func buttonTitleForEmptyDataSet(scrollView: UIScrollView!, forState state: UIControlState) -> NSAttributedString! {
280+
let text = "Say something"
281+
let attributes = [NSFontAttributeName : UIFont.boldSystemFontOfSize(19.0),
282+
NSForegroundColorAttributeName: UIColor.klusterPurpleColor()]
283+
let attributedString = NSAttributedString.init(string: text, attributes: attributes)
284+
return attributedString
285+
}
286+
287+
func spaceHeightForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat {
288+
return 20.0
289+
}
290+
}
291+

0 commit comments

Comments
 (0)