From 8bf007797eb86fcd7546dd5e723f2ebe43835cf1 Mon Sep 17 00:00:00 2001 From: Alexey Belkevich Date: Thu, 14 Jan 2016 22:47:55 +0200 Subject: [PATCH] Refactored contact dates extraction Renamed 'APDate' to 'APContactDate' --- .../AddressBook.xcodeproj/project.pbxproj | 6 ++++ Pod/Core/Private/Builders/APContactBuilder.m | 8 ++--- .../Extractors/APContactDataExtractor.h | 2 +- .../Extractors/APContactDataExtractor.m | 36 +++++++++---------- Pod/Core/Public/Models/APContact.h | 4 +-- .../Models/{APDate.h => APContactDate.h} | 6 ++-- Pod/Core/Public/Models/APContactDate.m | 13 +++++++ Pod/Core/Public/Models/APDate.m | 13 ------- Pod/Core/Public/Models/APEmail.h | 2 +- Pod/Core/Public/Models/APEmail.m | 2 +- Pod/Core/Public/Models/APJob.h | 2 +- Pod/Core/Public/Models/APJob.m | 2 +- Pod/Core/Public/Models/APName.h | 2 +- Pod/Core/Public/Models/APName.m | 2 +- Pod/Core/Public/Models/APRecordDate.h | 2 +- Pod/Core/Public/Models/APRecordDate.m | 2 +- Pod/Core/Public/Models/APSource.h | 2 +- Pod/Core/Public/Models/APSource.m | 2 +- Pod/Core/Public/Models/APTypes.h | 4 +-- Pod/Swift/APAddressBook-Bridging.h | 2 +- 20 files changed, 60 insertions(+), 54 deletions(-) rename Pod/Core/Public/Models/{APDate.h => APContactDate.h} (79%) create mode 100644 Pod/Core/Public/Models/APContactDate.m delete mode 100644 Pod/Core/Public/Models/APDate.m diff --git a/Example/Objective-C/AddressBook.xcodeproj/project.pbxproj b/Example/Objective-C/AddressBook.xcodeproj/project.pbxproj index 0b989d0..9c05001 100644 --- a/Example/Objective-C/AddressBook.xcodeproj/project.pbxproj +++ b/Example/Objective-C/AddressBook.xcodeproj/project.pbxproj @@ -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 */; }; @@ -51,6 +52,7 @@ 2DBA11586D1BD36B84E8D9B0 /* APAddressBookAccessRoutine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APAddressBookAccessRoutine.h; sourceTree = ""; }; 2DBA11ABCAF3BCAD3D9B4E0D /* APImageExtractor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APImageExtractor.h; sourceTree = ""; }; 2DBA12274B8BFA605F110B91 /* APAddressBookAccessRoutine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APAddressBookAccessRoutine.m; sourceTree = ""; }; + 2DBA12402A8EE654AD2FD70A /* APContactDate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APContactDate.m; sourceTree = ""; }; 2DBA125B051EE9D46F45C505 /* APThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APThread.m; sourceTree = ""; }; 2DBA12CDF576C49EAEB83108 /* APPhone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APPhone.h; sourceTree = ""; }; 2DBA12D09D8CD39546DE39A8 /* APDeprecated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APDeprecated.h; sourceTree = ""; }; @@ -87,6 +89,7 @@ 2DBA1CAE20F58C7157F9C097 /* APAddressBookBaseRoutine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APAddressBookBaseRoutine.h; sourceTree = ""; }; 2DBA1CE66C6D93542A66D6CC /* APAddressBookRefWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APAddressBookRefWrapper.m; sourceTree = ""; }; 2DBA1D50E367D26256BF6ACE /* APSocialServiceHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APSocialServiceHelper.m; sourceTree = ""; }; + 2DBA1D597A4DD560AEAD0FEA /* APContactDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APContactDate.h; sourceTree = ""; }; 2DBA1DD07C5A43B4DD3EA17A /* APContactBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APContactBuilder.h; sourceTree = ""; }; 2DBA1DD6DF0D8A85F333FBD3 /* APContactListBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APContactListBuilder.m; sourceTree = ""; }; 2DBA1F4B68223450E5314F03 /* APRecordDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APRecordDate.h; sourceTree = ""; }; @@ -251,6 +254,8 @@ 2DBA19CDD95005EF506993AF /* APJob.h */, 2DBA19D573D9CD2762141F22 /* APRecordDate.m */, 2DBA1F4B68223450E5314F03 /* APRecordDate.h */, + 2DBA1D597A4DD560AEAD0FEA /* APContactDate.h */, + 2DBA12402A8EE654AD2FD70A /* APContactDate.m */, ); path = Models; sourceTree = ""; @@ -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; }; diff --git a/Pod/Core/Private/Builders/APContactBuilder.m b/Pod/Core/Private/Builders/APContactBuilder.m index 34e3530..1d976d1 100644 --- a/Pod/Core/Private/Builders/APContactBuilder.m +++ b/Pod/Core/Private/Builders/APContactBuilder.m @@ -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]; @@ -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]; diff --git a/Pod/Core/Private/Extractors/APContactDataExtractor.h b/Pod/Core/Private/Extractors/APContactDataExtractor.h index f2e5f26..c5135ee 100644 --- a/Pod/Core/Private/Extractors/APContactDataExtractor.h +++ b/Pod/Core/Private/Extractors/APContactDataExtractor.h @@ -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; diff --git a/Pod/Core/Private/Extractors/APContactDataExtractor.m b/Pod/Core/Private/Extractors/APContactDataExtractor.m index 7bc2ad7..e9ba3de 100644 --- a/Pod/Core/Private/Extractors/APContactDataExtractor.m +++ b/Pod/Core/Private/Extractors/APContactDataExtractor.m @@ -17,7 +17,7 @@ #import "APSource.h" #import "APRelatedPerson.h" #import "APRecordDate.h" -#import "APDate.h" +#import "APContactDate.h" @implementation APContactDataExtractor @@ -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; @@ -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]; diff --git a/Pod/Core/Public/Models/APContact.h b/Pod/Core/Public/Models/APContact.h index e76253e..3f8ad64 100755 --- a/Pod/Core/Public/Models/APContact.h +++ b/Pod/Core/Public/Models/APContact.h @@ -17,7 +17,7 @@ #import "APRelatedPerson.h" #import "APSource.h" #import "APRecordDate.h" -#import "APDate.h" +#import "APContactDate.h" @interface APContact : NSObject @@ -30,12 +30,12 @@ @property (nullable, nonatomic, strong) NSArray *addresses; @property (nullable, nonatomic, strong) NSArray *socialProfiles; @property (nullable, nonatomic, strong) NSDate *birthday; -@property (nullable, nonatomic, strong) NSArray *dates; @property (nullable, nonatomic, strong) NSString *note; @property (nullable, nonatomic, strong) NSArray *websites; @property (nullable, nonatomic, strong) NSArray *relatedPersons; @property (nullable, nonatomic, strong) NSArray *linkedRecordIDs; @property (nullable, nonatomic, strong) APSource *source; +@property (nullable, nonatomic, strong) NSArray *dates; @property (nullable, nonatomic, strong) APRecordDate *recordDate; @end diff --git a/Pod/Core/Public/Models/APDate.h b/Pod/Core/Public/Models/APContactDate.h similarity index 79% rename from Pod/Core/Public/Models/APDate.h rename to Pod/Core/Public/Models/APContactDate.h index 08190b1..87ff841 100644 --- a/Pod/Core/Public/Models/APDate.h +++ b/Pod/Core/Public/Models/APContactDate.h @@ -1,6 +1,6 @@ // -// APDate.h -// Pods +// APContactDate.h +// APAddressBook // // Created by Alexandre Plisson on 14/01/2016. // @@ -8,7 +8,7 @@ #import -@interface APDate : NSObject +@interface APContactDate : NSObject @property (nullable, nonatomic, strong) NSDate *date; @property (nullable, nonatomic, strong) NSString *originalLabel; diff --git a/Pod/Core/Public/Models/APContactDate.m b/Pod/Core/Public/Models/APContactDate.m new file mode 100644 index 0000000..e4b56be --- /dev/null +++ b/Pod/Core/Public/Models/APContactDate.m @@ -0,0 +1,13 @@ +// +// APContactDate.m +// APAddressBook +// +// Created by Alexandre Plisson on 14/01/2016. +// +// + +#import "APContactDate.h" + +@implementation APContactDate + +@end diff --git a/Pod/Core/Public/Models/APDate.m b/Pod/Core/Public/Models/APDate.m deleted file mode 100644 index f391978..0000000 --- a/Pod/Core/Public/Models/APDate.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// APDate.m -// Pods -// -// Created by Alexandre Plisson on 14/01/2016. -// -// - -#import "APDate.h" - -@implementation APDate - -@end diff --git a/Pod/Core/Public/Models/APEmail.h b/Pod/Core/Public/Models/APEmail.h index b862964..95e464d 100644 --- a/Pod/Core/Public/Models/APEmail.h +++ b/Pod/Core/Public/Models/APEmail.h @@ -1,6 +1,6 @@ // // APEmail.h -// AddressBook +// APAddressBook // // Created by Sean Langley on 2015-03-18. // Copyright (c) 2015 Sean Langley. All rights reserved. diff --git a/Pod/Core/Public/Models/APEmail.m b/Pod/Core/Public/Models/APEmail.m index fa02f3c..bf08d70 100644 --- a/Pod/Core/Public/Models/APEmail.m +++ b/Pod/Core/Public/Models/APEmail.m @@ -1,6 +1,6 @@ // // APEmail.m -// AddressBook +// APAddressBook // // Created by Sean Langley on 2015-03-18. // Copyright (c) 2015 Sean Langley. All rights reserved. diff --git a/Pod/Core/Public/Models/APJob.h b/Pod/Core/Public/Models/APJob.h index e30fcef..be9e1f4 100644 --- a/Pod/Core/Public/Models/APJob.h +++ b/Pod/Core/Public/Models/APJob.h @@ -1,6 +1,6 @@ // // APJob -// AddressBook +// APAddressBook // // Created by Alexey Belkevich on 05.10.15. // Copyright © 2015 alterplay. All rights reserved. diff --git a/Pod/Core/Public/Models/APJob.m b/Pod/Core/Public/Models/APJob.m index 9b6622d..bb94a33 100644 --- a/Pod/Core/Public/Models/APJob.m +++ b/Pod/Core/Public/Models/APJob.m @@ -1,6 +1,6 @@ // // APJob -// AddressBook +// APAddressBook // // Created by Alexey Belkevich on 05.10.15. // Copyright © 2015 alterplay. All rights reserved. diff --git a/Pod/Core/Public/Models/APName.h b/Pod/Core/Public/Models/APName.h index 04f0dcc..724fa90 100644 --- a/Pod/Core/Public/Models/APName.h +++ b/Pod/Core/Public/Models/APName.h @@ -1,6 +1,6 @@ // // APName -// AddressBook +// APAddressBook // // Created by Alexey Belkevich on 05.10.15. // Copyright © 2015 alterplay. All rights reserved. diff --git a/Pod/Core/Public/Models/APName.m b/Pod/Core/Public/Models/APName.m index bd49354..f0745dd 100644 --- a/Pod/Core/Public/Models/APName.m +++ b/Pod/Core/Public/Models/APName.m @@ -1,6 +1,6 @@ // // APName -// AddressBook +// APAddressBook // // Created by Alexey Belkevich on 05.10.15. // Copyright © 2015 alterplay. All rights reserved. diff --git a/Pod/Core/Public/Models/APRecordDate.h b/Pod/Core/Public/Models/APRecordDate.h index b303a97..7980c52 100644 --- a/Pod/Core/Public/Models/APRecordDate.h +++ b/Pod/Core/Public/Models/APRecordDate.h @@ -1,6 +1,6 @@ // // APRecordDate -// AddressBook +// APAddressBook // // Created by Alexey Belkevich on 05.10.15. // Copyright © 2015 alterplay. All rights reserved. diff --git a/Pod/Core/Public/Models/APRecordDate.m b/Pod/Core/Public/Models/APRecordDate.m index aea4c9d..c8fdebd 100644 --- a/Pod/Core/Public/Models/APRecordDate.m +++ b/Pod/Core/Public/Models/APRecordDate.m @@ -1,6 +1,6 @@ // // APRecordDate -// AddressBook +// APAddressBook // // Created by Alexey Belkevich on 05.10.15. // Copyright © 2015 alterplay. All rights reserved. diff --git a/Pod/Core/Public/Models/APSource.h b/Pod/Core/Public/Models/APSource.h index 8b96e99..8a59e79 100644 --- a/Pod/Core/Public/Models/APSource.h +++ b/Pod/Core/Public/Models/APSource.h @@ -1,6 +1,6 @@ // // APSource -// AddressBook +// APAddressBook // // Created by Alexey Belkevich on 23.09.15. // Copyright © 2015 alterplay. All rights reserved. diff --git a/Pod/Core/Public/Models/APSource.m b/Pod/Core/Public/Models/APSource.m index 100bcf2..9062435 100644 --- a/Pod/Core/Public/Models/APSource.m +++ b/Pod/Core/Public/Models/APSource.m @@ -1,6 +1,6 @@ // // APSource -// AddressBook +// APAddressBook // // Created by Alexey Belkevich on 23.09.15. // Copyright © 2015 alterplay. All rights reserved. diff --git a/Pod/Core/Public/Models/APTypes.h b/Pod/Core/Public/Models/APTypes.h index 764dcca..309d643 100644 --- a/Pod/Core/Public/Models/APTypes.h +++ b/Pod/Core/Public/Models/APTypes.h @@ -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 }; diff --git a/Pod/Swift/APAddressBook-Bridging.h b/Pod/Swift/APAddressBook-Bridging.h index ab6c176..3cb2ef2 100644 --- a/Pod/Swift/APAddressBook-Bridging.h +++ b/Pod/Swift/APAddressBook-Bridging.h @@ -20,4 +20,4 @@ #import "APRelatedPerson.h" #import "APSource.h" #import "APRecordDate.h" -#import "APDate.h" +#import "APContactDate.h"