/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/org/waxworlds/edam/importcontacts/Doit.java

  • Committer: edam
  • Date: 2011-05-02 18:28:24 UTC
  • Revision ID: edam@waxworlds.org-20110502182824-acgdi3qfxfzqgely
- fixed logic for vcard field types (home, work, cell, etc) so it works
- updated NEWS and TODO
- rewrote most of ContactsCache, including a new ContactIdentifier class to identify contacts in the cache and new cache building code
- contacts now identified in the same way that Andoid displays them (by name, or organisation, or number, or email, in that order)
- propper handling and support for organisations and titles
- validation of imported contact now done by Importer, not VcfImporter
- separated sanitisation and normalisation (for cache lookups)
- generacised PhoneData, EmailData and AddressData classes
- ContactData is now aware of primary numbers, emails and organisations (defaults to the first prefrred one seen, or the first one seen where none is preferred)

Show diffs side-by-side

added added

removed removed

99
99
                                ( (Button)findViewById( R.id.back ) ).setEnabled( false );
100
100
                                updateNext( NEXT_CLOSE );
101
101
                                findViewById( R.id.doit_abort_disp ).setVisibility(
102
 
                                                View.GONE );
 
102
                                        View.GONE );
103
103
                                break;
104
104
                        case MESSAGE_ABORT:
105
105
                                manualAbort();
114
114
                                break;
115
115
                        case MESSAGE_SETPROGRESSMESSAGE:
116
116
                                ( (TextView)findViewById( R.id.doit_percentage ) ).
117
 
                                                setText( (String)msg.obj );
 
117
                                        setText( (String)msg.obj );
118
118
                                break;
119
119
                        case MESSAGE_SETMAXPROGRESS:
120
120
                                if( _maxProgress > 0 ) {
200
200
        {
201
201
                super.onPause();
202
202
 
203
 
                // close any open dialogs
204
 
                try {
205
 
                        dismissDialog( _currentDialogId );
206
 
                }
207
 
                catch( Exception e ) {
208
 
                }
209
 
 
210
203
                // saving the state of an import sounds complicated! Lets just abort!
211
 
                manualAbort( true );
 
204
                if( _nextAction != NEXT_CLOSE )
 
205
                        manualAbort( true );
212
206
        }
213
207
 
214
208
        @Override
296
290
                        if( view.getId() == R.id.abort )
297
291
                                manualAbort();
298
292
 
299
 
                        // else, response
300
 
                        else {
 
293
                        // else, response (just check we haven't aborted already!)
 
294
                        else if( Doit.this._importer != null ) {
301
295
                                int responseExtra = _mergePromptAlwaysSelected?
302
 
                                                Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
 
296
                                        Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
303
297
                                Doit.this._importer.wake( convertIdToAction( view.getId() ),
304
 
                                                responseExtra );
 
298
                                        responseExtra );
305
299
                        }
306
300
 
307
301
                        // close dialog and free (don't keep a reference)
344
338
                        setVisibility( View.VISIBLE );
345
339
                ( (TextView)findViewById( R.id.doit_alldone ) ).
346
340
                        setVisibility( View.GONE );
 
341
 
 
342
                // close any open dialogs
 
343
                try {
 
344
                        dismissDialog( _currentDialogId );
 
345
                }
 
346
                catch( Exception e ) {
 
347
                        // ignore errors
 
348
                }
347
349
        }
348
350
 
349
351
        private void updateNext( int nextAction )
378
380
        private DialogInterface.OnCancelListener _dialogOnCancelListener =
379
381
                        new DialogInterface.OnCancelListener() {
380
382
                public void onCancel( DialogInterface dialog ) {
381
 
                        setResult( RESULT_CANCELED );
382
 
                        finish();
 
383
                        manualAbort();
383
384
                }
384
385
        };
385
386
 
 
387
 
386
388
        @Override
387
389
        protected void onActivityResult( int requestCode, int resultCode,
388
390
                        Intent data )
407
409
                case DIALOG_MERGEPROMPT:
408
410
                        // set contact's name
409
411
                        ( (TextView)dialog.findViewById( R.id.mergeprompt_name ) ).setText(
410
 
                                        _dialogMessage );
 
412
                                _dialogMessage );
411
413
                        // and set up reference to dialog
412
414
                        _mergePromptDialog = dialog;
413
415
                        break;
445
447
                        if( _startedProgress )
446
448
                        {
447
449
                                ( (TextView)findViewById( R.id.doit_percentage ) ).setText(
448
 
                                                (int)Math.round( 100 * _progress / _maxProgress ) + "%" );
 
450
                                        (int)Math.round( 100 * _progress / _maxProgress ) + "%" );
449
451
                                outOf.setText( _progress + "/" + _maxProgress );
450
452
                                bar.setProgress( _progress );
451
453
                        }
455
457
        private void updateStats()
456
458
        {
457
459
                ( (TextView)findViewById( R.id.doit_overwrites ) ).setText(
458
 
                                "" + _countOverwrites );
 
460
                        "" + _countOverwrites );
459
461
                ( (TextView)findViewById( R.id.doit_creates ) ).setText(
460
 
                                "" + _countCreates );
 
462
                        "" + _countCreates );
461
463
                ( (TextView)findViewById( R.id.doit_merges ) ).setText(
462
 
                                "" + _countMerges );
 
464
                        "" + _countMerges );
463
465
                ( (TextView)findViewById( R.id.doit_skips ) ).setText(
464
 
                                "" + _countSkips );
 
466
                        "" + _countSkips );
465
467
        }
466
468
 
467
469
        private void abortImport( boolean showToasterPopup )
483
485
                                // notify the user
484
486
                                if( showToasterPopup )
485
487
                                        Toast.makeText( this, R.string.doit_importaborted,
486
 
                                                        Toast.LENGTH_LONG ).show();
 
488
                                                Toast.LENGTH_LONG ).show();
487
489
                        }
488
490
                }
489
491