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;
137
139
protected void setName( String name )
328
330
protected void finalise()
331
throws ContactNotIdentifiableException
330
333
// ensure that if there is a primary number, it is preferred so
331
334
// that there is always one preferred number. Android will assign
349
352
_organisations.put( _primary_organisation,
350
353
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;
354
368
private String sanitisePhoneNumber( String number )
569
583
return _doit.getText( res );
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
586
synchronized private boolean checkForDuplicate(
587
ContactsCache.CacheIdentifier cache_identifier, int merge_setting )
588
throws AbortImportException
583
590
_last_merge_decision = merge_setting;
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();
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)
592
596
// handle special cases
593
597
switch( merge_setting )
595
599
case Doit.ACTION_KEEP:
596
600
// if we keep contacts on duplicate, we better check for one
597
return !_contacts_cache.canLookup( identifier );
601
return !_contacts_cache.canLookup( cache_identifier );
599
603
case Doit.ACTION_PROMPT:
600
604
// if we are prompting on duplicate, we better check for one and if
601
605
// the contact doesn'te exist, we want to import it
602
if( !_contacts_cache.canLookup( identifier ) )
606
if( !_contacts_cache.canLookup( cache_identifier ) )
605
609
// ok, it exists, so do prompt
606
610
_doit._handler.sendMessage( Message.obtain( _doit._handler,
607
Doit.MESSAGE_MERGEPROMPT, identifier.getDetail() ) );
611
Doit.MESSAGE_MERGEPROMPT, cache_identifier.getDetail() ) );
618
622
_merge_setting = _response;
620
624
// recurse, with our new merge setting
621
return isImportRequired( contact, _response );
625
return checkForDuplicate( cache_identifier, _response );
624
628
// 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 ) ) {
640
656
// if( !showContinue( "====[ IMPORTING ]====\n: " + contact._name ) )
641
657
// finish( ACTION_ABORT );
643
ContentValues values = new ContentValues();
659
// keep track of whether we've informed the UI of what we're doing
644
660
boolean ui_informed = false;
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 );
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 );
657
666
// does contact exist already?
671
680
_doit.getContentResolver().delete( contact_uri, null, null );
674
_contacts_cache.removeLookup( identifier );
683
_contacts_cache.removeLookup( contact.getCacheIdentifier() );
675
684
_contacts_cache.removeAssociatedData( id );
677
686
// show that we're overwriting a contact
691
700
// create a new contact
701
ContentValues values = new ContentValues();
692
702
values.put( Contacts.People.NAME, contact._name );
693
703
Uri contact_uri = _doit.getContentResolver().insert(
694
704
Contacts.People.CONTENT_URI, values );
720
730
// if we haven't already shown that we're overwriting or creating a
721
// contact show that we're merging a contact
731
// contact, show that we're merging a contact
722
732
if( !ui_informed )
723
733
_doit._handler.sendEmptyMessage( Doit.MESSAGE_CONTACTMERGED );