/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-06-22 17:29:31 UTC
  • Revision ID: tim@ed.am-20130622172931-ujydoni23t3a543b
minor style tweaks

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
7
 * to as "this program").  For more information, see
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
 
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
                {
433
417
                        Matcher m = p.matcher( email );
434
418
                        if( m.matches() ) {
435
419
                                String[] bits = email.split( "@" );
436
 
                                return bits[ 0 ] + "@" +
437
 
                                        bits[ 1 ].toLowerCase( Locale.ENGLISH );
 
420
                                return bits[ 0 ] + "@" + bits[ 1 ].toLowerCase( Locale.US );
438
421
                        }
439
422
                        return null;
440
423
                }
544
527
                finish( ACTION_ABORT );
545
528
        }
546
529
 
547
 
        protected void showContinueOrAbort( int res ) throws AbortImportException
548
 
        {
549
 
                showContinueOrAbort( _doit.getText( res ).toString() );
550
 
        }
551
 
 
552
 
        synchronized protected void showContinueOrAbort( String message )
 
530
        protected void showFatalError( int res ) throws AbortImportException
 
531
        {
 
532
                showFatalError( _doit.getText( res ).toString() );
 
533
        }
 
534
 
 
535
        synchronized protected void showFatalError( String message )
 
536
                        throws AbortImportException
 
537
        {
 
538
                checkAbort();
 
539
                _doit._handler.sendMessage( Message.obtain(
 
540
                        _doit._handler, Doit.MESSAGE_ERROR, message ) );
 
541
                try {
 
542
                        wait();
 
543
                }
 
544
                catch( InterruptedException e ) { }
 
545
 
 
546
                // no need to check if an abortion happened during the wait, we are
 
547
                // about to finish anyway!
 
548
                finish( ACTION_ABORT );
 
549
        }
 
550
 
 
551
        protected boolean showContinue( int res ) throws AbortImportException
 
552
        {
 
553
                return showContinue( _doit.getText( res ).toString() );
 
554
        }
 
555
 
 
556
        synchronized protected boolean showContinue( String message )
553
557
                        throws AbortImportException
554
558
        {
555
559
                checkAbort();
560
564
                }
561
565
                catch( InterruptedException e ) { }
562
566
 
563
 
                // if we're aborting, there's no need to check if an abortion happened
564
 
                // during the wait
565
 
                if( _response == RESPONSE_NEGATIVE )
566
 
                        finish( ACTION_ABORT );
567
 
                else
568
 
                        checkAbort();
 
567
                // check if an abortion happened during the wait
 
568
                checkAbort();
 
569
 
 
570
                return _response == RESPONSE_POSITIVE;
569
571
        }
570
572
 
571
573
        protected void setProgressMessage( int res ) throws AbortImportException
760
762
                                importContactOrganisations( id, contact.getOrganisations() );
761
763
                        if( contact.hasNotes() )
762
764
                                importContactNotes( id, contact.getNotes() );
763
 
                        if( contact.hasBirthday() )
764
 
                                importContactBirthday( id, contact.getBirthday() );
765
765
                }
766
766
                catch( Backend.ContactCreationException e )
767
767
                {
874
874
                }
875
875
        }
876
876
 
877
 
        private void importContactNotes( Long id, HashSet< String > datas )
 
877
        private void importContactNotes( Long id,
 
878
                HashSet< String > datas )
878
879
                throws ContactCreationException
879
880
        {
880
881
                // add notes
894
895
                        // date from another file
895
896
                        _contacts_cache.addAssociatedNote( id, note );
896
897
                }
897
 
        }
898
 
 
899
 
        private void importContactBirthday( Long id, String birthday )
900
 
                throws ContactCreationException
901
 
        {
902
 
                // we don't want to import this birthday if it already exists
903
 
                if( _contacts_cache.hasAssociatedBirthday( id, birthday ) )
904
 
                        return;
905
 
 
906
 
                // add birthday
907
 
                _backend.addContactBirthday( id, birthday );
908
 
 
909
 
                // and update the cache
910
 
                _contacts_cache.addAssociatedBirthday( id, birthday );
 
898
 
911
899
        }
912
900
 
913
901
        synchronized protected void checkAbort() throws AbortImportException