1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Implements new "Batch ops" option menu in Message List. Provides for

flag/unflag, mark as read/unread and delete.  Also provides explicit
mode changing, and select/deselect all.  Move and copy are partially
implemented, but disabled.

Desperately needs a new icon.

The "Sort by..." menu now toggles ascending/descending when the
currently selected sort mode is clicked.

Also, an ineffective change to setting the title in the Message List.
A bit more work is in order on that.
This commit is contained in:
Daniel Applebaum 2009-12-10 05:26:16 +00:00
parent 5b1c5b2289
commit 0cd2dfb77d
3 changed files with 327 additions and 55 deletions

View File

@ -37,11 +37,61 @@
/>
</menu>
</item>
<item
android:id="@+id/reverse_sort"
android:title="@string/reverse_sort_action"
android:icon="@drawable/ic_menu_reverse_sort"
/>
<item
android:id="@+id/batch_ops"
android:title="@string/batch_ops"
android:icon="@drawable/ic_menu_reverse_sort">
<menu>
<item
android:id="@+id/batch_delete_op"
android:title="@string/batch_delete_op"
/>
<item
android:id="@+id/batch_mark_read_op"
android:title="@string/batch_mark_read_op"
/>
<item
android:id="@+id/batch_flag_op"
android:title="@string/batch_flag_op"
/>
<item
android:id="@+id/batch_mark_unread_op"
android:title="@string/batch_mark_unread_op"
/>
<item
android:id="@+id/batch_unflag_op"
android:title="@string/batch_unflag_op"
/>
<item
android:id="@+id/batch_move_op"
android:title="@string/batch_move_op"
/>
<item
android:id="@+id/batch_copy_op"
android:title="@string/batch_copy_op"
/>
<item
android:id="@+id/batch_flag_mode"
android:title="@string/batch_flag_mode"
/>
<item
android:id="@+id/batch_select_mode"
android:title="@string/batch_select_mode"
/>
<item
android:id="@+id/batch_plain_mode"
android:title="@string/batch_plain_mode"
/>
<item
android:id="@+id/batch_select_all"
android:title="@string/batch_select_all"
/>
<item
android:id="@+id/batch_deselect_all"
android:title="@string/batch_deselect_all"
/>
</menu>
</item>
<item
android:id="@+id/list_folders"
android:alphabeticShortcut="f"

View File

@ -573,5 +573,18 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="date_format_common">dd-MMM-yyyy</string>
<string name="date_format_iso8601">yyyy-MM-dd</string>
<string name="batch_ops">Batch Ops</string>
<string name="batch_delete_op">Delete selected</string>
<string name="batch_mark_read_op">Mark selected read</string>
<string name="batch_mark_unread_op">Mark selected unread</string>
<string name="batch_flag_op">Flag selected</string>
<string name="batch_unflag_op">Unflag selected</string>
<string name="batch_move_op">Move selected</string>
<string name="batch_copy_op">Copy selected</string>
<string name="batch_flag_mode">Star mode</string>
<string name="batch_select_mode">Select mode</string>
<string name="batch_plain_mode">Plain mode</string>
<string name="batch_select_all">Select all</string>
<string name="batch_deselect_all">Deselect all</string>
</resources>

View File

@ -433,7 +433,8 @@ public class MessageList
{
onRestoreListState(savedInstanceState);
}
setTitle();
}
private void onRestoreListState(Bundle savedInstanceState)
@ -485,13 +486,17 @@ public class MessageList
notifMgr.cancel(mAccount.getAccountNumber());
notifMgr.cancel(-1000 - mAccount.getAccountNumber());
setTitle();
}
private void setTitle()
{
setTitle(
mAccount.getDescription()
+ " - " +
mCurrentFolder.displayName
);
mAccount.getDescription()
+ " - " +
mCurrentFolder.displayName
);
}
@Override
@ -702,13 +707,11 @@ public class MessageList
case WIDGET_FLAG:
{
mSelectedWidget = WIDGET_MULTISELECT;
showBatchButtons();
break;
}
case WIDGET_MULTISELECT:
{
mSelectedWidget = WIDGET_NONE;
hideBatchButtons();
break;
}
case WIDGET_NONE:
@ -731,13 +734,11 @@ public class MessageList
case WIDGET_NONE:
{
mSelectedWidget=WIDGET_MULTISELECT;
showBatchButtons();
break;
}
case WIDGET_MULTISELECT:
{
mSelectedWidget=WIDGET_FLAG;
hideBatchButtons();
break;
}
@ -745,7 +746,25 @@ public class MessageList
}
configureWidgets();
}
private void configureWidgets()
{
switch (mSelectedWidget)
{
case WIDGET_FLAG:
hideBatchButtons();
break;
case WIDGET_NONE:
hideBatchButtons();
break;
case WIDGET_MULTISELECT:
showBatchButtons();
break;
}
int count = mListView.getChildCount();
for (int i=0; i<count; i++)
{
@ -811,11 +830,18 @@ public class MessageList
private void changeSort(SORT_TYPE newSortType)
{
sortType = newSortType;
MessagingController.getInstance(getApplication()).setSortType(sortType);
sortAscending = MessagingController.getInstance(getApplication()).isSortAscending(sortType);
sortDateAscending = MessagingController.getInstance(getApplication()).isSortAscending(SORT_TYPE.SORT_DATE);
reSort();
if (sortType == newSortType)
{
onToggleSortAscending();
}
else
{
sortType = newSortType;
MessagingController.getInstance(getApplication()).setSortType(sortType);
sortAscending = MessagingController.getInstance(getApplication()).isSortAscending(sortType);
sortDateAscending = MessagingController.getInstance(getApplication()).isSortAscending(SORT_TYPE.SORT_DATE);
reSort();
}
}
private void reSort()
@ -1119,7 +1145,8 @@ public class MessageList
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
int itemId = item.getItemId();
switch (itemId)
{
case R.id.check_mail:
checkMail(mAccount, mFolderName);
@ -1168,11 +1195,6 @@ public class MessageList
return true;
case R.id.reverse_sort:
onToggleSortAscending();
return true;
case R.id.list_folders:
onShowFolderList();
@ -1192,18 +1214,123 @@ public class MessageList
onEditAccount();
return true;
case R.id.batch_select_all:
setAllSelected(true);
return true;
case R.id.batch_deselect_all:
setAllSelected(false);
return true;
case R.id.batch_copy_op:
moveOrCopySelected(false);
return true;
case R.id.batch_move_op:
moveOrCopySelected(true);
return true;
case R.id.batch_delete_op:
deleteSelected();
return true;
case R.id.batch_mark_read_op:
flagSelected(Flag.SEEN, true);
return true;
case R.id.batch_mark_unread_op:
flagSelected(Flag.SEEN, false);
return true;
case R.id.batch_flag_op:
flagSelected(Flag.FLAGGED, true);
return true;
case R.id.batch_unflag_op:
flagSelected(Flag.FLAGGED, false);
return true;
case R.id.batch_plain_mode:
mSelectedWidget = WIDGET_NONE;
configureWidgets();
return true;
case R.id.batch_select_mode:
mSelectedWidget = WIDGET_MULTISELECT;
configureWidgets();
return true;
case R.id.batch_flag_mode:
mSelectedWidget = WIDGET_FLAG;
configureWidgets();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
private final int[] batch_ops = { R.id.batch_copy_op, R.id.batch_delete_op, R.id.batch_flag_op,
R.id.batch_unflag_op, R.id.batch_mark_read_op, R.id.batch_mark_unread_op, R.id.batch_move_op ,
R.id.batch_select_all, R.id.batch_deselect_all };
private final int[] batch_modes = { R.id.batch_flag_mode, R.id.batch_select_mode, R.id.batch_plain_mode };
private void setOpsState(Menu menu, boolean state, boolean enabled)
{
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.message_list_option, menu);
for (int id : batch_ops)
{
menu.findItem(id).setVisible(state);
menu.findItem(id).setEnabled(enabled);
}
}
private void setOpsMode(Menu menu, int currentModeId)
{
for (int id : batch_modes)
{
menu.findItem(id).setVisible(id != currentModeId);
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
switch (mSelectedWidget)
{
case WIDGET_FLAG:
{
setOpsState(menu, false, false);
setOpsMode(menu, R.id.batch_flag_mode);
break;
}
case WIDGET_MULTISELECT:
{
boolean anySelected = anySelected();
setOpsState(menu, true, anySelected);
setOpsMode(menu, R.id.batch_select_mode);
boolean newFlagState = computeBatchDirection(true);
boolean newReadState = computeBatchDirection(false);
menu.findItem(R.id.batch_flag_op).setVisible(newFlagState);
menu.findItem(R.id.batch_unflag_op).setVisible(!newFlagState);
menu.findItem(R.id.batch_mark_read_op).setVisible(newReadState);
menu.findItem(R.id.batch_mark_unread_op).setVisible(!newReadState);
menu.findItem(R.id.batch_deselect_all).setEnabled(anySelected);
menu.findItem(R.id.batch_select_all).setEnabled(true);
// TODO: batch move and copy not yet implemented
menu.findItem(R.id.batch_move_op).setVisible(false);
menu.findItem(R.id.batch_copy_op).setVisible(false);
break;
}
case WIDGET_NONE:
{
setOpsState(menu, false, false);
setOpsMode(menu, R.id.batch_plain_mode);
break;
}
}
if (mCurrentFolder.outbox)
{
menu.findItem(R.id.check_mail).setVisible(false);
@ -1212,6 +1339,16 @@ public class MessageList
{
menu.findItem(R.id.send_messages).setVisible(false);
}
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.message_list_option, menu);
return true;
}
@ -1343,16 +1480,6 @@ public class MessageList
}
}
private String truncateStatus(String mess)
{
if (mess != null && mess.length() > 27)
{
mess = mess.substring(0, 27);
}
return mess;
}
class MessageListAdapter extends BaseAdapter
{
private List<MessageInfoHolder> messages = java.util.Collections.synchronizedList(new ArrayList<MessageInfoHolder>());
@ -2226,44 +2353,67 @@ public class MessageList
}
}
}
public void onClick(View v)
private boolean computeBatchDirection(boolean flagged)
{
boolean newState = false;
List<Message> messageList = new ArrayList<Message>();
for (MessageInfoHolder holder : mAdapter.messages)
{
if (holder.selected)
{
if (v == mBatchDeleteButton)
{
mAdapter.removeMessage(holder);
}
else if (v == mBatchFlagButton)
if (flagged)
{
if (!holder.flagged)
{
newState = true;
}
}
else if (v == mBatchReadButton)
else
{
if (!holder.read)
{
newState = true;
}
}
messageList.add(holder.message);
}
}
return newState;
}
private boolean anySelected()
{
for (MessageInfoHolder holder : mAdapter.messages)
{
if (holder.selected)
{
return true;
}
}
return false;
}
public void onClick(View v)
{
boolean newState = false;
List<Message> messageList = new ArrayList<Message>();
List<MessageInfoHolder> removeHolderList = new ArrayList<MessageInfoHolder>();
if (v == mBatchFlagButton)
{
newState = computeBatchDirection(true);
}
else
{
newState = computeBatchDirection(false);
}
for (MessageInfoHolder holder : mAdapter.messages)
{
if (holder.selected)
{
if (v == mBatchDeleteButton)
{
//nothing
removeHolderList.add(holder);
}
else if (v == mBatchFlagButton)
{
@ -2273,8 +2423,10 @@ public class MessageList
{
holder.read = newState;
}
messageList.add(holder.message);
}
}
mAdapter.removeMessages(removeHolderList);
if (!messageList.isEmpty())
{
@ -2298,5 +2450,62 @@ public class MessageList
mHandler.sortMessages();
}
private void setAllSelected(boolean isSelected)
{
mSelectedCount = 0;
for (MessageInfoHolder holder : mAdapter.messages)
{
holder.selected = isSelected;
mSelectedCount += (isSelected ? 1 : 0);
}
mAdapter.notifyDataSetChanged();
showBatchButtons();
}
private void flagSelected(Flag flag, boolean newState)
{
List<Message> messageList = new ArrayList<Message>();
for (MessageInfoHolder holder : mAdapter.messages)
{
if (holder.selected)
{
messageList.add(holder.message);
if (flag == Flag.SEEN)
{
holder.read = newState;
}
else if (flag == Flag.FLAGGED)
{
holder.flagged = newState;
}
}
}
MessagingController.getInstance(getApplication()).setFlag(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]),
flag , newState);
mHandler.sortMessages();
}
private void deleteSelected()
{
List<Message> messageList = new ArrayList<Message>();
List<MessageInfoHolder> removeHolderList = new ArrayList<MessageInfoHolder>();
for (MessageInfoHolder holder : mAdapter.messages)
{
if (holder.selected)
{
removeHolderList.add(holder);
messageList.add(holder.message);
}
}
mAdapter.removeMessages(removeHolderList);
MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), null);
mSelectedCount = 0;
configureBatchButtons();
}
private void moveOrCopySelected(boolean isMove)
{
}
}