/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/Doit.java

  • Committer: Tim Marston
  • Date: 2013-10-20 17:51:59 UTC
  • Revision ID: tim@ed.am-20131020175159-xbei6qwxo8jxejdm
removed TODO from project

Show diffs side-by-side

added added

removed removed

1
 
package org.waxworlds.importcontacts;
 
1
/*
 
2
 * Doit.java
 
3
 *
 
4
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
 
5
 *
 
6
 * This file is part of the Import Contacts program (hereafter referred
 
7
 * to as "this program").  For more information, see
 
8
 * http://ed.am/dev/android/import-contacts
 
9
 *
 
10
 * This program is free software: you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation, either version 3 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
 */
 
23
 
 
24
package am.ed.importcontacts;
2
25
 
3
26
import android.app.AlertDialog;
4
27
import android.app.Dialog;
13
36
import android.widget.Button;
14
37
import android.widget.CheckBox;
15
38
import android.widget.CompoundButton;
16
 
import android.widget.LinearLayout;
17
39
import android.widget.ProgressBar;
18
40
import android.widget.TextView;
19
41
import android.widget.Toast;
24
46
        private final static int DIALOG_CONTINUEORABORT = 1;
25
47
        private final static int DIALOG_MERGEPROMPT = 2;
26
48
 
27
 
        public final static int MESSAGE_FINISHED_ALLDONE = 0;
28
 
        public final static int MESSAGE_FINISHED = 1;
29
 
        public final static int MESSAGE_FINISHED_GOBACK = 2;
 
49
        public final static int MESSAGE_ALLDONE = 0;
 
50
        public final static int MESSAGE_ABORT = 1;
30
51
        public final static int MESSAGE_ERROR = 3;
31
52
        public final static int MESSAGE_CONTINUEORABORT = 4;
32
53
        public final static int MESSAGE_SETPROGRESSMESSAGE = 5;
39
60
        public final static int MESSAGE_CONTACTMERGED = 12;
40
61
        public final static int MESSAGE_CONTACTSKIPPED = 13;
41
62
 
42
 
        private boolean _startedProgress;
43
 
        private int _maxProgress;
44
 
        private int _tmpProgress;
 
63
        public final static int ACTION_PROMPT = 0;
 
64
        public final static int ACTION_KEEP = 1;
 
65
        public final static int ACTION_MERGE_MERGE = 2;
 
66
        public final static int ACTION_OVERWRITE = 3;
 
67
 
 
68
        public final static int NEXT_BEGIN = 0;
 
69
        public final static int NEXT_CLOSE = 1;
 
70
 
 
71
        private boolean _started_progress;
 
72
        private int _max_progress;
 
73
        private int _tmp_progress;
45
74
        private int _progress;
46
 
        protected String _dialogMessage;
47
 
        private Dialog _mergePromptDialog;
48
 
        private boolean _mergePromptAlwaysSelected;
 
75
        protected String _dialog_message;
 
76
        private Dialog _merge_prompt_dialog;
 
77
        private boolean _merge_prompt_always_selected;
 
78
        private int _next_action;
 
79
        private int _current_dialog_id;
49
80
 
50
 
        private int _countOverwrites;
51
 
        private int _countCreates;
52
 
        private int _countMerges;
53
 
        private int _countSkips;
 
81
        private int _count_overwrites;
 
82
        private int _count_creates;
 
83
        private int _count_merges;
 
84
        private int _count_skips;
54
85
 
55
86
        protected Importer _importer = null;
56
87
 
62
93
                public void handleMessage( Message msg ) {
63
94
                        switch( msg.what )
64
95
                        {
65
 
                        case MESSAGE_FINISHED_ALLDONE:
 
96
                        case MESSAGE_ALLDONE:
66
97
                                ( (TextView)findViewById( R.id.doit_alldone ) ).
67
 
                                                setVisibility( View.VISIBLE );
68
 
                                // fall through
69
 
                        case MESSAGE_FINISHED:
70
 
                                ( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
71
 
                                                setVisibility( View.VISIBLE );
 
98
                                        setVisibility( View.VISIBLE );
 
99
                                ( (Button)findViewById( R.id.back ) ).setEnabled( false );
 
100
                                updateNext( NEXT_CLOSE );
 
101
                                findViewById( R.id.doit_abort_disp ).setVisibility(
 
102
                                        View.GONE );
72
103
                                break;
73
 
                        case MESSAGE_FINISHED_GOBACK:
74
 
                                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
 
104
                        case MESSAGE_ABORT:
 
105
                                manualAbort();
75
106
                                break;
76
107
                        case MESSAGE_ERROR:
77
 
                                Doit.this._dialogMessage = (String)msg.obj;
 
108
                                _dialog_message = (String)msg.obj;
78
109
                                showDialog( DIALOG_ERROR );
79
110
                                break;
80
111
                        case MESSAGE_CONTINUEORABORT:
81
 
                                Doit.this._dialogMessage = (String)msg.obj;
 
112
                                _dialog_message = (String)msg.obj;
82
113
                                showDialog( DIALOG_CONTINUEORABORT );
83
114
                                break;
84
115
                        case MESSAGE_SETPROGRESSMESSAGE:
85
116
                                ( (TextView)findViewById( R.id.doit_percentage ) ).
86
 
                                                setText( (String)msg.obj );
 
117
                                        setText( (String)msg.obj );
87
118
                                break;
88
119
                        case MESSAGE_SETMAXPROGRESS:
89
 
                                if( _maxProgress > 0 ) {
90
 
                                        if( _tmpProgress == _maxProgress )
91
 
                                                _tmpProgress = (Integer)msg.obj;
92
 
                                        if( _progress == _maxProgress )
 
120
                                if( _max_progress > 0 ) {
 
121
                                        if( _tmp_progress == _max_progress - 1 )
 
122
                                                _tmp_progress = (Integer)msg.obj;
 
123
                                        if( _progress == _max_progress - 1 )
93
124
                                                _progress = (Integer)msg.obj;
94
125
                                }
95
 
                                _maxProgress = (Integer)msg.obj;
 
126
                                _max_progress = (Integer)msg.obj;
96
127
                                updateProgress();
97
128
                                break;
98
129
                        case MESSAGE_SETTMPPROGRESS:
99
 
                                _tmpProgress = (Integer)msg.obj;
 
130
                                _tmp_progress = (Integer)msg.obj;
100
131
                                updateProgress();
101
132
                                break;
102
133
                        case MESSAGE_SETPROGRESS:
103
 
                                _startedProgress = true;
 
134
                                _started_progress = true;
104
135
                                _progress = (Integer)msg.obj;
105
136
                                updateProgress();
106
137
                                break;
107
138
                        case MESSAGE_MERGEPROMPT:
108
 
                                _dialogMessage = (String)msg.obj;
 
139
                                _dialog_message = (String)msg.obj;
109
140
                                showDialog( DIALOG_MERGEPROMPT );
110
141
                                break;
111
142
                        case MESSAGE_CONTACTOVERWRITTEN:
112
 
                                _countOverwrites++;
 
143
                                _count_overwrites++;
113
144
                                updateStats();
114
145
                                break;
115
146
                        case MESSAGE_CONTACTCREATED:
116
 
                                _countCreates++;
 
147
                                _count_creates++;
117
148
                                updateStats();
118
149
                                break;
119
150
                        case MESSAGE_CONTACTMERGED:
120
 
                                _countMerges++;
 
151
                                _count_merges++;
121
152
                                updateStats();
122
153
                                break;
123
154
                        case MESSAGE_CONTACTSKIPPED:
124
 
                                _countSkips++;
 
155
                                _count_skips++;
125
156
                                updateStats();
126
157
                                break;
127
158
                        default:
131
162
        }
132
163
 
133
164
        @Override
134
 
        protected void onCreate(Bundle savedInstanceState)
 
165
        protected void onCreate(Bundle saved_instance_state)
135
166
        {
136
167
                setContentView( R.layout.doit );
137
 
                super.onCreate( savedInstanceState );
 
168
                super.onCreate( saved_instance_state );
138
169
 
139
170
                // hide page 2
140
171
                ( findViewById( R.id.doit_page_2 ) ).setVisibility( View.GONE );
141
172
 
142
 
                // set up begin button
143
 
                Button begin = (Button)findViewById( R.id.doit_begin );
 
173
                // set up abort button
 
174
                Button begin = (Button)findViewById( R.id.abort );
144
175
                begin.setOnClickListener( new View.OnClickListener() {
145
176
                        public void onClick( View view ) {
146
 
                                importContacts();
147
 
                        }
148
 
                } );
149
 
 
150
 
                // set up close button
151
 
                Button close = (Button)findViewById( R.id.doit_close );
152
 
                close.setOnClickListener( new View.OnClickListener() {
153
 
                        public void onClick( View view ) {
154
 
                                setResult( RESULT_CANCELED );
155
 
                                finish();
156
 
                        }
157
 
                } );
158
 
 
159
 
                _startedProgress = false;
160
 
                _maxProgress = 0;
161
 
                _tmpProgress = 0;
 
177
                                manualAbort();
 
178
                        }
 
179
                } );
 
180
 
 
181
                _started_progress = false;
 
182
                _max_progress = 0;
 
183
                _tmp_progress = 0;
162
184
                _progress = 0;
163
185
                _handler = new DoitHandler();
164
186
 
165
 
                _countOverwrites = 0;
166
 
                _countCreates = 0;
167
 
                _countMerges = 0;
168
 
                _countSkips = 0;
 
187
                _count_overwrites = 0;
 
188
                _count_creates = 0;
 
189
                _count_merges = 0;
 
190
                _count_skips = 0;
 
191
 
 
192
                updateNext( NEXT_BEGIN );
169
193
 
170
194
                updateProgress();
171
195
                updateStats();
177
201
                super.onPause();
178
202
 
179
203
                // saving the state of an import sounds complicated! Lets just abort!
180
 
                abortImport();
181
 
 
182
 
                // destroy some stuff
183
 
                _importer = null;
184
 
                _handler = null;
 
204
                if( _next_action != NEXT_CLOSE )
 
205
                        manualAbort( true );
185
206
        }
186
207
 
187
208
        @Override
188
 
        protected Dialog onCreateDialog(int id)
 
209
        protected Dialog onCreateDialog( int id )
189
210
        {
190
211
                switch( id )
191
212
                {
192
213
                case DIALOG_ERROR:
193
214
                        return new AlertDialog.Builder( this )
194
 
                                        .setIcon( R.drawable.alert_dialog_icon )
195
 
                                        .setTitle( R.string.error_title )
196
 
                                        .setMessage( "" )
197
 
                                        .setPositiveButton( R.string.error_ok,
198
 
                                                        new DialogInterface.OnClickListener() {
199
 
                                                public void onClick(DialogInterface dialog,
200
 
                                                                int whichButton) {
201
 
                                                        Doit.this._importer.wake();
 
215
                                .setIcon( R.drawable.alert_dialog_icon )
 
216
                                .setTitle( R.string.error_title )
 
217
                                .setMessage( "" )
 
218
                                .setPositiveButton( R.string.error_ok,
 
219
                                        new DialogInterface.OnClickListener() {
 
220
                                                public void onClick( DialogInterface dialog,
 
221
                                                        int whichButton )
 
222
                                                {
 
223
                                                        if( Doit.this != null )
 
224
                                                                Doit.this._importer.wake();
202
225
                                                }
203
226
                                        } )
204
 
                                        .setOnCancelListener( _dialogOnCancelListener )
205
 
                                        .create();
 
227
                                .setOnCancelListener( _dialog_on_cancel_listener )
 
228
                                .create();
206
229
                case DIALOG_CONTINUEORABORT:
207
230
                        return new AlertDialog.Builder( this )
208
 
                                        .setIcon( R.drawable.alert_dialog_icon )
209
 
                                        .setTitle( R.string.error_title )
210
 
                                        .setMessage( "" )
211
 
                                        .setPositiveButton( R.string.error_continue,
212
 
                                                        new DialogInterface.OnClickListener() {
213
 
                                                public void onClick(DialogInterface dialog,
214
 
                                                                int whichButton) {
215
 
                                                        Doit.this._importer.wake(
 
231
                                .setIcon( R.drawable.alert_dialog_icon )
 
232
                                .setTitle( R.string.error_title )
 
233
                                .setMessage( "" )
 
234
                                .setPositiveButton( R.string.error_continue,
 
235
                                        new DialogInterface.OnClickListener() {
 
236
                                                public void onClick( DialogInterface dialog,
 
237
                                                        int which_button )
 
238
                                                {
 
239
                                                        if( Doit.this != null )
 
240
                                                                Doit.this._importer.wake(
216
241
                                                                        Importer.RESPONSE_POSITIVE );
217
242
                                                }
218
243
                                        } )
219
 
                                        .setNegativeButton( R.string.error_abort,
220
 
                                                        new DialogInterface.OnClickListener() {
221
 
                                                public void onClick(DialogInterface dialog,
222
 
                                                                int whichButton) {
223
 
                                                        Doit.this._importer.wake(
 
244
                                .setNegativeButton( R.string.error_abort,
 
245
                                        new DialogInterface.OnClickListener() {
 
246
                                                public void onClick( DialogInterface dialog,
 
247
                                                        int which_button )
 
248
                                                {
 
249
                                                        if( Doit.this != null )
 
250
                                                                Doit.this._importer.wake(
224
251
                                                                        Importer.RESPONSE_NEGATIVE );
225
252
                                                }
226
253
                                        } )
227
 
                                        .setOnCancelListener( _dialogOnCancelListener )
228
 
                                        .create();
 
254
                                .setOnCancelListener( _dialog_on_cancel_listener )
 
255
                                .create();
229
256
                case DIALOG_MERGEPROMPT:
230
257
                        // custom layout in an AlertDialog
231
258
                        LayoutInflater factory = LayoutInflater.from( this );
232
 
                        final View dialogView = factory.inflate(
233
 
                                        R.layout.mergeprompt, null );
234
 
                        ( (CheckBox)dialogView.findViewById( R.id.mergeprompt_always ) ).
235
 
                                        setOnCheckedChangeListener(
236
 
                                                        new CompoundButton.OnCheckedChangeListener() {
237
 
                                public void onCheckedChanged( CompoundButton buttonView,
238
 
                                                boolean isChecked ) {
239
 
                                        Doit.this._mergePromptAlwaysSelected = isChecked;
240
 
                                }
241
 
                        } );
242
 
                        ( (Button)dialogView.findViewById( R.id.merge_keep ) ).
243
 
                                        setOnClickListener( _mergePromptButtonListener );
244
 
                        ( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
245
 
                                        setOnClickListener( _mergePromptButtonListener );
246
 
                        ( (Button)dialogView.findViewById( R.id.merge_merge ) ).
247
 
                                        setOnClickListener( _mergePromptButtonListener );
248
 
                        _mergePromptAlwaysSelected = false;
 
259
                        final View dialog_view = factory.inflate(
 
260
                                R.layout.mergeprompt, null );
 
261
                        ( (CheckBox)dialog_view.findViewById( R.id.mergeprompt_always ) ).
 
262
                                setOnCheckedChangeListener(
 
263
                                        new CompoundButton.OnCheckedChangeListener() {
 
264
                                                public void onCheckedChanged(
 
265
                                                        CompoundButton button_view, boolean is_checked )
 
266
                                                {
 
267
                                                        if( Doit.this != null )
 
268
                                                                Doit.this._merge_prompt_always_selected =
 
269
                                                                        is_checked;
 
270
                                                }
 
271
                                        } );
 
272
                        ( (Button)dialog_view.findViewById( R.id.merge_keep ) ).
 
273
                                setOnClickListener( _merge_prompt_button_listener );
 
274
                        ( (Button)dialog_view.findViewById( R.id.merge_overwrite ) ).
 
275
                                setOnClickListener( _merge_prompt_button_listener );
 
276
                        ( (Button)dialog_view.findViewById( R.id.merge_merge ) ).
 
277
                                setOnClickListener( _merge_prompt_button_listener );
 
278
                        ( (Button)dialog_view.findViewById( R.id.abort ) ).
 
279
                                setOnClickListener( _merge_prompt_button_listener );
 
280
                        _merge_prompt_always_selected = false;
249
281
                        return new AlertDialog.Builder( this )
250
 
                                        .setIcon( R.drawable.alert_dialog_icon )
251
 
                                        .setTitle( R.string.mergeprompt_title )
252
 
                                        .setView( dialogView )
253
 
                                        .setOnCancelListener( _dialogOnCancelListener )
254
 
                                        .create();
 
282
                                .setIcon( R.drawable.alert_dialog_icon )
 
283
                                .setTitle( R.string.mergeprompt_title )
 
284
                                .setView( dialog_view )
 
285
                                .setOnCancelListener( _dialog_on_cancel_listener )
 
286
                                .create();
255
287
                }
256
288
                return null;
257
289
        }
258
290
 
259
 
    private OnClickListener _mergePromptButtonListener = new OnClickListener() {
260
 
                public void onClick( View view ) {
261
 
                        int responseExtra = _mergePromptAlwaysSelected?
 
291
        private OnClickListener _merge_prompt_button_listener =
 
292
                new OnClickListener()
 
293
        {
 
294
                public void onClick( View view )
 
295
                {
 
296
                        if( Doit.this == null ) return;
 
297
 
 
298
                        // handle abort
 
299
                        if( view.getId() == R.id.abort )
 
300
                                manualAbort();
 
301
 
 
302
                        // else, response (just check we haven't aborted already!)
 
303
                        else if( Doit.this._importer != null ) {
 
304
                                int response_extra = _merge_prompt_always_selected?
262
305
                                        Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
263
 
                        Doit.this._mergePromptDialog.dismiss();
264
 
                        Doit.this._mergePromptDialog = null;    // dont keep a reference!
265
 
                        Doit.this._importer.wake( view.getId(), responseExtra );
 
306
                                Doit.this._importer.wake( convertIdToAction( view.getId() ),
 
307
                                        response_extra );
 
308
                        }
 
309
 
 
310
                        // close dialog and free (don't keep a reference)
 
311
                        Doit.this._merge_prompt_dialog.dismiss();
 
312
                        Doit.this._merge_prompt_dialog = null;
266
313
                }
267
314
        };
268
315
 
269
 
        private DialogInterface.OnCancelListener _dialogOnCancelListener =
270
 
                        new DialogInterface.OnCancelListener() {
 
316
        @Override
 
317
        protected void onNext()
 
318
        {
 
319
                Button next = (Button)findViewById( R.id.next );
 
320
                next.setEnabled( false );
 
321
 
 
322
                switch( _next_action )
 
323
                {
 
324
                case NEXT_BEGIN:
 
325
                        importContacts();
 
326
                        break;
 
327
                case NEXT_CLOSE:
 
328
                        setResult( RESULT_OK );
 
329
                        finish();
 
330
                        break;
 
331
                }
 
332
        }
 
333
 
 
334
        private void manualAbort()
 
335
        {
 
336
                manualAbort( false );
 
337
        }
 
338
 
 
339
        private void manualAbort( boolean show_toaster_popup )
 
340
        {
 
341
                abortImport( show_toaster_popup );
 
342
 
 
343
                updateNext( NEXT_CLOSE );
 
344
                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
 
345
                findViewById( R.id.doit_abort_disp ).setVisibility( View.GONE );
 
346
                ( (TextView)findViewById( R.id.doit_aborted ) ).
 
347
                        setVisibility( View.VISIBLE );
 
348
                ( (TextView)findViewById( R.id.doit_alldone ) ).
 
349
                        setVisibility( View.GONE );
 
350
 
 
351
                // close any open dialogs
 
352
                try {
 
353
                        dismissDialog( _current_dialog_id );
 
354
                }
 
355
                catch( Exception e ) {
 
356
                        // ignore errors
 
357
                }
 
358
        }
 
359
 
 
360
        private void updateNext( int next_action )
 
361
        {
 
362
                Button next = (Button)findViewById( R.id.next );
 
363
                switch( next_action ) {
 
364
                case NEXT_BEGIN:        next.setText( R.string.doit_begin ); break;
 
365
                case NEXT_CLOSE:        next.setText( R.string.doit_close ); break;
 
366
                }
 
367
                next.setEnabled( true );
 
368
                _next_action = next_action;
 
369
        }
 
370
 
 
371
        public static int convertIdToAction( int id ) {
 
372
                switch( id ) {
 
373
                case R.id.merge_keep:           return ACTION_KEEP;
 
374
                case R.id.merge_merge:          return ACTION_MERGE_MERGE;
 
375
                case R.id.merge_overwrite:      return ACTION_OVERWRITE;
 
376
                default: return ACTION_PROMPT;
 
377
                }
 
378
        }
 
379
 
 
380
        public static int convertActionToId( int action ) {
 
381
                switch( action ) {
 
382
                case ACTION_KEEP:               return R.id.merge_keep;
 
383
                case ACTION_MERGE_MERGE:return R.id.merge_merge;
 
384
                case ACTION_OVERWRITE:  return R.id.merge_overwrite;
 
385
                default: return R.id.merge_prompt;
 
386
                }
 
387
        }
 
388
 
 
389
        private DialogInterface.OnCancelListener _dialog_on_cancel_listener =
 
390
                new DialogInterface.OnCancelListener()
 
391
        {
271
392
                public void onCancel( DialogInterface dialog ) {
272
 
                        setResult( RESULT_CANCELED );
273
 
                        finish();
 
393
                        manualAbort();
274
394
                }
275
395
        };
276
396
 
 
397
 
277
398
        @Override
278
 
        protected void onActivityResult( int requestCode, int resultCode,
279
 
                        Intent data )
 
399
        protected void onActivityResult( int request_code, int result_code,
 
400
                Intent data )
280
401
        {
281
402
                // if we're cancelling, abort any import
282
 
                if( resultCode == RESULT_CANCELED )
283
 
                        abortImport();
 
403
                if( result_code == RESULT_CANCELED )
 
404
                        abortImport( true );
284
405
        }
285
406
 
286
407
        @Override
287
 
        protected void onPrepareDialog(int id, Dialog dialog)
 
408
        protected void onPrepareDialog( int id, Dialog dialog )
288
409
        {
 
410
                _current_dialog_id = id;
 
411
 
289
412
                switch( id )
290
413
                {
291
414
                case DIALOG_ERROR:      // fall through
292
415
                case DIALOG_CONTINUEORABORT:
293
416
                        // set dialog message
294
 
                        ( (AlertDialog)dialog ).setMessage( _dialogMessage );
 
417
                        ( (AlertDialog)dialog ).setMessage( _dialog_message );
295
418
                        break;
296
419
                case DIALOG_MERGEPROMPT:
297
420
                        // set contact's name
298
 
                        ( (TextView)dialog.findViewById( R.id.mergeprompt_name ) ).setText(
299
 
                                        _dialogMessage );
 
421
                        ( (TextView)dialog.findViewById( R.id.mergeprompt_name ) )
 
422
                                .setText( _dialog_message );
300
423
                        // and set up reference to dialog
301
 
                        _mergePromptDialog = dialog;
 
424
                        _merge_prompt_dialog = dialog;
302
425
                        break;
303
426
                }
304
427
 
315
438
                ( (Button)findViewById( R.id.back ) ).setEnabled( false );
316
439
 
317
440
                // create importer
318
 
                _importer = new VCFImporter( this );
 
441
                _importer = new VcardImporter( this );
319
442
 
320
443
                // start the service's thread
321
444
                _importer.start();
324
447
        private void updateProgress()
325
448
        {
326
449
                ProgressBar bar = (ProgressBar)findViewById( R.id.doit_progress );
327
 
                TextView outOf = (TextView)findViewById( R.id.doit_outof );
 
450
                TextView out_of = (TextView)findViewById( R.id.doit_outof );
328
451
 
329
 
                if( _maxProgress > 0 )
 
452
                if( _max_progress > 0 )
330
453
                {
331
 
                        bar.setMax( _maxProgress );
332
 
                        bar.setSecondaryProgress( _tmpProgress );
 
454
                        bar.setMax( _max_progress );
 
455
                        bar.setSecondaryProgress( _tmp_progress );
333
456
 
334
 
                        if( _startedProgress )
 
457
                        if( _started_progress )
335
458
                        {
336
459
                                ( (TextView)findViewById( R.id.doit_percentage ) ).setText(
337
 
                                                (int)Math.round( 100 * _progress / _maxProgress ) + "%" );
338
 
                                outOf.setText( _progress + "/" + _maxProgress );
 
460
                                        (int)Math.round( 100 * _progress / _max_progress ) + "%" );
 
461
                                out_of.setText( _progress + "/" + _max_progress );
339
462
                                bar.setProgress( _progress );
340
463
                        }
341
464
                }
344
467
        private void updateStats()
345
468
        {
346
469
                ( (TextView)findViewById( R.id.doit_overwrites ) ).setText(
347
 
                                "" + _countOverwrites );
 
470
                        "" + _count_overwrites );
348
471
                ( (TextView)findViewById( R.id.doit_creates ) ).setText(
349
 
                                "" + _countCreates );
 
472
                        "" + _count_creates );
350
473
                ( (TextView)findViewById( R.id.doit_merges ) ).setText(
351
 
                                "" + _countMerges );
 
474
                        "" + _count_merges );
352
475
                ( (TextView)findViewById( R.id.doit_skips ) ).setText(
353
 
                                "" + _countSkips );
 
476
                        "" + _count_skips );
354
477
        }
355
478
 
356
 
        private void abortImport()
 
479
        private void abortImport( boolean show_toaster_popup )
357
480
        {
358
481
                if( _importer != null )
359
482
                {
370
493
                                }
371
494
 
372
495
                                // notify the user
373
 
                        Toast.makeText( this, R.string.doit_importaborted,
374
 
                                        Toast.LENGTH_LONG ).show();
 
496
                                if( show_toaster_popup )
 
497
                                        Toast.makeText( this, R.string.doit_importaborted,
 
498
                                                Toast.LENGTH_LONG ).show();
375
499
                        }
376
500
                }
 
501
 
 
502
                // destroy some stuff
 
503
                _importer = null;
 
504
                _handler = null;
377
505
        }
378
506
}