Skip to content

Commit 3525337

Browse files
committed
1st wired up version of multi-select + delete button (still rough on the edges)
1 parent 69e7243 commit 3525337

File tree

5 files changed

+176
-37
lines changed

5 files changed

+176
-37
lines changed

res/layout/message_list.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="fill_parent"
5+
android:layout_height="fill_parent" >
6+
<ListView
7+
android:id="@+id/message_list"
8+
android:layout_width="fill_parent"
9+
android:layout_height="wrap_content"
10+
android:layout_alignParentTop="true"
11+
android:layout_centerHorizontal="true"
12+
/>
13+
<LinearLayout
14+
xmlns:android="http://schemas.android.com/apk/res/android"
15+
android:id="@+id/batch_button_area"
16+
android:layout_width="fill_parent"
17+
android:layout_height="wrap_content"
18+
android:gravity="center"
19+
android:orientation="horizontal"
20+
android:layout_alignParentBottom="true"
21+
android:layout_centerHorizontal="true"
22+
android:visibility="gone"
23+
android:padding="2sp"
24+
android:background="#CCCCCC"
25+
>
26+
<Button
27+
android:id="@+id/batch_read_button"
28+
android:layout_width="0dip"
29+
android:layout_height="wrap_content"
30+
android:layout_weight="1"
31+
android:text="Read"
32+
/>
33+
<Button
34+
android:id="@+id/batch_delete_button"
35+
android:layout_width="0dip"
36+
android:layout_height="wrap_content"
37+
android:layout_weight="1"
38+
android:text="Delete"
39+
/>
40+
<Button
41+
android:id="@+id/batch_flag_button"
42+
android:layout_width="0dip"
43+
android:layout_height="wrap_content"
44+
android:layout_weight="1"
45+
android:text="Flag"
46+
/>
47+
</LinearLayout>
48+
</RelativeLayout>

res/layout/message_list_widgets.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
<!-- http://stackoverflow.com/questions/1121192/android-custom-listview-unable-to-click-on-items
2626
we want something a bit bigger than it is right now -->
2727
<CheckBox
28-
android:id="@+id/selected_checkbox"
29-
android:layout_width="wrap_content"
30-
android:layout_height="wrap_content"
31-
android:layout_centerVertical="true"
32-
android:focusable="true"
33-
android:button="@drawable/checkbox"
34-
android:text=""
35-
/>
36-
</LinearLayout>
28+
android:id="@+id/selected_checkbox"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:layout_centerVertical="true"
32+
android:focusable="true"
33+
android:button="@drawable/checkbox"
34+
android:background="@drawable/checkbox_background"
35+
/>
36+
</LinearLayout>

res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,5 +562,6 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
562562
<string name="background_ops_never">Never</string>
563563
<string name="background_ops_always">Always</string>
564564
<string name="background_ops_enabled">When \'Background data\' is checked</string>
565-
565+
566+
<string name="no_message_seletected_toast">No message selected</string>
566567
</resources>

src/com/android/email/MessagingController.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,16 +3240,27 @@ private void moveOrCopyMessageSynchronous(final Account account, final String sr
32403240
throw new RuntimeException("Error moving message", me);
32413241
}
32423242
}
3243-
3244-
3245-
public void deleteMessages(final Account account, final String folder, final Message[] messages,
3246-
final MessagingListener listener)
3243+
3244+
public void deleteMessageList(final Account account, final String folder, final List<Message> messageList,
3245+
final MessagingListener listener)
32473246
{
3248-
for (Message message : messages)
3247+
for (Message message : messageList)
32493248
{
3250-
deleteMessage(account, folder, message, listener);
3249+
suppressMessage(account, folder, message);
32513250
}
3251+
3252+
put("deleteMessageList", null, new Runnable()
3253+
{
3254+
public void run()
3255+
{
3256+
for (Message message : messageList)
3257+
{
3258+
deleteMessageSynchronous(account, folder, message, listener);
3259+
}
3260+
}
3261+
});
32523262
}
3263+
32533264
public void deleteMessage(final Account account, final String folder, final Message message,
32543265
final MessagingListener listener)
32553266
{

src/com/android/email/activity/MessageList.java

Lines changed: 100 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,26 @@
2525
import android.view.Menu;
2626
import android.view.MenuItem;
2727
import android.view.View;
28-
import android.view.View.OnKeyListener;
2928
import android.view.View.OnClickListener;
30-
import android.view.View.OnFocusChangeListener;
3129
import android.view.ViewGroup;
3230
import android.view.Window;
3331
import android.view.ContextMenu.ContextMenuInfo;
32+
import android.widget.AdapterView;
3433
import android.widget.BaseAdapter;
3534
import android.widget.ListView;
36-
import android.widget.AdapterView;
3735
import android.widget.ProgressBar;
3836
import android.widget.TextView;
3937
import android.widget.ImageButton;
40-
import android.widget.Button;
41-
import android.widget.CheckBox;
4238
import android.widget.Toast;
4339
import android.widget.AdapterView.AdapterContextMenuInfo;
44-
import android.widget.AdapterView.OnItemClickListener;
4540

41+
import android.widget.Button;
4642
import android.widget.CheckBox;
4743
import android.widget.CompoundButton;
4844
import android.widget.CompoundButton.OnCheckedChangeListener;
49-
import com.android.email.K9ListActivity;
5045
import com.android.email.Account;
5146
import com.android.email.Email;
47+
import com.android.email.K9Activity;
5248
import com.android.email.MessagingController;
5349
import com.android.email.MessagingListener;
5450
import com.android.email.R;
@@ -76,7 +72,9 @@
7672
*
7773
*/
7874

79-
public class MessageList extends K9ListActivity
75+
public class MessageList
76+
extends K9Activity
77+
implements OnClickListener, AdapterView.OnItemClickListener
8078
{
8179

8280
private static final int DIALOG_MARK_ALL_AS_READ = 1;
@@ -87,13 +85,12 @@ public class MessageList extends K9ListActivity
8785

8886
private static final String EXTRA_ACCOUNT = "account";
8987
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+
9290
private static final String STATE_KEY_LIST = "com.android.email.activity.messagelist_state";
93-
9491
private static final String STATE_CURRENT_FOLDER = "com.android.email.activity.messagelist_folder";
9592
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";
9794

9895
private static final int WIDGET_NONE = 1;
9996
private static final int WIDGET_FLAG = 2;
@@ -159,6 +156,13 @@ public class MessageList extends K9ListActivity
159156

160157
private boolean mStartup = false;
161158

159+
private int mSelectedCount = 0;
160+
161+
private View mBatchButtonArea;
162+
private Button mBatchReadButton;
163+
private Button mBatchDeleteButton;
164+
private Button mBatchFlagButton;
165+
162166
private DateFormat getDateFormat()
163167
{
164168
if (dateFormat == null)
@@ -386,7 +390,8 @@ public static void actionHandleFolder(Context context, Account account, String f
386390
context.startActivity(intent);
387391
}
388392

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)
390395
{
391396
if ((position+1) == (mAdapter.getCount()))
392397
{
@@ -411,12 +416,15 @@ public void onCreate(Bundle savedInstanceState)
411416

412417
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
413418

414-
mListView = getListView();
419+
setContentView(R.layout.message_list);
420+
421+
mListView = (ListView) findViewById(R.id.message_list);
415422
mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET);
416423
mListView.setLongClickable(true);
417424
mListView.setFastScrollEnabled(true);
418425
mListView.setScrollingCacheEnabled(true);
419-
426+
mListView.setOnItemClickListener(this);
427+
420428
registerForContextMenu(mListView);
421429

422430
/*
@@ -427,6 +435,14 @@ public void onCreate(Bundle savedInstanceState)
427435

428436
mInflater = getLayoutInflater();
429437

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+
430446
Intent intent = getIntent();
431447
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
432448
mStartup = (boolean)intent.getBooleanExtra(EXTRA_STARTUP, false);
@@ -446,11 +462,9 @@ public void onCreate(Bundle savedInstanceState)
446462
else
447463
{
448464
mFolderName = savedInstanceState.getString(STATE_CURRENT_FOLDER);
465+
mSelectedCount = savedInstanceState.getInt(STATE_KEY_SELECTED_COUNT);
449466
}
450467

451-
452-
453-
454468
/*
455469
* Since the color chip is always the same color for a given account we just
456470
* cache the id of the chip right here.
@@ -469,7 +483,7 @@ public void onCreate(Bundle savedInstanceState)
469483

470484
mCurrentFolder = mAdapter.getFolder(mFolderName);
471485

472-
setListAdapter(mAdapter);
486+
mListView.setAdapter(mAdapter);
473487

474488
if (savedInstanceState != null)
475489
{
@@ -541,6 +555,7 @@ public void onSaveInstanceState(Bundle outState)
541555
outState.putParcelable(STATE_KEY_LIST, mListView.onSaveInstanceState());
542556
outState.putInt(STATE_KEY_SELECTION, mListView .getSelectedItemPosition());
543557
outState.putString(STATE_CURRENT_FOLDER, mCurrentFolder.name);
558+
outState.putInt(STATE_KEY_SELECTED_COUNT, mSelectedCount);
544559
}
545560

546561

@@ -1833,9 +1848,11 @@ public void onClick(View v)
18331848

18341849

18351850
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;
18361854
holder.selected.setChecked(message.selected);
18371855

1838-
18391856
if (message.downloaded)
18401857
{
18411858
holder.chip.getBackground().setAlpha(message.read ? 0 : 127);
@@ -1868,6 +1885,7 @@ public void onClick(View v)
18681885
holder.from.setTypeface(null, Typeface.NORMAL);
18691886
holder.date.setText("No date");
18701887
holder.from.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
1888+
//WARNING: Order of the next 2 lines matter
18711889
holder.position = -1;
18721890
holder.selected.setChecked(false);
18731891
holder.flagged.setChecked(false);
@@ -2147,7 +2165,28 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
21472165
if (position!=-1)
21482166
{
21492167
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+
}
21512190
}
21522191
}
21532192
}
@@ -2268,4 +2307,44 @@ public void populate(Folder folder)
22682307
}
22692308
}
22702309

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+
22712350
}

0 commit comments

Comments
 (0)