/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: 2016-03-28 18:13:50 UTC
  • Revision ID: tim@ed.am-20160328181350-ytxvox60fxj1tevm
fixed typo in strings

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * Importer.java
3
3
 *
4
 
 * Copyright (C) 2009 to 2012 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2009 to 2013 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;
145
146
 
146
147
                private ContactsCache.CacheIdentifier _cache_identifier = null;
147
148
 
362
363
                        return _notes;
363
364
                }
364
365
 
 
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
 
365
381
                protected void finalise()
366
382
                        throws ContactNotIdentifiableException
367
383
                {
417
433
                        Matcher m = p.matcher( email );
418
434
                        if( m.matches() ) {
419
435
                                String[] bits = email.split( "@" );
420
 
                                return bits[ 0 ] + "@" + bits[ 1 ].toLowerCase( Locale.US );
 
436
                                return bits[ 0 ] + "@" +
 
437
                                        bits[ 1 ].toLowerCase( Locale.ENGLISH );
421
438
                        }
422
439
                        return null;
423
440
                }
527
544
                finish( ACTION_ABORT );
528
545
        }
529
546
 
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 )
 
547
        protected void showContinueOrAbort( int res ) throws AbortImportException
 
548
        {
 
549
                showContinueOrAbort( _doit.getText( res ).toString() );
 
550
        }
 
551
 
 
552
        synchronized protected void showContinueOrAbort( String message )
557
553
                        throws AbortImportException
558
554
        {
559
555
                checkAbort();
564
560
                }
565
561
                catch( InterruptedException e ) { }
566
562
 
567
 
                // check if an abortion happened during the wait
568
 
                checkAbort();
569
 
 
570
 
                return _response == RESPONSE_POSITIVE;
 
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();
571
569
        }
572
570
 
573
571
        protected void setProgressMessage( int res ) throws AbortImportException
762
760
                                importContactOrganisations( id, contact.getOrganisations() );
763
761
                        if( contact.hasNotes() )
764
762
                                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,
878
 
                HashSet< String > datas )
 
877
        private void importContactNotes( Long id, HashSet< String > datas )
879
878
                throws ContactCreationException
880
879
        {
881
880
                // add notes
895
894
                        // date from another file
896
895
                        _contacts_cache.addAssociatedNote( id, note );
897
896
                }
898
 
 
 
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 );
899
911
        }
900
912
 
901
913
        synchronized protected void checkAbort() throws AbortImportException