/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: Tim Marston
  • Date: 2013-05-10 12:16:15 UTC
  • Revision ID: tim@ed.am-20130510121615-g8qhsu0h3t0ymrt6
Tags: 1.3.2
fix spacing in NEWS

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * Importer.java
3
3
 *
4
 
 * Copyright (C) 2009 to 2013 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2009 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
142
142
                protected HashMap< String, PreferredDetail > _emails = null;
143
143
                protected HashMap< String, TypeDetail > _addresses = null;
144
144
                protected HashSet< String > _notes = null;
145
 
                protected String _birthday = null;
146
145
 
147
146
                private ContactsCache.CacheIdentifier _cache_identifier = null;
148
147
 
186
185
 
187
186
                        // if this is the first organisation added, or it's a preferred
188
187
                        // organisation and the current primary organisation isn't, then
189
 
                        // record this as the primary organisation
 
188
                        // record this as the primary organisation.
190
189
                        if( _primary_organisation == null ||
191
190
                                ( is_preferred && !_primary_organisation_is_preferred ) )
192
191
                        {
240
239
                        // and the current primary number isn't, or this number is on equal
241
240
                        // standing with the primary number in terms of preference and it is
242
241
                        // a voice number and the primary number isn't, then record this as
243
 
                        // the primary number
 
242
                        // the primary number.
244
243
                        if( _primary_number == null ||
245
244
                                ( is_preferred && !_primary_number_is_preferred ) ||
246
245
                                ( is_preferred == _primary_number_is_preferred &&
292
291
 
293
292
                        // if this is the first email added, or it's a preferred email and
294
293
                        // the current primary organisation isn't, then record this as the
295
 
                        // primary email
 
294
                        // primary email.
296
295
                        if( _primary_email == null ||
297
296
                                ( is_preferred && !_primary_email_is_preferred ) )
298
297
                        {
363
362
                        return _notes;
364
363
                }
365
364
 
366
 
                public void setBirthday( String birthday )
367
 
                {
368
 
                        _birthday = birthday;
369
 
                }
370
 
 
371
 
                public boolean hasBirthday()
372
 
                {
373
 
                        return _birthday != null;
374
 
                }
375
 
 
376
 
                public String getBirthday()
377
 
                {
378
 
                        return _birthday;
379
 
                }
380
 
 
381
365
                protected void finalise()
382
366
                        throws ContactNotIdentifiableException
383
367
                {
384
 
                        // Ensure that if there is a primary number, it is preferred so
385
 
                        // that there is always one preferred number.  Android will assign
 
368
                        // ensure that if there is a primary number, it is preferred so
 
369
                        // that there is always one preferred number. Android will assign
386
370
                        // preference to one anyway so we might as well decide one sensibly.
387
371
                        if( _primary_number != null ) {
388
372
                                PreferredDetail data = _numbers.get( _primary_number );
643
627
        /**
644
628
         * Should we skip a contact, given whether it exists or not and the current
645
629
         * merge setting?  This routine handles throwing up a prompt, if required.
646
 
         *
647
630
         * @param contact_detail the display name of the contact
648
631
         * @param exists true if this contact matches one in the cache
649
632
         * @param merge_setting the merge setting to use
703
686
        {
704
687
                checkAbort();
705
688
 
706
 
                // It is expected that we use contact.getCacheIdentifier() here.  The
 
689
                // It is expected that we use contact.getCacheIdentifier() here. The
707
690
                // contact we are passed should have been successfully finalise()d,
708
691
                // which includes generating a valid cache identifier.
709
692
                ContactsCache.CacheIdentifier cache_identifier =
778
761
                                importContactOrganisations( id, contact.getOrganisations() );
779
762
                        if( contact.hasNotes() )
780
763
                                importContactNotes( id, contact.getNotes() );
781
 
                        if( contact.hasBirthday() )
782
 
                                importContactBirthday( id, contact.getBirthday() );
783
764
                }
784
765
                catch( Backend.ContactCreationException e )
785
766
                {
798
779
                        String number = i.next();
799
780
                        ContactData.PreferredDetail data = datas.get( number );
800
781
 
801
 
                        // We don't want to add this number if it's crap, or it already
802
 
                        // exists (which would cause a duplicate to be created).  We don't
803
 
                        // take in to account the type when checking for duplicates.  This
804
 
                        // is intentional: types aren't really very reliable.  We assume
805
 
                        // that if the number exists at all, it doesn't need importing.
806
 
                        // Because of this, we also can't update the cache (which we don't
807
 
                        // need to anyway, so it's not a problem).
 
782
                        // we don't want to add this number if it's crap, or it already
 
783
                        // exists (which would cause a duplicate to be created). We don't
 
784
                        // take in to account the type when checking for duplicates. This is
 
785
                        // intentional: types aren't really very reliable. We assume that
 
786
                        // if the number exists at all, it doesn't need importing. Because
 
787
                        // of this, we also can't update the cache (which we don't need to
 
788
                        // anyway, so it's not a problem).
808
789
                        if( _contacts_cache.hasAssociatedNumber( id, number ) )
809
790
                                continue;
810
791
 
829
810
                        ContactData.PreferredDetail data = datas.get( email );
830
811
 
831
812
                        // we don't want to add this email address if it exists already or
832
 
                        // we would introduce duplicates
 
813
                        // we would introduce duplicates.
833
814
                        if( _contacts_cache.hasAssociatedEmail( id, email ) )
834
815
                                continue;
835
816
 
892
873
                }
893
874
        }
894
875
 
895
 
        private void importContactNotes( Long id, HashSet< String > datas )
 
876
        private void importContactNotes( Long id,
 
877
                HashSet< String > datas )
896
878
                throws ContactCreationException
897
879
        {
898
880
                // add notes
912
894
                        // date from another file
913
895
                        _contacts_cache.addAssociatedNote( id, note );
914
896
                }
915
 
        }
916
 
 
917
 
        private void importContactBirthday( Long id, String birthday )
918
 
                throws ContactCreationException
919
 
        {
920
 
                // we don't want to import this birthday if it already exists
921
 
                if( _contacts_cache.hasAssociatedBirthday( id, birthday ) )
922
 
                        return;
923
 
 
924
 
                // add birthday
925
 
                _backend.addContactBirthday( id, birthday );
926
 
 
927
 
                // and update the cache
928
 
                _contacts_cache.addAssociatedBirthday( id, birthday );
 
897
 
929
898
        }
930
899
 
931
900
        synchronized protected void checkAbort() throws AbortImportException