Skip to content

Commit

Permalink
Added sorting, filtering and checking necessary data
Browse files Browse the repository at this point in the history
  • Loading branch information
belkevich committed Jan 13, 2014
1 parent 2cf92ec commit 1dff44b
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 137 deletions.
20 changes: 6 additions & 14 deletions AddressBook/AddressBook.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
FA66282E187FE9EF00667C81 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FA66282D187FE9EF00667C81 /* Images.xcassets */; };
FA66284E187FEC1400667C81 /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FA66284D187FEC1400667C81 /* Storyboard.storyboard */; };
FA662854187FEC7F00667C81 /* ListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FA662853187FEC7F00667C81 /* ListViewController.m */; };
FA662858187FEC9600667C81 /* ContactViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FA662857187FEC9600667C81 /* ContactViewController.m */; };
FA66285C187FFACD00667C81 /* APAddressBook.m in Sources */ = {isa = PBXBuildFile; fileRef = FA66285B187FFACD00667C81 /* APAddressBook.m */; };
FA662860187FFB2100667C81 /* APContact.m in Sources */ = {isa = PBXBuildFile; fileRef = FA66285F187FFB2100667C81 /* APContact.m */; };
FA662862187FFCA700667C81 /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA662861187FFCA700667C81 /* AddressBook.framework */; };
FA66286618800DC500667C81 /* ContactTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FA66286518800DC500667C81 /* ContactTableViewCell.m */; };
FAD1CCE91881A18900D03475 /* ContactTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = FAD1CCE81881A18900D03475 /* ContactTableViewCell.xib */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -41,15 +41,15 @@
FA66284D187FEC1400667C81 /* Storyboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = "<group>"; };
FA662852187FEC7F00667C81 /* ListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListViewController.h; sourceTree = "<group>"; };
FA662853187FEC7F00667C81 /* ListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ListViewController.m; sourceTree = "<group>"; };
FA662856187FEC9600667C81 /* ContactViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactViewController.h; sourceTree = "<group>"; };
FA662857187FEC9600667C81 /* ContactViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactViewController.m; sourceTree = "<group>"; };
FA66285A187FFACD00667C81 /* APAddressBook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = APAddressBook.h; path = ../Classes/APAddressBook.h; sourceTree = "<group>"; };
FA66285B187FFACD00667C81 /* APAddressBook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = APAddressBook.m; path = ../Classes/APAddressBook.m; sourceTree = "<group>"; };
FA66285E187FFB2100667C81 /* APContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = APContact.h; path = ../Classes/APContact.h; sourceTree = "<group>"; };
FA66285F187FFB2100667C81 /* APContact.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = APContact.m; path = ../Classes/APContact.m; sourceTree = "<group>"; };
FA662861187FFCA700667C81 /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
FA66286418800DC500667C81 /* ContactTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactTableViewCell.h; sourceTree = "<group>"; };
FA66286518800DC500667C81 /* ContactTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactTableViewCell.m; sourceTree = "<group>"; };
FAD1CCE718819F7000D03475 /* APTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = APTypes.h; path = ../Classes/APTypes.h; sourceTree = "<group>"; };
FAD1CCE81881A18900D03475 /* ContactTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ContactTableViewCell.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -135,7 +135,6 @@
isa = PBXGroup;
children = (
FA662855187FEC8500667C81 /* List */,
FA662859187FECBE00667C81 /* Contact */,
);
name = Controllers;
sourceTree = "<group>";
Expand All @@ -158,22 +157,14 @@
name = List;
sourceTree = "<group>";
};
FA662859187FECBE00667C81 /* Contact */ = {
isa = PBXGroup;
children = (
FA662856187FEC9600667C81 /* ContactViewController.h */,
FA662857187FEC9600667C81 /* ContactViewController.m */,
);
name = Contact;
sourceTree = "<group>";
};
FA66285D187FFAD300667C81 /* Classes */ = {
isa = PBXGroup;
children = (
FA66285A187FFACD00667C81 /* APAddressBook.h */,
FA66285B187FFACD00667C81 /* APAddressBook.m */,
FA66285E187FFB2100667C81 /* APContact.h */,
FA66285F187FFB2100667C81 /* APContact.m */,
FAD1CCE718819F7000D03475 /* APTypes.h */,
);
name = Classes;
sourceTree = "<group>";
Expand All @@ -191,6 +182,7 @@
children = (
FA66286418800DC500667C81 /* ContactTableViewCell.h */,
FA66286518800DC500667C81 /* ContactTableViewCell.m */,
FAD1CCE81881A18900D03475 /* ContactTableViewCell.xib */,
);
name = Cells;
sourceTree = "<group>";
Expand Down Expand Up @@ -248,6 +240,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FAD1CCE91881A18900D03475 /* ContactTableViewCell.xib in Resources */,
FA662826187FE9EF00667C81 /* InfoPlist.strings in Resources */,
FA66282E187FE9EF00667C81 /* Images.xcassets in Resources */,
FA66284E187FEC1400667C81 /* Storyboard.storyboard in Resources */,
Expand Down Expand Up @@ -297,7 +290,6 @@
FA66282C187FE9EF00667C81 /* AppDelegate.m in Sources */,
FA66285C187FFACD00667C81 /* APAddressBook.m in Sources */,
FA66286618800DC500667C81 /* ContactTableViewCell.m in Sources */,
FA662858187FEC9600667C81 /* ContactViewController.m in Sources */,
FA662860187FFB2100667C81 /* APContact.m in Sources */,
FA662828187FE9EF00667C81 /* main.m in Sources */,
FA662854187FEC7F00667C81 /* ListViewController.m in Sources */,
Expand Down
29 changes: 26 additions & 3 deletions AddressBook/AddressBook/ContactTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#import "ContactTableViewCell.h"
#import "APContact.h"

@interface ContactTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *photoView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@property (weak, nonatomic) IBOutlet UILabel *phonesLabel;
@property (weak, nonatomic) IBOutlet UILabel *emailsLabel;
@end

@implementation ContactTableViewCell

#pragma mark - life cycle
Expand All @@ -28,8 +36,11 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
- (void)updateWithModel:(id)model
{
APContact *contact = model;
self.textLabel.text = [self contactName:contact];
self.detailTextLabel.text = [self contactPhones:contact];
self.nameLabel.text = [self contactName:contact];
self.companyLabel.text = contact.company ?: @"(No company)";
self.phonesLabel.text = [self contactPhones:contact];
self.emailsLabel.text = [self contactEmails:contact];
self.photoView.image = contact.photo ?: [UIImage imageNamed:@"no_photo"];
}

#pragma mark - private
Expand Down Expand Up @@ -58,7 +69,19 @@ - (NSString *)contactPhones:(APContact *)contact
}
else
{
return contact.phones.firstObject ?: @"No phones";
return contact.phones.firstObject ?: @"(No phones)";
}
}

- (NSString *)contactEmails:(APContact *)contact
{
if (contact.emails.count > 1)
{
return [contact.emails componentsJoinedByString:@", "];
}
else
{
return contact.emails.firstObject ?: @"(No emails)";
}
}

Expand Down
59 changes: 59 additions & 0 deletions AddressBook/AddressBook/ContactTableViewCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3747"/>
</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" rowHeight="85" id="434-jy-hEK" customClass="ContactTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="85"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="434-jy-hEK" id="FKC-HD-Wje">
<rect key="frame" x="0.0" y="0.0" width="320" height="84"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="tp5-zf-JC4">
<rect key="frame" x="0.0" y="7" width="70" height="70"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Name" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="WNT-Du-rLr">
<rect key="frame" x="77" y="0.0" width="243" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Company" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="s4Y-nL-BJ6">
<rect key="frame" x="77" y="21" width="243" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Light" family="Helvetica Neue" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Phones" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="lip-dA-8QX">
<rect key="frame" x="77" y="42" width="243" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Light" family="Helvetica Neue" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Emails" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="HB4-lT-Bym">
<rect key="frame" x="77" y="63" width="243" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Light" family="Helvetica Neue" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="companyLabel" destination="s4Y-nL-BJ6" id="vC8-cr-sPS"/>
<outlet property="emailsLabel" destination="HB4-lT-Bym" id="etT-Bf-34t"/>
<outlet property="nameLabel" destination="WNT-Du-rLr" id="YjX-Pb-iJR"/>
<outlet property="phonesLabel" destination="lip-dA-8QX" id="wLs-m2-3GG"/>
<outlet property="photoView" destination="tp5-zf-JC4" id="bZ2-6t-xfj"/>
</connections>
</tableViewCell>
</objects>
</document>
13 changes: 0 additions & 13 deletions AddressBook/AddressBook/ContactViewController.h

This file was deleted.

38 changes: 0 additions & 38 deletions AddressBook/AddressBook/ContactViewController.m

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "no_photo.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions AddressBook/AddressBook/ListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#import "ContactTableViewCell.h"
#import "APContact.h"
#import "APAddressBook.h"
#import "ContactViewController.h"

@interface ListViewController ()
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activity;
Expand Down Expand Up @@ -43,12 +42,18 @@ - (void)viewDidLoad
[self loadContacts];
}

#pragma mark - table view data source implementation

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 85.f;
}

#pragma mark - table view delegate implementation

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
[self performSegueWithIdentifier:NSStringFromClass(ContactViewController.class) sender:self];
}

#pragma mark - private
Expand All @@ -57,6 +62,14 @@ - (void)loadContacts
{
[self.activity startAnimating];
__weak __typeof(self) weakSelf = self;
addressBook.fieldsMask = APContactFieldAll;
addressBook.sortDescriptors = @[
[NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES],
[NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES]];
addressBook.filterBlock = ^BOOL(APContact *contact)
{
return contact.phones.count > 0;
};
[addressBook loadContacts:^(NSArray *contacts, NSError *error)
{
[weakSelf.activity stopAnimating];
Expand Down
20 changes: 0 additions & 20 deletions AddressBook/AddressBook/Storyboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,12 @@
<connections>
<outlet property="activity" destination="qCc-8T-6qI" id="3kC-Mn-9nQ"/>
<outlet property="tableView" destination="jh6-dS-3e7" id="f40-AU-ADT"/>
<segue destination="x3S-fv-DkB" kind="push" identifier="ContactViewController" id="3el-3x-UoO"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="0tZ-fz-LlY" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="558" y="249"/>
</scene>
<!--Contact View Controller - Contact-->
<scene sceneID="EWy-hb-qee">
<objects>
<viewController id="x3S-fv-DkB" customClass="ContactViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="4Kk-H1-FrX"/>
<viewControllerLayoutGuide type="bottom" id="i7k-ir-VQQ"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Nzm-nX-8Df">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" title="Contact" id="Kk3-2E-aHR"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qPt-XG-BXr" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="979" y="249"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
Expand Down
12 changes: 6 additions & 6 deletions Classes/APAddressBook.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
//

#import <Foundation/Foundation.h>
#import "APTypes.h"

typedef enum
{
APAddressBookAccessUnknown = 0,
APAddressBookAccessGranted = 1,
APAddressBookAccessDenied = 2
} APAddressBookAccess;
@class APContact;

@interface APAddressBook : NSObject

@property (nonatomic, assign) APContactField fieldsMask;
@property (nonatomic, copy) APContactFilterBlock filterBlock;
@property (nonatomic, strong) NSArray *sortDescriptors;

+ (APAddressBookAccess)access;
- (void)loadContacts:(void (^)(NSArray *contacts, NSError *error))callbackBlock;

Expand Down
Loading

0 comments on commit 1dff44b

Please sign in to comment.