/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts

« back to all changes in this revision

Viewing changes to src/am/ed/importcontacts/ContactsCache.java

  • Committer: edam
  • Date: 2012-12-20 16:49:39 UTC
  • Revision ID: tim@ed.am-20121220164939-j9mg98v0uofws7kw
added support for notes; rewrote backends so that all normalising of data is now done within the contacts cache; made the vCard unescape routine slightly more acceptant of non-standard escaped characters

Show diffs side-by-side

added added

removed removed

4
4
 * Copyright (C) 2011 to 2012 Tim Marston <tim@ed.am>
5
5
 *
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
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
36
36
         */
37
37
        public static class CacheIdentifier
38
38
        {
39
 
                public enum Type { NAME, ORGANISATION, PRIMARY_NUMBER, PRIMARY_EMAIL }
 
39
                public enum Type {
 
40
                        NONE, NAME, ORGANISATION, PRIMARY_NUMBER, PRIMARY_EMAIL }
40
41
 
41
42
                private Type _type;
42
43
                private String _detail;
43
44
 
 
45
                protected CacheIdentifier()
 
46
                {
 
47
                        _type = Type.NONE;
 
48
                }
 
49
 
44
50
                /**
45
51
                 * Obtain a cache identifier.  This routine is designed to be as robust
46
52
                 * as possible (in terms of bad or null detail values), and to return
47
53
                 * null when a cache identifier can not be created.
48
 
                 *
49
54
                 * @param type the detail type
50
55
                 * @param detail the detail
51
56
                 * @return the cache identifier, or null
68
73
                 * Obtain a cache identifier from contact data.  This routine is
69
74
                 * designed to be as robust as possible and may return null when a cache
70
75
                 * identifier can not be created.
71
 
                 *
72
76
                 * @param contact the contact data
73
77
                 * @return the cache identifier, or null
74
78
                 */
75
79
                public static CacheIdentifier factory( Importer.ContactData contact )
76
80
                {
77
 
                        CacheIdentifier identifier = null;
 
81
                        CacheIdentifier ret = null;
78
82
 
79
83
                        if( contact.hasName() )
80
 
                                identifier = factory( CacheIdentifier.Type.NAME,
 
84
                                ret = factory( CacheIdentifier.Type.NAME,
81
85
                                        contact.getName() );
82
 
                        if( identifier != null ) return identifier;
83
 
 
84
 
                        if( contact.hasPrimaryOrganisation() )
85
 
                                identifier = factory( CacheIdentifier.Type.ORGANISATION,
 
86
                        if( ret == null && contact.hasPrimaryOrganisation() )
 
87
                                ret = factory( CacheIdentifier.Type.ORGANISATION,
86
88
                                        contact.getPrimaryOrganisation() );
87
 
                        if( identifier != null ) return identifier;
88
 
 
89
 
                        if( contact.hasPrimaryNumber() )
90
 
                                identifier = factory( CacheIdentifier.Type.PRIMARY_NUMBER,
 
89
                        if( ret == null && contact.hasPrimaryNumber() )
 
90
                                ret = factory( CacheIdentifier.Type.PRIMARY_NUMBER,
91
91
                                        contact.getPrimaryNumber() );
92
 
                        if( identifier != null ) return identifier;
93
 
 
94
 
                        if( contact.hasPrimaryEmail() )
95
 
                                identifier = factory( CacheIdentifier.Type.PRIMARY_EMAIL,
 
92
                        if( ret == null && contact.hasPrimaryEmail() )
 
93
                                ret = factory( CacheIdentifier.Type.PRIMARY_EMAIL,
96
94
                                        contact.getPrimaryEmail() );
97
 
                        if( identifier != null ) return identifier;
98
95
 
99
 
                        return null;
 
96
                        return ret;
100
97
                }
101
98
 
102
99
                protected CacheIdentifier( Type type, String detail )
146
143
        /**
147
144
         * Retrieve the contact id of a contact identified by the specified cache
148
145
         * identifier, if it exists.
149
 
         *
150
146
         * @param identifier the cache identifier
151
147
         * @return a contact id, or null
152
148
         */
168
164
 
169
165
        /**
170
166
         * Remove any cache entry that is identified by the cache identifier.
171
 
         *
172
167
         * @param identifier the cache identifier
173
168
         * @return the contact id of the contact that was removed, or null
174
169
         */
190
185
 
191
186
        /**
192
187
         * Add a lookup from a contact identifier to a contact id to the cache.
193
 
         *
194
188
         * @param identifier the cache identifier
195
189
         * @param id teh contact id
196
190
         */
215
209
 
216
210
        /**
217
211
         * Remove any data that is associated with an contact id.
218
 
         *
219
212
         * @param id
220
213
         */
221
214
        public void removeAssociatedData( Long id )