4
* Copyright (C) 2011 to 2012 Tim Marston <tim@ed.am>
4
* Copyright (C) 2011 to 2013 Tim Marston <tim@ed.am>
6
6
* This file is part of the Import Contacts program (hereafter referred
7
* to as "this program"). For more information, see
7
* to as "this program"). For more information, see
8
8
* http://ed.am/dev/android/import-contacts
10
10
* This program is free software: you can redistribute it and/or modify
45
45
* Obtain a cache identifier. This routine is designed to be as robust
46
46
* as possible (in terms of bad or null detail values), and to return
47
47
* null when a cache identifier can not be created.
48
49
* @param type the detail type
49
50
* @param detail the detail
50
51
* @return the cache identifier, or null
67
68
* Obtain a cache identifier from contact data. This routine is
68
69
* designed to be as robust as possible and may return null when a cache
69
70
* identifier can not be created.
70
72
* @param contact the contact data
71
73
* @return the cache identifier, or null
73
75
public static CacheIdentifier factory( Importer.ContactData contact )
75
CacheIdentifier ret = null;
77
CacheIdentifier identifier = null;
77
79
if( contact.hasName() )
78
ret = factory( CacheIdentifier.Type.NAME,
80
identifier = factory( CacheIdentifier.Type.NAME,
79
81
contact.getName() );
80
if( ret == null && contact.hasPrimaryOrganisation() )
81
ret = factory( CacheIdentifier.Type.ORGANISATION,
82
if( identifier != null ) return identifier;
84
if( contact.hasPrimaryOrganisation() )
85
identifier = factory( CacheIdentifier.Type.ORGANISATION,
82
86
contact.getPrimaryOrganisation() );
83
if( ret == null && contact.hasPrimaryNumber() )
84
ret = factory( CacheIdentifier.Type.PRIMARY_NUMBER,
87
if( identifier != null ) return identifier;
89
if( contact.hasPrimaryNumber() )
90
identifier = factory( CacheIdentifier.Type.PRIMARY_NUMBER,
85
91
contact.getPrimaryNumber() );
86
if( ret == null && contact.hasPrimaryEmail() )
87
ret = factory( CacheIdentifier.Type.PRIMARY_EMAIL,
92
if( identifier != null ) return identifier;
94
if( contact.hasPrimaryEmail() )
95
identifier = factory( CacheIdentifier.Type.PRIMARY_EMAIL,
88
96
contact.getPrimaryEmail() );
97
if( identifier != null ) return identifier;
93
102
protected CacheIdentifier( Type type, String detail )
128
137
= new HashMap< Long, HashSet< String > >();
129
138
private HashMap< Long, HashSet< String > > _contactNotes
130
139
= new HashMap< Long, HashSet< String > >();
140
private HashMap< Long, String > _contactBirthdays
141
= new HashMap< Long, String >();
132
143
public boolean canLookup( CacheIdentifier identifier )
138
149
* Retrieve the contact id of a contact identified by the specified cache
139
150
* identifier, if it exists.
140
152
* @param identifier the cache identifier
141
153
* @return a contact id, or null
342
public boolean hasAssociatedBirthday( Long id, String birthday )
344
birthday = normaliseBirthday( birthday );
345
if( birthday == null ) return false;
347
String found = _contactBirthdays.get( id );
348
return found != null && found.equalsIgnoreCase( birthday );
351
public void addAssociatedBirthday( Long id, String birthday )
353
birthday = normaliseBirthday( birthday );
354
if( birthday == null ) return;
356
_contactBirthdays.put( id, birthday );
327
359
static public String normaliseName( String name )
329
361
if( name == null ) return null;
365
397
note = note.trim();
366
398
return note.length() > 0? note : null;
401
static public String normaliseBirthday( String birthday )
403
if( birthday == null ) return null;
404
birthday = birthday.trim();
405
return birthday.length() > 0? birthday : null;