120
@SuppressWarnings("serial")
121
protected class ContactNotIdentifiableException extends Exception
125
125
protected String _name = null;
126
126
protected String _primary_organisation = null;
127
127
protected boolean _primary_organisation_is_preferred = false;
134
134
protected HashMap< String, PreferredDetail > _emails = null;
135
135
protected HashMap< String, TypeDetail > _addresses = null;
137
private ContactsCache.CacheIdentifier _cache_identifier = null;
139
137
protected void setName( String name )
330
328
protected void finalise()
331
throws ContactNotIdentifiableException
333
330
// ensure that if there is a primary number, it is preferred so
334
331
// that there is always one preferred number. Android will assign
352
349
_organisations.put( _primary_organisation,
353
350
new ExtraDetail( 0, true, data.getExtra() ) );
356
// create a cache identifier from this contact data, which can be
357
// used to look-up an existing contact
358
_cache_identifier = ContactsCache.createIdentifier( this );
359
if( _cache_identifier == null )
360
throw new ContactNotIdentifiableException();
363
public ContactsCache.CacheIdentifier getCacheIdentifier()
365
return _cache_identifier;
368
354
private String sanitisePhoneNumber( String number )
583
569
return _doit.getText( res );
586
synchronized private boolean checkForDuplicate(
587
ContactsCache.CacheIdentifier cache_identifier, int merge_setting )
588
throws AbortImportException
572
protected boolean isImportRequired( ContactData contact )
573
throws AbortImportException, ContactNeedsMoreInfoException
576
return isImportRequired( contact, _merge_setting );
579
synchronized private boolean isImportRequired(
580
ContactData contact, int merge_setting )
581
throws AbortImportException, ContactNeedsMoreInfoException
590
583
_last_merge_decision = merge_setting;
592
// it is ok to use contact.getCacheIdentifier(). The contact has already
593
// been finalised, which means a valid cache identifier will have been
594
// created for it (or it would have been skipped)
585
// create a cache identifier which we can use to detect if this contact
586
// is valid for importing
587
ContactsCache.CacheIdentifier identifier =
588
ContactsCache.createIdentifier( contact );
589
if( identifier == null )
590
throw new ContactNeedsMoreInfoException();
596
592
// handle special cases
597
593
switch( merge_setting )
599
595
case Doit.ACTION_KEEP:
600
596
// if we keep contacts on duplicate, we better check for one
601
return !_contacts_cache.canLookup( cache_identifier );
597
return !_contacts_cache.canLookup( identifier );
603
599
case Doit.ACTION_PROMPT:
604
600
// if we are prompting on duplicate, we better check for one and if
605
601
// the contact doesn'te exist, we want to import it
606
if( !_contacts_cache.canLookup( cache_identifier ) )
602
if( !_contacts_cache.canLookup( identifier ) )
609
605
// ok, it exists, so do prompt
610
606
_doit._handler.sendMessage( Message.obtain( _doit._handler,
611
Doit.MESSAGE_MERGEPROMPT, cache_identifier.getDetail() ) );
607
Doit.MESSAGE_MERGEPROMPT, identifier.getDetail() ) );
622
618
_merge_setting = _response;
624
620
// recurse, with our new merge setting
625
return checkForDuplicate( cache_identifier, _response );
621
return isImportRequired( contact, _response );
628
624
// for all other cases (either overwriting or merging) we will need the
644
// It is expected that we use contact.getCacheIdentifier() here. The
645
// contact we are passed should have been successfully finalise()d,
646
// which includes generating a valid cache identifier.
647
ContactsCache.CacheIdentifier cache_identifier =
648
contact.getCacheIdentifier();
650
// check to see if this contact is a duplicate and should be skipped
651
if( !checkForDuplicate( cache_identifier, _merge_setting ) ) {
656
640
// if( !showContinue( "====[ IMPORTING ]====\n: " + contact._name ) )
657
641
// finish( ACTION_ABORT );
659
// keep track of whether we've informed the UI of what we're doing
643
ContentValues values = new ContentValues();
660
644
boolean ui_informed = false;
662
// attempt to lookup the id of an existing contact in the cache with
663
// this contact data's cache identifier
664
Long id = (Long)_contacts_cache.lookup( cache_identifier );
647
// give the contact a chance to finalise it's data
650
// create something, from the contact data, that we can use to identify
651
// a cache entry and attempt to lookup the id of an existing contact in
653
ContactsCache.CacheIdentifier identifier =
654
ContactsCache.createIdentifier( contact );
655
if( identifier != null ) id = (Long)_contacts_cache.lookup( identifier );
666
657
// does contact exist already?
680
671
_doit.getContentResolver().delete( contact_uri, null, null );
683
_contacts_cache.removeLookup( contact.getCacheIdentifier() );
674
_contacts_cache.removeLookup( identifier );
684
675
_contacts_cache.removeAssociatedData( id );
686
677
// show that we're overwriting a contact
700
691
// create a new contact
701
ContentValues values = new ContentValues();
702
692
values.put( Contacts.People.NAME, contact._name );
703
693
Uri contact_uri = _doit.getContentResolver().insert(
704
694
Contacts.People.CONTENT_URI, values );
730
720
// if we haven't already shown that we're overwriting or creating a
731
// contact, show that we're merging a contact
721
// contact show that we're merging a contact
732
722
if( !ui_informed )
733
723
_doit._handler.sendEmptyMessage( Doit.MESSAGE_CONTACTMERGED );