/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/Importer.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

Lines of Context:
141
141
                protected HashMap< String, PreferredDetail > _numbers = null;
142
142
                protected HashMap< String, PreferredDetail > _emails = null;
143
143
                protected HashMap< String, TypeDetail > _addresses = null;
 
144
                protected HashSet< String > _notes = null;
144
145
 
145
146
                private ContactsCache.CacheIdentifier _cache_identifier = null;
146
147
 
344
345
                        return _addresses;
345
346
                }
346
347
 
 
348
                protected void addNote( String note )
 
349
                {
 
350
                        if( _notes == null ) _notes = new HashSet< String >();
 
351
                        if( !_notes.contains( note ) )
 
352
                                _notes.add( note );
 
353
                }
 
354
 
 
355
                public boolean hasNotes()
 
356
                {
 
357
                        return _notes != null && _notes.size() > 0;
 
358
                }
 
359
 
 
360
                public HashSet< String > getNotes()
 
361
                {
 
362
                        return _notes;
 
363
                }
 
364
 
347
365
                protected void finalise()
348
366
                        throws ContactNotIdentifiableException
349
367
                {
372
390
 
373
391
                        // create a cache identifier from this contact data, which can be
374
392
                        // used to look-up an existing contact
375
 
                        _cache_identifier = ContactsCache.createIdentifier( this );
 
393
                        _cache_identifier = ContactsCache.CacheIdentifier.factory( this );
376
394
                        if( _cache_identifier == null )
377
395
                                throw new ContactNotIdentifiableException();
378
396
                }
741
759
                                importContactAddresses( id, contact.getAddresses() );
742
760
                        if( contact.hasOrganisations() )
743
761
                                importContactOrganisations( id, contact.getOrganisations() );
 
762
                        if( contact.hasNotes() )
 
763
                                importContactNotes( id, contact.getNotes() );
744
764
                }
745
765
                catch( Backend.ContactCreationException e )
746
766
                {
853
873
                }
854
874
        }
855
875
 
 
876
        private void importContactNotes( Long id,
 
877
                HashSet< String > datas )
 
878
                throws ContactCreationException
 
879
        {
 
880
                // add notes
 
881
                Iterator< String > i = datas.iterator();
 
882
                while( i.hasNext() ) {
 
883
                        String note = i.next();
 
884
 
 
885
                        // we don't want to add this note if it exists already or we would
 
886
                        // introduce duplicates
 
887
                        if( _contacts_cache.hasAssociatedNote( id, note ) )
 
888
                                continue;
 
889
 
 
890
                        // add note
 
891
                        _backend.addContactNote( id, note );
 
892
 
 
893
                        // and add this note to the cache to prevent a addition of duplicate
 
894
                        // date from another file
 
895
                        _contacts_cache.addAssociatedNote( id, note );
 
896
                }
 
897
 
 
898
        }
 
899
 
856
900
        synchronized protected void checkAbort() throws AbortImportException
857
901
        {
858
902
                if( _abort ) {