diff --git a/res/layout/folder_list_item.xml b/res/layout/folder_list_item.xml index 3d747ac57..520a38a81 100644 --- a/res/layout/folder_list_item.xml +++ b/res/layout/folder_list_item.xml @@ -40,6 +40,7 @@ android:layout_height="wrap_content" /> + android:layout_alignParentTop="true" + android:clickable="true" + /> diff --git a/src/com/fsck/k9/MessagingController.java b/src/com/fsck/k9/MessagingController.java index ba004c855..f5506b487 100644 --- a/src/com/fsck/k9/MessagingController.java +++ b/src/com/fsck/k9/MessagingController.java @@ -701,7 +701,7 @@ public class MessagingController implements Runnable public void searchLocalMessages(SearchSpecification searchSpecification, final Message[] messages, final MessagingListener listener) { - searchLocalMessages(searchSpecification.getAccountUuids(), null, messages, + searchLocalMessages(searchSpecification.getAccountUuids(), searchSpecification.getFolderNames(), messages, searchSpecification.getQuery(), searchSpecification.isIntegrate(), searchSpecification.getRequiredFlags(), searchSpecification.getForbiddenFlags(), listener); } @@ -719,20 +719,33 @@ public class MessagingController implements Runnable public void searchLocalMessages(final String[] accountUuids, final String[] folderNames, final Message[] messages, final String query, final boolean integrate, final Flag[] requiredFlags, final Flag[] forbiddenFlags, final MessagingListener listener) { - final AccountStats stats = new AccountStats(); - final Set accountUuidsSet = new HashSet(); - if (accountUuids != null) + if (K9.DEBUG) { - for (String accountUuid : accountUuids) - { - accountUuidsSet.add(accountUuid); - } + Log.i(K9.LOG_TAG, "searchLocalMessages (" + + "accounts=" + Utility.combine(accountUuids, ',') + + ", folders = " + Utility.combine(folderNames, ',') + + ", messages.size() = " + (messages != null ? messages.length : null) + + ", query = " + query + + ", integrate = " + integrate + + ", requiredFlags = " + Utility.combine(requiredFlags, ',') + + ", forbiddenFlags = " + Utility.combine(forbiddenFlags, ',') + + ")"); } + threadPool.execute(new Runnable() { public void run() { + final AccountStats stats = new AccountStats(); + final Set accountUuidsSet = new HashSet(); + if (accountUuids != null) + { + for (String accountUuid : accountUuids) + { + accountUuidsSet.add(accountUuid); + } + } final Preferences prefs = Preferences.getPreferences(mApplication.getApplicationContext()); Account[] accounts = prefs.getAccounts(); List foldersToSearch = null; @@ -768,20 +781,20 @@ public class MessagingController implements Runnable listener.listLocalMessagesStarted(account, null); } - if (integrate || displayableOnly || folderNames != null || noSpecialFolders) + if (integrate || displayableOnly || folderNames != null || noSpecialFolders) { List tmpFoldersToSearch = new LinkedList(); try { LocalStore store = account.getLocalStore(); List folders = store.getPersonalNamespaces(); - ArrayList folderNameList = null; + Set folderNameSet = null; if (folderNames != null) { - folderNameList = new ArrayList(); + folderNameSet = new HashSet(); for (String folderName : folderNames) { - folderNameList.add(folderName); + folderNameSet.add(folderName); } } for (Folder folder : folders) @@ -796,9 +809,13 @@ public class MessagingController implements Runnable } else { - if (folderNameList != null && folderNameList.contains(localFolder.getName()) == false) + if (folderNameSet != null) { - include = false; + if (folderNameSet.contains(localFolderName) == false) + + { + include = false; + } } else if (noSpecialFolders && ( localFolderName.equals(account.getTrashFolderName()) || @@ -836,12 +853,7 @@ public class MessagingController implements Runnable public void messageFinished(Message message, int number, int ofTotal) { List messages = new ArrayList(); - LocalFolder localFolder = (LocalStore.LocalFolder)message.getFolder(); - if (localFolder.getName().equals(localFolder.getAccount().getErrorFolderName())) - { - return; - } - + messages.add(message); stats.unreadMessageCount += (message.isSet(Flag.SEEN) == false) ? 1 : 0; stats.flaggedMessageCount += (message.isSet(Flag.FLAGGED)) ? 1 : 0; @@ -2934,7 +2946,6 @@ public class MessagingController implements Runnable { throw new IllegalArgumentException("Message not found: folder=" + folder + ", uid=" + uid); } - for (MessagingListener l : getListeners()) { l.loadMessageForViewHeadersAvailable(account, folder, uid, message); diff --git a/src/com/fsck/k9/SearchAccount.java b/src/com/fsck/k9/SearchAccount.java index df804d37c..bdb999f92 100644 --- a/src/com/fsck/k9/SearchAccount.java +++ b/src/com/fsck/k9/SearchAccount.java @@ -9,7 +9,6 @@ import java.util.UUID; import android.content.Context; import com.fsck.k9.mail.Flag; -import com.fsck.k9.mail.Message; public class SearchAccount implements BaseAccount, SearchSpecification, Serializable { @@ -22,6 +21,7 @@ public class SearchAccount implements BaseAccount, SearchSpecification, Serializ private String mUuid = UUID.randomUUID().toString(); private boolean builtin = false; private String[] accountUuids = null; + private String[] folderNames = null; public SearchAccount(Preferences preferences) { @@ -122,4 +122,13 @@ public class SearchAccount implements BaseAccount, SearchSpecification, Serializ { this.accountUuids = accountUuids; } + @Override + public String[] getFolderNames() + { + return folderNames; + } + public void setFolderNames(String[] folderNames) + { + this.folderNames = folderNames; + } } \ No newline at end of file diff --git a/src/com/fsck/k9/SearchSpecification.java b/src/com/fsck/k9/SearchSpecification.java index dc9791397..4d433645c 100644 --- a/src/com/fsck/k9/SearchSpecification.java +++ b/src/com/fsck/k9/SearchSpecification.java @@ -15,4 +15,6 @@ public interface SearchSpecification public String getQuery(); public String[] getAccountUuids(); + + public String[] getFolderNames(); } \ No newline at end of file diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java index 02166b9f7..ac64fce1e 100644 --- a/src/com/fsck/k9/activity/Accounts.java +++ b/src/com/fsck/k9/activity/Accounts.java @@ -968,6 +968,12 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC { return false; } + + @Override + public String[] getFolderNames() + { + return null; + } }; MessageList.actionHandle(Accounts.this, description, searchSpec); @@ -975,23 +981,5 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC } } - - - private enum SearchModifier - { - FLAGGED(R.string.flagged_modifier, new Flag[] { Flag.FLAGGED}, null), UNREAD(R.string.unread_modifier, null, new Flag[] { Flag.SEEN} ); - - final int resId; - final Flag[] requiredFlags; - final Flag[] forbiddenFlags; - - SearchModifier(int nResId, Flag[] nRequiredFlags, Flag[] nForbiddenFlags) - { - resId = nResId; - requiredFlags = nRequiredFlags; - forbiddenFlags = nForbiddenFlags; - } - - } } diff --git a/src/com/fsck/k9/activity/FolderList.java b/src/com/fsck/k9/activity/FolderList.java index 40ca2628c..0e2d7d5d1 100644 --- a/src/com/fsck/k9/activity/FolderList.java +++ b/src/com/fsck/k9/activity/FolderList.java @@ -16,6 +16,7 @@ import android.util.Log; import android.util.TypedValue; import android.view.*; import android.view.ContextMenu.ContextMenuInfo; +import android.view.View.OnClickListener; import android.widget.*; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; @@ -23,6 +24,7 @@ import com.fsck.k9.*; import com.fsck.k9.Account.FolderMode; import com.fsck.k9.activity.setup.AccountSettings; import com.fsck.k9.activity.setup.FolderSettings; +import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.Folder; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.MessagingException; @@ -64,7 +66,6 @@ public class FolderList extends K9ListActivity private FolderListHandler mHandler = new FolderListHandler(); private int mUnreadMessageCount; - private int mFlaggedMessageCount; private FontSizes mFontSizes = K9.getFontSizes(); @@ -1190,6 +1191,7 @@ public class FolderList extends K9ListActivity holder.newMessageCount = (TextView) view.findViewById(R.id.folder_unread_message_count); holder.flaggedMessageCount = (TextView) view.findViewById(R.id.folder_flagged_message_count); holder.folderStatus = (TextView) view.findViewById(R.id.folder_status); + holder.activeIcons = (RelativeLayout) view.findViewById(R.id.active_icons); holder.chip = view.findViewById(R.id.chip); holder.rawFolderName = folder.name; @@ -1240,6 +1242,7 @@ public class FolderList extends K9ListActivity { holder.newMessageCount.setText(Integer .toString(folder.unreadMessageCount)); + holder.newMessageCount.setOnClickListener(new FolderClickListener(mAccount, folder.name, folder.displayName, SearchModifier.UNREAD)); holder.newMessageCount.setVisibility(View.VISIBLE); } else @@ -1251,13 +1254,23 @@ public class FolderList extends K9ListActivity { holder.flaggedMessageCount.setText(Integer .toString(folder.flaggedMessageCount)); + holder.flaggedMessageCount.setOnClickListener(new FolderClickListener(mAccount, folder.name, folder.displayName, SearchModifier.FLAGGED)); holder.flaggedMessageCount.setVisibility(View.VISIBLE); } else { holder.flaggedMessageCount.setVisibility(View.GONE); } - + holder.activeIcons.setOnClickListener(new OnClickListener() + { + public void onClick(View v) + { + Toast toast = Toast.makeText(getApplication(), getString(R.string.tap_hint), Toast.LENGTH_SHORT); + toast.show(); + } + } + ); + holder.chip.setBackgroundResource(K9.COLOR_CHIP_RES_IDS[mAccount.getAccountNumber() % K9.COLOR_CHIP_RES_IDS.length]); holder.chip.getBackground().setAlpha(folder.unreadMessageCount == 0 ? 127 : 255); @@ -1422,8 +1435,77 @@ public class FolderList extends K9ListActivity public TextView newMessageCount; public TextView flaggedMessageCount; + public RelativeLayout activeIcons; public String rawFolderName; public View chip; } + + private class FolderClickListener implements OnClickListener + { + + final BaseAccount account; + final String folderName; + final String displayName; + final SearchModifier searchModifier; + FolderClickListener(BaseAccount nAccount, String folderName, String displayName, SearchModifier nSearchModifier ) + { + account = nAccount; + this.folderName = folderName; + searchModifier = nSearchModifier; + this.displayName = displayName; + } + @Override + public void onClick(View v) + { + String description = getString(R.string.search_title, + getString(R.string.message_list_title, account.getDescription(), displayName), + getString(searchModifier.resId)); + + SearchSpecification searchSpec = new SearchSpecification() + { + @Override + public String[] getAccountUuids() + { + return new String[] { account.getUuid() }; + } + + @Override + public Flag[] getForbiddenFlags() + { + return searchModifier.forbiddenFlags; + } + + @Override + public String getQuery() + { + return ""; + } + + @Override + public Flag[] getRequiredFlags() + { + return searchModifier.requiredFlags; + } + + @Override + public boolean isIntegrate() + { + return false; + } + + @Override + public String[] getFolderNames() + { + return new String[] { folderName }; + } + + }; + MessageList.actionHandle(FolderList.this, description, searchSpec); + + } + + } + + } diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 4b636291c..d4a42a4dc 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -67,7 +67,8 @@ public class MessageList private static final String EXTRA_QUERY_FLAGS = "queryFlags"; private static final String EXTRA_FORBIDDEN_FLAGS = "forbiddenFlags"; private static final String EXTRA_INTEGRATE = "integrate"; - private static final String EXTRA_ACCOUNT_UUIDS = "accountUuids"; + private static final String EXTRA_ACCOUNT_UUIDS = "accountUuids"; + private static final String EXTRA_FOLDER_NAMES = "folderNames"; private static final String EXTRA_TITLE = "title"; private ListView mListView; @@ -99,6 +100,7 @@ public class MessageList private Flag[] mForbiddenFlags = null; private boolean mIntegrate = false; private String[] mAccountUuids = null; + private String[] mFolderNames = null; private String mTitle; private MessageListHandler mHandler = new MessageListHandler(); @@ -343,6 +345,7 @@ public class MessageList } intent.putExtra(EXTRA_INTEGRATE, searchSpecification.isIntegrate()); intent.putExtra(EXTRA_ACCOUNT_UUIDS, searchSpecification.getAccountUuids()); + intent.putExtra(EXTRA_FOLDER_NAMES, searchSpecification.getFolderNames()); intent.putExtra(EXTRA_TITLE, title); context.startActivity(intent); @@ -414,7 +417,7 @@ public class MessageList } mIntegrate = intent.getBooleanExtra(EXTRA_INTEGRATE, false); mAccountUuids = intent.getStringArrayExtra(EXTRA_ACCOUNT_UUIDS); - + mFolderNames = intent.getStringArrayExtra(EXTRA_FOLDER_NAMES); mTitle = intent.getStringExtra(EXTRA_TITLE); // Take the initial folder into account only if we are *not* restoring the @@ -488,7 +491,7 @@ public class MessageList } else if (mQueryString != null) { - mController.searchLocalMessages(mAccountUuids, null, null, mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags, mAdapter.mListener); + mController.searchLocalMessages(mAccountUuids, mFolderNames, null, mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags, mAdapter.mListener); } mHandler.refreshTitle(); diff --git a/src/com/fsck/k9/activity/SearchModifier.java b/src/com/fsck/k9/activity/SearchModifier.java new file mode 100644 index 000000000..a6c86f878 --- /dev/null +++ b/src/com/fsck/k9/activity/SearchModifier.java @@ -0,0 +1,24 @@ +/** + * + */ +package com.fsck.k9.activity; + +import com.fsck.k9.R; +import com.fsck.k9.mail.Flag; + +enum SearchModifier +{ + FLAGGED(R.string.flagged_modifier, new Flag[] { Flag.FLAGGED}, null), UNREAD(R.string.unread_modifier, null, new Flag[] { Flag.SEEN} ); + + final int resId; + final Flag[] requiredFlags; + final Flag[] forbiddenFlags; + + SearchModifier(int nResId, Flag[] nRequiredFlags, Flag[] nForbiddenFlags) + { + resId = nResId; + requiredFlags = nRequiredFlags; + forbiddenFlags = nForbiddenFlags; + } + +} \ No newline at end of file