Skip to content

Commit

Permalink
Refactored contact dates extraction
Browse files Browse the repository at this point in the history
Renamed 'APDate' to 'APContactDate'
  • Loading branch information
belkevich committed Jan 14, 2016
1 parent e886d57 commit 8bf0077
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 54 deletions.
6 changes: 6 additions & 0 deletions Example/Objective-C/AddressBook.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
2DBA12ED1646227C60CFEB8A /* APSocialServiceHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DBA1D50E367D26256BF6ACE /* APSocialServiceHelper.m */; };
2DBA1353F6D48E61D8FE52E9 /* APAddressBookAccessRoutine.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DBA12274B8BFA605F110B91 /* APAddressBookAccessRoutine.m */; };
2DBA137D3076D6E6FC78ABB9 /* APContactBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DBA10055B7C4CA15B752EE5 /* APContactBuilder.m */; };
2DBA143E1EF04463EA0C757D /* APContactDate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DBA12402A8EE654AD2FD70A /* APContactDate.m */; };
2DBA14C2B75EDDF1BE7BCE4B /* APRelatedPerson.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DBA1841E1F7B8E6EDEF5438 /* APRelatedPerson.m */; };
2DBA1592543ABA1E3A6B98EA /* APEmail.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DBA137692064C27CC3DDBC5 /* APEmail.m */; };
2DBA161F7922FC8733E39BDF /* APSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DBA1F7630DA6BBFED5D6526 /* APSource.m */; };
Expand Down Expand Up @@ -51,6 +52,7 @@
2DBA11586D1BD36B84E8D9B0 /* APAddressBookAccessRoutine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APAddressBookAccessRoutine.h; sourceTree = "<group>"; };
2DBA11ABCAF3BCAD3D9B4E0D /* APImageExtractor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APImageExtractor.h; sourceTree = "<group>"; };
2DBA12274B8BFA605F110B91 /* APAddressBookAccessRoutine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APAddressBookAccessRoutine.m; sourceTree = "<group>"; };
2DBA12402A8EE654AD2FD70A /* APContactDate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APContactDate.m; sourceTree = "<group>"; };
2DBA125B051EE9D46F45C505 /* APThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APThread.m; sourceTree = "<group>"; };
2DBA12CDF576C49EAEB83108 /* APPhone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APPhone.h; sourceTree = "<group>"; };
2DBA12D09D8CD39546DE39A8 /* APDeprecated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APDeprecated.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -87,6 +89,7 @@
2DBA1CAE20F58C7157F9C097 /* APAddressBookBaseRoutine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APAddressBookBaseRoutine.h; sourceTree = "<group>"; };
2DBA1CE66C6D93542A66D6CC /* APAddressBookRefWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APAddressBookRefWrapper.m; sourceTree = "<group>"; };
2DBA1D50E367D26256BF6ACE /* APSocialServiceHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APSocialServiceHelper.m; sourceTree = "<group>"; };
2DBA1D597A4DD560AEAD0FEA /* APContactDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APContactDate.h; sourceTree = "<group>"; };
2DBA1DD07C5A43B4DD3EA17A /* APContactBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APContactBuilder.h; sourceTree = "<group>"; };
2DBA1DD6DF0D8A85F333FBD3 /* APContactListBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APContactListBuilder.m; sourceTree = "<group>"; };
2DBA1F4B68223450E5314F03 /* APRecordDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APRecordDate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -251,6 +254,8 @@
2DBA19CDD95005EF506993AF /* APJob.h */,
2DBA19D573D9CD2762141F22 /* APRecordDate.m */,
2DBA1F4B68223450E5314F03 /* APRecordDate.h */,
2DBA1D597A4DD560AEAD0FEA /* APContactDate.h */,
2DBA12402A8EE654AD2FD70A /* APContactDate.m */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -524,6 +529,7 @@
2DBA18949A6B5C9961D5548E /* APJob.m in Sources */,
2DBA1C01BE35D5D6CC6DEE99 /* APRecordDate.m in Sources */,
2DBA193C7A6E4AF64D50C7E9 /* APContactListBuilder.m in Sources */,
2DBA143E1EF04463EA0C757D /* APContactDate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 4 additions & 4 deletions Pod/Core/Private/Builders/APContactBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ - (APContact *)contactWithRecordRef:(ABRecordRef)recordRef fieldMask:(APContactF
{
contact.birthday = [self.extractor dateProperty:kABPersonBirthdayProperty];
}
if (fieldMask & APContactFieldDates)
{
contact.dates = [self.extractor dates];
}
if (fieldMask & APContactFieldWebsites)
{
contact.websites = [self.extractor arrayProperty:kABPersonURLProperty];
Expand All @@ -89,6 +85,10 @@ - (APContact *)contactWithRecordRef:(ABRecordRef)recordRef fieldMask:(APContactF
{
contact.source = [self.extractor source];
}
if (fieldMask & APContactFieldDates)
{
contact.dates = [self.extractor dates];
}
if (fieldMask & APContactFieldRecordDate)
{
contact.recordDate = [self.extractor recordDate];
Expand Down
2 changes: 1 addition & 1 deletion Pod/Core/Private/Extractors/APContactDataExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
- (NSArray *)socialProfiles;
- (NSArray *)relatedPersons;
- (NSArray *)linkedRecordIDs;
- (NSArray *)dates;
- (APSource *)source;
- (NSArray *)dates;
- (APRecordDate *)recordDate;
- (NSString *)stringProperty:(ABPropertyID)property;
- (NSArray *)arrayProperty:(ABPropertyID)property;
Expand Down
36 changes: 18 additions & 18 deletions Pod/Core/Private/Extractors/APContactDataExtractor.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#import "APSource.h"
#import "APRelatedPerson.h"
#import "APRecordDate.h"
#import "APDate.h"
#import "APContactDate.h"

@implementation APContactDataExtractor

Expand Down Expand Up @@ -156,23 +156,6 @@ - (NSArray *)linkedRecordIDs
return linkedRecordIDs.array;
}

- (NSArray *) dates
{
return [self mapMultiValueOfProperty:kABPersonDateProperty
withBlock:^id(ABMultiValueRef multiValue, CFTypeRef value, CFIndex index)
{
APDate *date;
if (value)
{
date = [[APDate alloc] init];
date.date = (__bridge NSDate *)ABMultiValueCopyValueAtIndex(multiValue, index);
date.originalLabel = [self originalLabelFromMultiValue:multiValue index:index];
date.localizedLabel = [self localizedLabelFromMultiValue:multiValue index:index];
}
return date;
}];
}

- (APSource *)source
{
APSource *source;
Expand All @@ -187,6 +170,23 @@ - (APSource *)source
return source;
}

- (NSArray *)dates
{
return [self mapMultiValueOfProperty:kABPersonDateProperty
withBlock:^id(ABMultiValueRef multiValue, CFTypeRef value, CFIndex index)
{
APContactDate *date;
if (value)
{
date = [[APContactDate alloc] init];
date.date = (__bridge NSDate *)value;
date.originalLabel = [self originalLabelFromMultiValue:multiValue index:index];
date.localizedLabel = [self localizedLabelFromMultiValue:multiValue index:index];
}
return date;
}];
}

- (APRecordDate *)recordDate
{
APRecordDate *recordDate = [[APRecordDate alloc] init];
Expand Down
4 changes: 2 additions & 2 deletions Pod/Core/Public/Models/APContact.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#import "APRelatedPerson.h"
#import "APSource.h"
#import "APRecordDate.h"
#import "APDate.h"
#import "APContactDate.h"

@interface APContact : NSObject

Expand All @@ -30,12 +30,12 @@
@property (nullable, nonatomic, strong) NSArray <APAddress *> *addresses;
@property (nullable, nonatomic, strong) NSArray <APSocialProfile *> *socialProfiles;
@property (nullable, nonatomic, strong) NSDate *birthday;
@property (nullable, nonatomic, strong) NSArray <APDate *> *dates;
@property (nullable, nonatomic, strong) NSString *note;
@property (nullable, nonatomic, strong) NSArray <NSString *> *websites;
@property (nullable, nonatomic, strong) NSArray <APRelatedPerson *> *relatedPersons;
@property (nullable, nonatomic, strong) NSArray <NSNumber *> *linkedRecordIDs;
@property (nullable, nonatomic, strong) APSource *source;
@property (nullable, nonatomic, strong) NSArray <APContactDate *> *dates;
@property (nullable, nonatomic, strong) APRecordDate *recordDate;

@end
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// APDate.h
// Pods
// APContactDate.h
// APAddressBook
//
// Created by Alexandre Plisson on 14/01/2016.
//
//

#import <Foundation/Foundation.h>

@interface APDate : NSObject
@interface APContactDate : NSObject

@property (nullable, nonatomic, strong) NSDate *date;
@property (nullable, nonatomic, strong) NSString *originalLabel;
Expand Down
13 changes: 13 additions & 0 deletions Pod/Core/Public/Models/APContactDate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// APContactDate.m
// APAddressBook
//
// Created by Alexandre Plisson on 14/01/2016.
//
//

#import "APContactDate.h"

@implementation APContactDate

@end
13 changes: 0 additions & 13 deletions Pod/Core/Public/Models/APDate.m

This file was deleted.

2 changes: 1 addition & 1 deletion Pod/Core/Public/Models/APEmail.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// APEmail.h
// AddressBook
// APAddressBook
//
// Created by Sean Langley on 2015-03-18.
// Copyright (c) 2015 Sean Langley. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Pod/Core/Public/Models/APEmail.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// APEmail.m
// AddressBook
// APAddressBook
//
// Created by Sean Langley on 2015-03-18.
// Copyright (c) 2015 Sean Langley. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Pod/Core/Public/Models/APJob.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// APJob
// AddressBook
// APAddressBook
//
// Created by Alexey Belkevich on 05.10.15.
// Copyright © 2015 alterplay. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Pod/Core/Public/Models/APJob.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// APJob
// AddressBook
// APAddressBook
//
// Created by Alexey Belkevich on 05.10.15.
// Copyright © 2015 alterplay. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Pod/Core/Public/Models/APName.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// APName
// AddressBook
// APAddressBook
//
// Created by Alexey Belkevich on 05.10.15.
// Copyright © 2015 alterplay. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Pod/Core/Public/Models/APName.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// APName
// AddressBook
// APAddressBook
//
// Created by Alexey Belkevich on 05.10.15.
// Copyright © 2015 alterplay. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Pod/Core/Public/Models/APRecordDate.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// APRecordDate
// AddressBook
// APAddressBook
//
// Created by Alexey Belkevich on 05.10.15.
// Copyright © 2015 alterplay. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Pod/Core/Public/Models/APRecordDate.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// APRecordDate
// AddressBook
// APAddressBook
//
// Created by Alexey Belkevich on 05.10.15.
// Copyright © 2015 alterplay. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Pod/Core/Public/Models/APSource.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// APSource
// AddressBook
// APAddressBook
//
// Created by Alexey Belkevich on 23.09.15.
// Copyright © 2015 alterplay. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Pod/Core/Public/Models/APSource.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// APSource
// AddressBook
// APAddressBook
//
// Created by Alexey Belkevich on 23.09.15.
// Copyright © 2015 alterplay. All rights reserved.
Expand Down
4 changes: 2 additions & 2 deletions Pod/Core/Public/Models/APTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ typedef NS_OPTIONS(NSUInteger, APContactField)
APContactFieldAddresses AP_DEPRECATED('APContactFieldAddressesOnly') = APContactFieldAddressesOnly,
APContactFieldSocialProfiles = 1 << 9,
APContactFieldBirthday = 1 << 10,
APContactFieldDates = 1 << 17,
APContactFieldWebsites = 1 << 11,
APContactFieldNote = 1 << 12,
APContactFieldRelatedPersons = 1 << 13,
APContactFieldLinkedRecordIDs = 1 << 14,
APContactFieldSource = 1 << 15,
APContactFieldRecordDate = 1 << 16,
APContactFieldDates = 1 << 16,
APContactFieldRecordDate = 1 << 17,
APContactFieldDefault = APContactFieldName | APContactFieldPhonesOnly,
APContactFieldAll = 0xFFFFFFFF
};
Expand Down
2 changes: 1 addition & 1 deletion Pod/Swift/APAddressBook-Bridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
#import "APRelatedPerson.h"
#import "APSource.h"
#import "APRecordDate.h"
#import "APDate.h"
#import "APContactDate.h"

0 comments on commit 8bf0077

Please sign in to comment.