25
25
import android .view .Menu ;
26
26
import android .view .MenuItem ;
27
27
import android .view .View ;
28
- import android .view .View .OnKeyListener ;
29
28
import android .view .View .OnClickListener ;
30
- import android .view .View .OnFocusChangeListener ;
31
29
import android .view .ViewGroup ;
32
30
import android .view .Window ;
33
31
import android .view .ContextMenu .ContextMenuInfo ;
32
+ import android .widget .AdapterView ;
34
33
import android .widget .BaseAdapter ;
35
34
import android .widget .ListView ;
36
- import android .widget .AdapterView ;
37
35
import android .widget .ProgressBar ;
38
36
import android .widget .TextView ;
39
37
import android .widget .ImageButton ;
40
- import android .widget .Button ;
41
- import android .widget .CheckBox ;
42
38
import android .widget .Toast ;
43
39
import android .widget .AdapterView .AdapterContextMenuInfo ;
44
- import android .widget .AdapterView .OnItemClickListener ;
45
40
41
+ import android .widget .Button ;
46
42
import android .widget .CheckBox ;
47
43
import android .widget .CompoundButton ;
48
44
import android .widget .CompoundButton .OnCheckedChangeListener ;
49
- import com .android .email .K9ListActivity ;
50
45
import com .android .email .Account ;
51
46
import com .android .email .Email ;
47
+ import com .android .email .K9Activity ;
52
48
import com .android .email .MessagingController ;
53
49
import com .android .email .MessagingListener ;
54
50
import com .android .email .R ;
76
72
*
77
73
*/
78
74
79
- public class MessageList extends K9ListActivity
75
+ public class MessageList
76
+ extends K9Activity
77
+ implements OnClickListener , AdapterView .OnItemClickListener
80
78
{
81
79
82
80
private static final int DIALOG_MARK_ALL_AS_READ = 1 ;
@@ -87,13 +85,12 @@ public class MessageList extends K9ListActivity
87
85
88
86
private static final String EXTRA_ACCOUNT = "account" ;
89
87
private static final String EXTRA_STARTUP = "startup" ;
90
-
91
- private static final String EXTRA_FOLDER = "folder" ;
88
+ private static final String EXTRA_FOLDER = "folder" ;
89
+
92
90
private static final String STATE_KEY_LIST = "com.android.email.activity.messagelist_state" ;
93
-
94
91
private static final String STATE_CURRENT_FOLDER = "com.android.email.activity.messagelist_folder" ;
95
92
private static final String STATE_KEY_SELECTION = "com.android.email.activity.messagelist_selection" ;
96
-
93
+ private static final String STATE_KEY_SELECTED_COUNT = "com.android.email.activity.messagelist_selected_count" ;
97
94
98
95
private static final int WIDGET_NONE = 1 ;
99
96
private static final int WIDGET_FLAG = 2 ;
@@ -159,6 +156,13 @@ public class MessageList extends K9ListActivity
159
156
160
157
private boolean mStartup = false ;
161
158
159
+ private int mSelectedCount = 0 ;
160
+
161
+ private View mBatchButtonArea ;
162
+ private Button mBatchReadButton ;
163
+ private Button mBatchDeleteButton ;
164
+ private Button mBatchFlagButton ;
165
+
162
166
private DateFormat getDateFormat ()
163
167
{
164
168
if (dateFormat == null )
@@ -386,7 +390,8 @@ public static void actionHandleFolder(Context context, Account account, String f
386
390
context .startActivity (intent );
387
391
}
388
392
389
- public void onListItemClick (ListView parent , View v , int position , long id )
393
+ @ Override
394
+ public void onItemClick (AdapterView parent , View v , int position , long id )
390
395
{
391
396
if ((position +1 ) == (mAdapter .getCount ()))
392
397
{
@@ -411,12 +416,15 @@ public void onCreate(Bundle savedInstanceState)
411
416
412
417
requestWindowFeature (Window .FEATURE_INDETERMINATE_PROGRESS );
413
418
414
- mListView = getListView ();
419
+ setContentView (R .layout .message_list );
420
+
421
+ mListView = (ListView ) findViewById (R .id .message_list );
415
422
mListView .setScrollBarStyle (View .SCROLLBARS_OUTSIDE_INSET );
416
423
mListView .setLongClickable (true );
417
424
mListView .setFastScrollEnabled (true );
418
425
mListView .setScrollingCacheEnabled (true );
419
-
426
+ mListView .setOnItemClickListener (this );
427
+
420
428
registerForContextMenu (mListView );
421
429
422
430
/*
@@ -427,6 +435,14 @@ public void onCreate(Bundle savedInstanceState)
427
435
428
436
mInflater = getLayoutInflater ();
429
437
438
+ mBatchButtonArea = findViewById (R .id .batch_button_area );
439
+ mBatchReadButton = (Button ) findViewById (R .id .batch_read_button );
440
+ mBatchReadButton .setOnClickListener (this );
441
+ mBatchDeleteButton = (Button ) findViewById (R .id .batch_delete_button );
442
+ mBatchDeleteButton .setOnClickListener (this );
443
+ mBatchFlagButton = (Button ) findViewById (R .id .batch_flag_button );
444
+ mBatchFlagButton .setOnClickListener (this );
445
+
430
446
Intent intent = getIntent ();
431
447
mAccount = (Account )intent .getSerializableExtra (EXTRA_ACCOUNT );
432
448
mStartup = (boolean )intent .getBooleanExtra (EXTRA_STARTUP , false );
@@ -446,11 +462,9 @@ public void onCreate(Bundle savedInstanceState)
446
462
else
447
463
{
448
464
mFolderName = savedInstanceState .getString (STATE_CURRENT_FOLDER );
465
+ mSelectedCount = savedInstanceState .getInt (STATE_KEY_SELECTED_COUNT );
449
466
}
450
467
451
-
452
-
453
-
454
468
/*
455
469
* Since the color chip is always the same color for a given account we just
456
470
* cache the id of the chip right here.
@@ -469,7 +483,7 @@ public void onCreate(Bundle savedInstanceState)
469
483
470
484
mCurrentFolder = mAdapter .getFolder (mFolderName );
471
485
472
- setListAdapter (mAdapter );
486
+ mListView . setAdapter (mAdapter );
473
487
474
488
if (savedInstanceState != null )
475
489
{
@@ -541,6 +555,7 @@ public void onSaveInstanceState(Bundle outState)
541
555
outState .putParcelable (STATE_KEY_LIST , mListView .onSaveInstanceState ());
542
556
outState .putInt (STATE_KEY_SELECTION , mListView .getSelectedItemPosition ());
543
557
outState .putString (STATE_CURRENT_FOLDER , mCurrentFolder .name );
558
+ outState .putInt (STATE_KEY_SELECTED_COUNT , mSelectedCount );
544
559
}
545
560
546
561
@@ -1833,9 +1848,11 @@ public void onClick(View v)
1833
1848
1834
1849
1835
1850
holder .flagged .setChecked (message .flagged );
1851
+ //So that the mSelectedCount is only incremented/decremented
1852
+ //when a user checks the checkbox (vs code)
1853
+ holder .position = -1 ;
1836
1854
holder .selected .setChecked (message .selected );
1837
1855
1838
-
1839
1856
if (message .downloaded )
1840
1857
{
1841
1858
holder .chip .getBackground ().setAlpha (message .read ? 0 : 127 );
@@ -1868,6 +1885,7 @@ public void onClick(View v)
1868
1885
holder .from .setTypeface (null , Typeface .NORMAL );
1869
1886
holder .date .setText ("No date" );
1870
1887
holder .from .setCompoundDrawablesWithIntrinsicBounds (null , null , null , null );
1888
+ //WARNING: Order of the next 2 lines matter
1871
1889
holder .position = -1 ;
1872
1890
holder .selected .setChecked (false );
1873
1891
holder .flagged .setChecked (false );
@@ -2147,7 +2165,28 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
2147
2165
if (position !=-1 )
2148
2166
{
2149
2167
MessageInfoHolder message = (MessageInfoHolder ) mAdapter .getItem (position );
2150
- message .selected = isChecked ;
2168
+ if (message .selected !=isChecked )
2169
+ {
2170
+ if (isChecked )
2171
+ {
2172
+ mSelectedCount ++;
2173
+ if (mSelectedCount ==1 )
2174
+ {
2175
+ //TODO: Fade in animation
2176
+ mBatchButtonArea .setVisibility (View .VISIBLE );
2177
+ }
2178
+ }
2179
+ else
2180
+ {
2181
+ mSelectedCount --;
2182
+ if (mSelectedCount ==0 )
2183
+ {
2184
+ //TODO: Fade out animation
2185
+ mBatchButtonArea .setVisibility (View .GONE );
2186
+ }
2187
+ }
2188
+ message .selected = isChecked ;
2189
+ }
2151
2190
}
2152
2191
}
2153
2192
}
@@ -2268,4 +2307,44 @@ public void populate(Folder folder)
2268
2307
}
2269
2308
}
2270
2309
2310
+ @ Override
2311
+ public void onClick (View v )
2312
+ {
2313
+ if (v ==mBatchDeleteButton )
2314
+ {
2315
+ List <Message > messageList = new ArrayList <Message >();
2316
+ //TODO: Optimize i.e. batch all these operations
2317
+ for (MessageInfoHolder holder : mAdapter .messages )
2318
+ {
2319
+ if (holder .selected )
2320
+ {
2321
+ if (holder .read == false && holder .folder .unreadMessageCount > 0 )
2322
+ {
2323
+ holder .folder .unreadMessageCount --;
2324
+ }
2325
+ mAdapter .removeMessage (holder );
2326
+ messageList .add (holder .message );
2327
+ }
2328
+ }
2329
+ if (!messageList .isEmpty ())
2330
+ {
2331
+ //We assume that all messages are in the same folder
2332
+ String folderName = messageList .get (0 ).getFolder ().getName ();
2333
+ MessagingController .getInstance (getApplication ()).deleteMessageList (mAccount , folderName , messageList , null );
2334
+ mSelectedCount = 0 ;
2335
+ //TODO: Fade out animation
2336
+ mBatchButtonArea .setVisibility (View .GONE );
2337
+ }
2338
+ else
2339
+ {
2340
+ //Should not happen
2341
+ Toast .makeText (this , R .string .no_message_seletected_toast , Toast .LENGTH_SHORT ).show ();
2342
+ }
2343
+ }
2344
+ else
2345
+ {
2346
+ Toast .makeText (this , "Not yet implemented" , Toast .LENGTH_SHORT ).show ();
2347
+ }
2348
+ }
2349
+
2271
2350
}
0 commit comments