mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 16:22:39 +00:00
-> Check if any contact contains a matrix email
-> display the Matrix icon at the right cell side.
This commit is contained in:
parent
dcb8badf91
commit
a1a5849881
13 changed files with 260 additions and 35 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
/* Begin PBXBuildFile section */
|
||||
710210A41A67A4B600364868 /* ConsoleGrowingTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 710210A31A67A4B600364868 /* ConsoleGrowingTextView.m */; };
|
||||
710CC3BF1A6E9F14006EE973 /* matrixUser.png in Resources */ = {isa = PBXBuildFile; fileRef = 710CC3BE1A6E9F14006EE973 /* matrixUser.png */; };
|
||||
71193D241A6D64F900E59A9E /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 71193D231A6D64F900E59A9E /* AddressBook.framework */; };
|
||||
71193D291A6E3DC000E59A9E /* ContactsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71193D281A6E3DC000E59A9E /* ContactsViewController.m */; };
|
||||
71193D2C1A6E433900E59A9E /* ContactTableCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 71193D2B1A6E433900E59A9E /* ContactTableCell.m */; };
|
||||
|
@ -80,8 +81,9 @@
|
|||
13057A57E74FD5504196F47F /* Pods-matrixConsole.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-matrixConsole.release.xcconfig"; path = "Pods/Target Support Files/Pods-matrixConsole/Pods-matrixConsole.release.xcconfig"; sourceTree = "<group>"; };
|
||||
710210A21A67A4B600364868 /* ConsoleGrowingTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConsoleGrowingTextView.h; sourceTree = "<group>"; };
|
||||
710210A31A67A4B600364868 /* ConsoleGrowingTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConsoleGrowingTextView.m; sourceTree = "<group>"; };
|
||||
710CC3BE1A6E9F14006EE973 /* matrixUser.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = matrixUser.png; sourceTree = "<group>"; };
|
||||
71193D231A6D64F900E59A9E /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
|
||||
71193D271A6E3DC000E59A9E /* ContactsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactsViewController.h; sourceTree = "<group>"; };
|
||||
71193D271A6E3DC000E59A9E /* ContactsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ContactsViewController.h; path = ViewController/ContactsViewController.h; sourceTree = "<group>"; };
|
||||
71193D281A6E3DC000E59A9E /* ContactsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactsViewController.m; sourceTree = "<group>"; };
|
||||
71193D2A1A6E433900E59A9E /* ContactTableCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactTableCell.h; sourceTree = "<group>"; };
|
||||
71193D2B1A6E433900E59A9E /* ContactTableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactTableCell.m; sourceTree = "<group>"; };
|
||||
|
@ -219,6 +221,7 @@
|
|||
F01628B519E298710071C473 /* Assets */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
710CC3BE1A6E9F14006EE973 /* matrixUser.png */,
|
||||
F030974A1A6580D70090BC00 /* icon_keyboard.png */,
|
||||
F030974B1A6580D70090BC00 /* icon_keyboard@2x.png */,
|
||||
F05C3A3C1A3F3D7F002B698E /* icon_users.png */,
|
||||
|
@ -255,7 +258,6 @@
|
|||
F03EF5E919F171EB00A0EE52 /* ViewController */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
71193D271A6E3DC000E59A9E /* ContactsViewController.h */,
|
||||
71193D281A6E3DC000E59A9E /* ContactsViewController.m */,
|
||||
F03EF5EA19F171EB00A0EE52 /* HomeViewController.h */,
|
||||
F03EF5EB19F171EB00A0EE52 /* HomeViewController.m */,
|
||||
|
@ -354,6 +356,7 @@
|
|||
F04EE51E1A3A01D500C64930 /* APNSHandler.m */,
|
||||
F07A80D919DD9DE700B621A1 /* AppDelegate.h */,
|
||||
F07A80DA19DD9DE700B621A1 /* AppDelegate.m */,
|
||||
71193D271A6E3DC000E59A9E /* ContactsViewController.h */,
|
||||
F0D3C30A1A011EF10000D49E /* AppSettings.h */,
|
||||
F0D3C30B1A011EF10000D49E /* AppSettings.m */,
|
||||
F03C470F1A02952800E445AB /* CustomAlert.h */,
|
||||
|
@ -485,6 +488,7 @@
|
|||
F07A80E919DD9DE700B621A1 /* LaunchScreen.xib in Resources */,
|
||||
F0CEA5AF19E6895E00E47915 /* tab_recents.png in Resources */,
|
||||
F030974D1A6580D70090BC00 /* icon_keyboard@2x.png in Resources */,
|
||||
710CC3BF1A6E9F14006EE973 /* matrixUser.png in Resources */,
|
||||
F030974C1A6580D70090BC00 /* icon_keyboard.png in Resources */,
|
||||
F05C3A3F1A3F3D7F002B698E /* icon_users@2x.png in Resources */,
|
||||
F01628C319E29C660071C473 /* logo.png in Resources */,
|
||||
|
|
BIN
matrixConsole/Assets/matrixUser.png
Executable file
BIN
matrixConsole/Assets/matrixUser.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 373 B |
|
@ -1371,14 +1371,16 @@
|
|||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="B4B-GZ-atv" customClass="CustomImageView">
|
||||
<rect key="frame" x="16" y="7" width="30" height="30"/>
|
||||
<rect key="frame" x="12" y="3" width="38" height="38"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<color key="tintColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="30" id="F3r-c8-zTQ"/>
|
||||
<constraint firstAttribute="width" constant="30" id="ewx-39-TQ9"/>
|
||||
<constraint firstAttribute="height" constant="38" id="F3r-c8-zTQ"/>
|
||||
<constraint firstAttribute="width" constant="38" id="ewx-39-TQ9"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nzg-dr-os0">
|
||||
<rect key="frame" x="58" y="8" width="526" height="30"/>
|
||||
<rect key="frame" x="62" y="8" width="510" height="30"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="30" id="92u-Am-XY3"/>
|
||||
</constraints>
|
||||
|
@ -1386,17 +1388,28 @@
|
|||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="matrixUser.png" translatesAutoresizingMaskIntoConstraints="NO" id="fJ6-gD-7yP">
|
||||
<rect key="frame" x="576" y="14" width="16" height="16"/>
|
||||
<color key="tintColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="16" id="RkA-cA-qCQ"/>
|
||||
<constraint firstAttribute="height" constant="16" id="Y21-Gt-uRM"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="B4B-GZ-atv" firstAttribute="leading" secondItem="uEH-gd-MNN" secondAttribute="leadingMargin" constant="8" id="9iE-X4-ZUS"/>
|
||||
<constraint firstAttribute="centerY" secondItem="fJ6-gD-7yP" secondAttribute="centerY" id="2Su-DN-jCW"/>
|
||||
<constraint firstItem="B4B-GZ-atv" firstAttribute="leading" secondItem="uEH-gd-MNN" secondAttribute="leadingMargin" constant="4" id="9iE-X4-ZUS"/>
|
||||
<constraint firstAttribute="centerY" secondItem="B4B-GZ-atv" secondAttribute="centerY" id="HhS-o6-BrA"/>
|
||||
<constraint firstItem="nzg-dr-os0" firstAttribute="top" secondItem="uEH-gd-MNN" secondAttribute="topMargin" id="M18-xH-iYO"/>
|
||||
<constraint firstItem="nzg-dr-os0" firstAttribute="leading" secondItem="B4B-GZ-atv" secondAttribute="trailing" constant="12" id="hNL-Kh-Wga"/>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="nzg-dr-os0" secondAttribute="trailing" constant="8" id="x1k-qP-Mig"/>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="fJ6-gD-7yP" secondAttribute="trailing" id="pYO-iK-Sb7"/>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="nzg-dr-os0" secondAttribute="trailing" constant="20" id="x1k-qP-Mig"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<connections>
|
||||
<outlet property="contactDisplayName" destination="nzg-dr-os0" id="2Ce-Xv-mPM"/>
|
||||
<outlet property="matrixUserIconView" destination="fJ6-gD-7yP" id="hBT-VO-KJD"/>
|
||||
<outlet property="thumbnail" destination="B4B-GZ-atv" id="jDt-mM-3TL"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
|
@ -1436,6 +1449,7 @@
|
|||
<image name="icon_keyboard.png" width="20" height="20"/>
|
||||
<image name="icon_users.png" width="35" height="25"/>
|
||||
<image name="logoHighRes.png" width="480" height="204"/>
|
||||
<image name="matrixUser.png" width="16" height="16"/>
|
||||
<image name="play.png" width="64" height="64"/>
|
||||
<image name="tab_home.ico" width="16" height="16"/>
|
||||
</resources>
|
||||
|
|
|
@ -17,20 +17,28 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import <AddressBook/AddressBook.h>
|
||||
|
||||
// warn when a contact has a new matrix identifier
|
||||
// the contactID is provided in parameter
|
||||
extern NSString *const kConsoleContactMatrixIdentifierUpdateNotification;
|
||||
|
||||
@interface ConsoleContact : NSObject
|
||||
|
||||
// unique identifier
|
||||
@property (nonatomic, copy, readwrite) NSString * contactID;
|
||||
// display name
|
||||
@property (nonatomic, copy, readwrite) NSString *displayName;
|
||||
|
||||
// contact thumbnail
|
||||
@property (nonatomic, copy, readwrite) UIImage *thumbnail;
|
||||
|
||||
// array of ConsolePhoneNumber
|
||||
@property (nonatomic, readwrite) NSArray *phoneNumbers;
|
||||
// array of ConsoleEmail
|
||||
@property (nonatomic, readwrite) NSArray *emailAddresses;
|
||||
// array of strings
|
||||
// array of ConsoleContact / ConsoleEmail with contains a matrix identifer
|
||||
@property (nonatomic, readonly) NSArray* matrixIdentifiers;
|
||||
|
||||
- (id) initWithABRecord:(ABRecordRef)record;
|
||||
- (id)initWithABRecord:(ABRecordRef)record;
|
||||
|
||||
// check if there is any matrix identifier updates
|
||||
- (void)checkMatrixIdentifiers;
|
||||
|
||||
@end
|
|
@ -16,24 +16,31 @@
|
|||
|
||||
#import "ConsoleContact.h"
|
||||
|
||||
// warn when a contact has a new matrix identifier
|
||||
// the contactID is provided in parameter
|
||||
NSString *const kConsoleContactMatrixIdentifierUpdateNotification = @"kConsoleContactMatrixIdentifierUpdateNotification";
|
||||
|
||||
#import "ConsoleEmail.h"
|
||||
#import "ConsolePhoneNumber.h"
|
||||
|
||||
@implementation ConsoleContact
|
||||
@synthesize displayName, phoneNumbers, emailAddresses, thumbnail;
|
||||
@synthesize displayName, phoneNumbers, emailAddresses, thumbnail, contactID;
|
||||
|
||||
- (id) initWithABRecord:(ABRecordRef)record {
|
||||
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
|
||||
|
||||
// compute a contact ID
|
||||
self.contactID = [NSString stringWithFormat:@"%d", ABRecordGetRecordID(record)];
|
||||
|
||||
// use the contact book display name
|
||||
self.displayName = (__bridge NSString*) ABRecordCopyCompositeName(record);
|
||||
|
||||
// avoid nil display name
|
||||
// the display name is used to sort contacts
|
||||
if (!self.displayName) {
|
||||
self.displayName = @"";
|
||||
displayName = @"";
|
||||
}
|
||||
|
||||
// extract the phone numbers and their related label
|
||||
|
@ -86,7 +93,7 @@
|
|||
}
|
||||
|
||||
CFRelease(multi);
|
||||
self.phoneNumbers = pns;
|
||||
phoneNumbers = pns;
|
||||
|
||||
// extract the emails
|
||||
multi = ABRecordCopyValue(record, kABPersonEmailProperty);
|
||||
|
@ -120,10 +127,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
ConsoleEmail* email = [[ConsoleEmail alloc] init];
|
||||
email.type = lbl;
|
||||
email.emailAddress = emailVal;
|
||||
|
||||
ConsoleEmail* email = [[ConsoleEmail alloc] initWithEmailAddress:emailVal andType:lbl within:self.contactID];
|
||||
[emails addObject: email];
|
||||
|
||||
if (lblRef) {
|
||||
|
@ -142,7 +146,7 @@
|
|||
|
||||
CFRelease(multi);
|
||||
|
||||
self.emailAddresses = emails;
|
||||
emailAddresses = emails;
|
||||
|
||||
// thumbnail/picture
|
||||
// check whether the contact has a picture
|
||||
|
@ -153,10 +157,14 @@
|
|||
dataRef = ABPersonCopyImageDataWithFormat(record, kABPersonImageFormatThumbnail);
|
||||
if (dataRef)
|
||||
{
|
||||
self.thumbnail = [UIImage imageWithData:(__bridge NSData*)dataRef];
|
||||
thumbnail = [UIImage imageWithData:(__bridge NSData*)dataRef];
|
||||
CFRelease(dataRef);
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{
|
||||
[self checkMatrixIdentifiers];
|
||||
});
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -165,18 +173,28 @@
|
|||
NSMutableArray* identifiers = [[NSMutableArray alloc] init];
|
||||
|
||||
for(ConsolePhoneNumber* pn in self.phoneNumbers) {
|
||||
if (pn.isMatrixIdentifier) {
|
||||
[identifiers addObject:pn.textNumber];
|
||||
if (pn.matrixUserID) {
|
||||
[identifiers addObject:pn];
|
||||
}
|
||||
}
|
||||
|
||||
for(ConsoleEmail* email in self.emailAddresses) {
|
||||
if (email.isMatrixIdentifier) {
|
||||
[identifiers addObject:email.emailAddress];
|
||||
if (email.matrixUserID) {
|
||||
[identifiers addObject:email];
|
||||
}
|
||||
}
|
||||
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
- (void)checkMatrixIdentifiers {
|
||||
for(ConsolePhoneNumber* pn in self.phoneNumbers) {
|
||||
[pn getMatrixID];
|
||||
}
|
||||
|
||||
for(ConsoleEmail* email in self.emailAddresses) {
|
||||
[email getMatrixID];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -16,10 +16,17 @@
|
|||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface ConsoleEmail : NSObject
|
||||
@interface ConsoleEmail : NSObject {
|
||||
BOOL pendingMatrixIDRequest;
|
||||
BOOL gotMatrixID;
|
||||
}
|
||||
|
||||
@property (nonatomic, readwrite) NSString *type;
|
||||
@property (nonatomic, readwrite) NSString *emailAddress;
|
||||
@property (nonatomic, readwrite) BOOL isMatrixIdentifier;
|
||||
@property (nonatomic, readwrite) NSString *contactID;
|
||||
@property (nonatomic, readwrite) NSString *matrixUserID;
|
||||
|
||||
- (id)initWithEmailAddress:(NSString*)anEmailAddress andType:(NSString*)aType within:(NSString*)aContactID;
|
||||
|
||||
- (void)getMatrixID;
|
||||
@end
|
||||
|
|
|
@ -13,9 +13,77 @@
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import "ConsoleEmail.h"
|
||||
#import "MatrixHandler.h"
|
||||
|
||||
#import "ConsoleContact.h"
|
||||
|
||||
@implementation ConsoleEmail
|
||||
@synthesize type, emailAddress, contactID, matrixUserID;
|
||||
|
||||
- (id)init {
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
// init statuses
|
||||
gotMatrixID = NO;
|
||||
pendingMatrixIDRequest = NO;
|
||||
|
||||
// init members
|
||||
self.emailAddress = nil;
|
||||
self.type = nil;
|
||||
self.contactID = nil;
|
||||
self.matrixUserID = nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithEmailAddress:(NSString*)anEmailAddress andType:(NSString*)aType within:(NSString*)aContactID {
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
self.emailAddress = anEmailAddress;
|
||||
self.type = aType;
|
||||
self.contactID = aContactID;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)getMatrixID {
|
||||
|
||||
// sanity check
|
||||
if ((self.emailAddress.length > 0) && (self.contactID.length > 0)) {
|
||||
|
||||
// check if the matrix id was not requested
|
||||
if (!gotMatrixID && !pendingMatrixIDRequest) {
|
||||
MatrixHandler *matrix = [MatrixHandler sharedHandler];
|
||||
|
||||
if (matrix.mxRestClient) {
|
||||
pendingMatrixIDRequest = YES;
|
||||
|
||||
[matrix.mxRestClient lookup3pid:self.emailAddress
|
||||
forMedium:@"email"
|
||||
success:^(NSString *userId) {
|
||||
pendingMatrixIDRequest = NO;
|
||||
self.matrixUserID = userId;
|
||||
gotMatrixID = YES;
|
||||
|
||||
if (self.matrixUserID) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kConsoleContactMatrixIdentifierUpdateNotification object:self.contactID userInfo:nil];
|
||||
});
|
||||
}
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
pendingMatrixIDRequest = NO;
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@synthesize type, emailAddress, isMatrixIdentifier;
|
||||
@end
|
||||
|
|
|
@ -17,8 +17,12 @@
|
|||
|
||||
@interface ConsolePhoneNumber : NSObject
|
||||
|
||||
@property (nonatomic, readwrite) NSString *type;
|
||||
@property (nonatomic, readwrite) NSString *textNumber;
|
||||
@property (nonatomic, readwrite) BOOL isMatrixIdentifier;
|
||||
@property (nonatomic, readwrite) NSString *type;
|
||||
@property (nonatomic, readwrite) NSString *textNumber;
|
||||
@property (nonatomic, readwrite) NSString *contactID;
|
||||
@property (nonatomic, readwrite) NSString *matrixUserID;
|
||||
|
||||
- (id)initWithTextNumber:(NSString*)textNumber andType:(NSString*)aType within:(NSString*)aContactID;
|
||||
|
||||
- (void)getMatrixID;
|
||||
@end
|
|
@ -17,5 +17,23 @@
|
|||
#import "ConsolePhoneNumber.h"
|
||||
|
||||
@implementation ConsolePhoneNumber
|
||||
@synthesize type, textNumber, isMatrixIdentifier;
|
||||
@synthesize type, textNumber, contactID, matrixUserID;
|
||||
|
||||
- (id)initWithTextNumber:(NSString*)aTextNumber andType:(NSString*)aType within:(NSString*)aContactID {
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
self.type = aType;
|
||||
self.textNumber = aTextNumber;
|
||||
self.contactID = aContactID;
|
||||
self.matrixUserID = nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)getMatrixID {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@end
|
|
@ -16,9 +16,16 @@
|
|||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "CustomImageView.h"
|
||||
#import "ConsoleContact.h"
|
||||
|
||||
@interface ContactTableCell : UITableViewCell
|
||||
|
||||
@property (strong, nonatomic) IBOutlet CustomImageView *thumbnail;
|
||||
@property (strong, nonatomic) IBOutlet UILabel *contactDisplayName;
|
||||
@property (strong, nonatomic) IBOutlet UIImageView *matrixUserIconView;
|
||||
|
||||
// reference to the linked message
|
||||
@property (strong, nonatomic) ConsoleContact *contact;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -17,4 +17,32 @@
|
|||
#import "ContactTableCell.h"
|
||||
|
||||
@implementation ContactTableCell
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (void)setContact:(ConsoleContact *)aContact {
|
||||
_contact = aContact;
|
||||
|
||||
[_contact checkMatrixIdentifiers];
|
||||
self.matrixUserIconView.hidden = (0 == aContact.matrixIdentifiers.count);
|
||||
|
||||
// remove any pending observers
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMatrixIdUpdate:) name:kConsoleContactMatrixIdentifierUpdateNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)onMatrixIdUpdate:(NSNotification *)notif {
|
||||
// sanity check
|
||||
if ([notif.object isKindOfClass:[NSString class]]) {
|
||||
NSString* matrixID = notif.object;
|
||||
|
||||
if ([matrixID isEqualToString:self.contact.contactID]) {
|
||||
self.matrixUserIconView.hidden = (0 == _contact.matrixIdentifiers.count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
@interface ContactsViewController : UITableViewController <UINavigationControllerDelegate> {
|
||||
SectionedContacts *sectionedContacts;
|
||||
|
||||
NSArray* collationTitles;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -27,7 +27,10 @@
|
|||
[super viewDidLoad];
|
||||
|
||||
sectionedContacts = nil;
|
||||
|
||||
|
||||
// get the system collation titles
|
||||
collationTitles = [[UILocalizedIndexedCollation currentCollation]sectionTitles];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onContactsRefresh:) name:kContactManagerRefreshNotification object:nil];
|
||||
}
|
||||
|
||||
|
@ -55,6 +58,48 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)aTableView
|
||||
{
|
||||
NSMutableArray* titles = [[NSMutableArray alloc] initWithCapacity:10];
|
||||
|
||||
[titles addObjectsFromArray:[[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]];
|
||||
|
||||
// force the background color
|
||||
if ([self.tableView respondsToSelector:@selector(setSectionIndexBackgroundColor:)]) {
|
||||
[self.tableView setSectionIndexBackgroundColor:[UIColor clearColor]];
|
||||
}
|
||||
|
||||
return titles;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)aTableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
|
||||
{
|
||||
NSUInteger section;
|
||||
|
||||
@synchronized(self)
|
||||
{
|
||||
section = [sectionedContacts.sectionTitles indexOfObject:title];
|
||||
}
|
||||
|
||||
// undefined title -> jump to the first valid non empty section
|
||||
if (NSNotFound == section) {
|
||||
NSUInteger systemCollationIndex = [collationTitles indexOfObject:title];
|
||||
|
||||
// find in the system collation
|
||||
if (NSNotFound != systemCollationIndex) {
|
||||
systemCollationIndex--;
|
||||
|
||||
while ((systemCollationIndex == 0) && (NSNotFound == section)) {
|
||||
NSString* systemTitle = [collationTitles objectAtIndex:systemCollationIndex];
|
||||
section = [sectionedContacts.sectionTitles indexOfObject:systemTitle];
|
||||
systemCollationIndex--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
ContactTableCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ContactCell" forIndexPath:indexPath];
|
||||
|
||||
|
@ -68,6 +113,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
cell.contact = contact;
|
||||
|
||||
// set the thumbnail
|
||||
if (contact.thumbnail) {
|
||||
cell.thumbnail.image = contact.thumbnail;
|
||||
|
|
Loading…
Reference in a new issue