1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-24 16:48:50 -05:00

Add context action bar on FolderList activity.

This commit is contained in:
Sander Bogaert 2012-08-28 15:23:25 -04:00 committed by Andrew Chen
parent c0e483d2b9
commit a5b8ce8064
6 changed files with 143 additions and 128 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 430 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -1,36 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/open_folder"
android:title="@string/open_action"
/>
<item
android:id="@+id/mark_all_as_read"
android:title="@string/mark_all_as_read_action"
/>
<item
android:id="@+id/empty_trash"
android:title="@string/empty_trash_action"
/>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/check_mail"
android:title="@string/check_mail_action"
/>
android:icon="@drawable/ic_action_refresh"
android:showAsAction="always"
android:title="@string/check_mail_action"/>
<item
android:id="@+id/empty_trash"
android:icon="@drawable/ic_action_delete"
android:showAsAction="always"
android:title="@string/empty_trash_action"/>
<item
android:id="@+id/folder_settings"
android:icon="@drawable/ic_action_settings"
android:showAsAction="always"
android:title="@string/folder_settings_action"/>
<item
android:id="@+id/mark_all_as_read"
android:icon="@drawable/ic_action_read"
android:showAsAction="always"
android:title="@string/mark_all_as_read_action"/>
<item
android:id="@+id/send_messages"
android:title="@string/send_messages_action"
/>
<item
android:id="@+id/folder_settings"
android:title="@string/folder_settings_action"
/>
android:showAsAction="never"
android:title="@string/send_messages_action"/>
<item
android:id="@+id/clear_local_folder"
android:title="@string/clear_local_folder_action"
/>
android:showAsAction="never"
android:title="@string/clear_local_folder_action"/>
<item
android:id="@+id/expunge"
android:title="@string/expunge_action"
/>
android:showAsAction="never"
android:title="@string/expunge_action"/>
</menu>

View File

@ -19,16 +19,14 @@ import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.Filter;
@ -40,11 +38,10 @@ import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.fsck.k9.Account;
import com.fsck.k9.Account.FolderMode;
import com.fsck.k9.AccountStats;
@ -55,7 +52,6 @@ import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.SearchSpecification;
import com.fsck.k9.activity.FolderList.FolderListAdapter.FolderListFilter;
import com.fsck.k9.activity.misc.ActionBarNavigationSpinner;
import com.fsck.k9.activity.setup.AccountSettings;
import com.fsck.k9.activity.setup.FolderSettings;
import com.fsck.k9.activity.setup.Prefs;
@ -76,7 +72,7 @@ import com.fsck.k9.service.MailService;
* Activity shows list of the Account's folders
*/
public class FolderList extends K9ListActivity implements OnNavigationListener {
public class FolderList extends K9ListActivity {
/*
* Constants for showDialog() etc.
*/
@ -103,6 +99,8 @@ public class FolderList extends K9ListActivity implements OnNavigationListener {
private int mUnreadMessageCount;
private FolderInfoHolder mSelectedContextFolder = null;
private FontSizes mFontSizes = K9.getFontSizes();
private Context context;
@ -306,6 +304,27 @@ public class FolderList extends K9ListActivity implements OnNavigationListener {
onOpenFolder(((FolderInfoHolder)mAdapter.getItem(position)).name);
}
});
// Enable context action bar behaviour
mListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
// is already in selection mode we ignore the next long presses
if (mSelectedContextFolder != null) {
return false;
}
// this cast will always be safe
mSelectedContextFolder = (FolderInfoHolder) mAdapter.getItem(position);
mActionMode = FolderList.this.startActionMode(mActionModeCallback);
mActionMode.invalidate();
mActionMode.setTitle(String.format(getString(R.string.actionbar_string_selected),
mSelectedContextFolder.displayName));
return true;
}});
registerForContextMenu(mListView);
mListView.setSaveEnabled(true);
@ -329,19 +348,6 @@ public class FolderList extends K9ListActivity implements OnNavigationListener {
mActionBar.setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
if (itemId == ActionBarNavigationSpinner.AB_NAVIGATION_INBOX) {
onOpenFolder(mAccount.getInboxFolderName());
return true;
} else if (itemId == ActionBarNavigationSpinner.AB_NAVIGATION_ACCOUNTS) {
onAccounts();
return true;
}
return false;
}
@Override
public void onNewIntent(Intent intent) {
setIntent(intent); // onNewIntent doesn't autoset our "internal" intent
@ -660,54 +666,6 @@ public class FolderList extends K9ListActivity implements OnNavigationListener {
return true;
}
@Override public boolean onContextItemSelected(android.view.MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item .getMenuInfo();
FolderInfoHolder folder = (FolderInfoHolder) mAdapter.getItem(info.position);
switch (item.getItemId()) {
case R.id.open_folder:
onOpenFolder(folder.name);
break;
case R.id.mark_all_as_read:
onMarkAllAsRead(mAccount, folder.name);
break;
case R.id.send_messages:
sendMail(mAccount);
break;
case R.id.check_mail:
checkMail(folder);
break;
case R.id.folder_settings:
onEditFolder(mAccount, folder.name);
break;
case R.id.empty_trash:
onEmptyTrash(mAccount);
break;
case R.id.expunge:
onExpunge(mAccount, folder.name);
break;
case R.id.clear_local_folder:
onClearFolder(mAccount, folder.name);
break;
}
return super.onContextItemSelected(item);
}
private FolderInfoHolder mSelectedContextFolder = null;
private void onMarkAllAsRead(final Account account, final String folder) {
mSelectedContextFolder = mAdapter.getFolder(folder);
if (K9.confirmMarkAllAsRead()) {
@ -820,39 +778,6 @@ public class FolderList extends K9ListActivity implements OnNavigationListener {
}
}
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
getMenuInflater().inflate(R.menu.folder_context, menu);
FolderInfoHolder folder = (FolderInfoHolder) mAdapter.getItem(info.position);
menu.setHeaderTitle(folder.displayName);
if (!folder.name.equals(mAccount.getTrashFolderName()))
menu.findItem(R.id.empty_trash).setVisible(false);
if (folder.name.equals(mAccount.getOutboxFolderName())) {
menu.findItem(R.id.check_mail).setVisible(false);
} else {
menu.findItem(R.id.send_messages).setVisible(false);
}
if (K9.ERROR_FOLDER_NAME.equals(folder.name)) {
menu.findItem(R.id.expunge).setVisible(false);
}
if (!MessagingController.getInstance(getApplication()).isMoveCapable(mAccount)) {
// FIXME: Really we want to do this for all local-only folders
if (!mAccount.getInboxFolderName().equals(folder.name)) {
menu.findItem(R.id.check_mail).setVisible(false);
}
menu.findItem(R.id.expunge).setVisible(false);
}
menu.setHeaderTitle(folder.displayName);
}
class FolderListAdapter extends BaseAdapter implements Filterable {
private ArrayList<FolderInfoHolder> mFolders = new ArrayList<FolderInfoHolder>();
private List<FolderInfoHolder> mFilteredFolders = Collections.unmodifiableList(mFolders);
@ -1459,4 +1384,93 @@ public class FolderList extends K9ListActivity implements OnNavigationListener {
MessageList.actionHandle(context, description, searchSpec);
}
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
FolderInfoHolder folder = mSelectedContextFolder;
menu.findItem(R.id.empty_trash).setVisible(
folder.name.equals(mAccount.getTrashFolderName()) ? false : true);
if (folder.name.equals(mAccount.getOutboxFolderName())) {
menu.findItem(R.id.check_mail).setVisible(false);
menu.findItem(R.id.send_messages).setVisible(true);
} else {
menu.findItem(R.id.send_messages).setVisible(false);
menu.findItem(R.id.check_mail).setVisible(true);
}
menu.findItem(R.id.expunge).setVisible(
K9.ERROR_FOLDER_NAME.equals(folder.name) ? false : true);
if (!MessagingController.getInstance(getApplication()).isMoveCapable(mAccount)) {
// FIXME: Really we want to do this for all local-only folders
if (!mAccount.getInboxFolderName().equals(folder.name)) {
menu.findItem(R.id.check_mail).setVisible(false);
} else {
menu.findItem(R.id.check_mail).setVisible(true);
}
menu.findItem(R.id.expunge).setVisible(false);
} else {
menu.findItem(R.id.expunge).setVisible(true);
}
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mSelectedContextFolder = null;
mActionMode = null;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.folder_context, menu);
return true;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {;
FolderInfoHolder folder= mSelectedContextFolder;
switch (item.getItemId()) {
case R.id.mark_all_as_read:
onMarkAllAsRead(mAccount, folder.name);
break;
case R.id.send_messages:
sendMail(mAccount);
break;
case R.id.check_mail:
checkMail(folder);
break;
case R.id.folder_settings:
onEditFolder(mAccount, folder.name);
break;
case R.id.empty_trash:
onEmptyTrash(mAccount);
break;
case R.id.expunge:
onExpunge(mAccount, folder.name);
break;
case R.id.clear_local_folder:
onClearFolder(mAccount, folder.name);
break;
}
return true;
}
};
}