From f550aaefb58bb41ae4b5a358a63b07a7dccc273e Mon Sep 17 00:00:00 2001 From: Sander Bogaert Date: Sat, 13 Oct 2012 14:03:40 -0400 Subject: [PATCH] Add new SearchAccount class and move it together with SearchModifier to the search package ( refactor ). --- src/com/fsck/k9/SearchAccount.java | 153 ------------------ src/com/fsck/k9/activity/AccountList.java | 2 +- src/com/fsck/k9/activity/FolderList.java | 1 + src/com/fsck/k9/provider/MessageProvider.java | 2 +- src/com/fsck/k9/search/SearchAccount.java | 66 ++++++++ .../{activity => search}/SearchModifier.java | 4 +- 6 files changed, 71 insertions(+), 157 deletions(-) delete mode 100644 src/com/fsck/k9/SearchAccount.java create mode 100644 src/com/fsck/k9/search/SearchAccount.java rename src/com/fsck/k9/{activity => search}/SearchModifier.java (90%) diff --git a/src/com/fsck/k9/SearchAccount.java b/src/com/fsck/k9/SearchAccount.java deleted file mode 100644 index 97e2092ee..000000000 --- a/src/com/fsck/k9/SearchAccount.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.fsck.k9; - -import java.io.Serializable; -import java.util.UUID; - -import android.content.Context; - -import com.fsck.k9.mail.Flag; -import com.fsck.k9.search.SearchSpecification; - -/** - * This is a meta-Account that represents one or more accounts with filters on them. The filter specification - * is defined by {@link com.fsck.k9.activity.SearchModifier}. - */ -public class SearchAccount implements BaseAccount, SearchSpecification, Serializable { - /** - * Create a {@code SearchAccount} instance for the Unified Inbox. - * - * @param context - * A {@link Context} instance that will be used to get localized strings and will be - * passed on to the {@code SearchAccount} instance. - * - * @return The {@link SearchAccount} instance for the Unified Inbox. - */ - public static SearchAccount createUnifiedInboxAccount(Context context) { - SearchAccount unifiedInbox = new SearchAccount(context, true, null, null); - unifiedInbox.setDescription(context.getString(R.string.integrated_inbox_title)); - unifiedInbox.setEmail(context.getString(R.string.integrated_inbox_detail)); - return unifiedInbox; - } - - /** - * Create a {@code SearchAccount} instance for the special account "All messages". - * - * @param context - * A {@link Context} instance that will be used to get localized strings and will be - * passed on to the {@code SearchAccount} instance. - * - * @return The {@link SearchAccount} instance for the Unified Inbox. - */ - public static SearchAccount createAllMessagesAccount(Context context) { - SearchAccount allMessages = new SearchAccount(context, false, null, null); - allMessages.setDescription(context.getString(R.string.search_all_messages_title)); - allMessages.setEmail(context.getString(R.string.search_all_messages_detail)); - return allMessages; - } - - - private static final long serialVersionUID = -4388420303235543976L; - private Flag[] mRequiredFlags = null; - private Flag[] mForbiddenFlags = null; - private String email = null; - private String description = null; - private String query = ""; - private boolean integrate = false; - private String mUuid = null; - private boolean builtin = false; - private String[] accountUuids = null; - private String[] folderNames = null; - - public SearchAccount(Preferences preferences) { - } - - protected synchronized void delete(Preferences preferences) { - } - - public synchronized void save(Preferences preferences) { - } - - public SearchAccount(Context context, boolean nintegrate, Flag[] requiredFlags, Flag[] forbiddenFlags) { - mRequiredFlags = requiredFlags; - mForbiddenFlags = forbiddenFlags; - integrate = nintegrate; - } - - @Override - public synchronized String getEmail() { - return email; - } - - @Override - public synchronized void setEmail(String email) { - this.email = email; - } - - public Flag[] getRequiredFlags() { - return mRequiredFlags; - } - - public Flag[] getForbiddenFlags() { - return mForbiddenFlags; - } - - public boolean isIntegrate() { - return integrate; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getQuery() { - return query; - } - - public void setQuery(String query) { - this.query = query; - } - - public String getUuid() { - if (mUuid == null) { - setUuid(UUID.randomUUID().toString()); - } - return mUuid; - } - - public void setUuid(String nUuid) { - mUuid = nUuid; - } - - public void setIntegrate(boolean integrate) { - this.integrate = integrate; - } - - public boolean isBuiltin() { - return builtin; - } - - public void setBuiltin(boolean builtin) { - this.builtin = builtin; - } - - public String[] getAccountUuids() { - return accountUuids; - } - - public void setAccountUuids(String[] accountUuids) { - this.accountUuids = accountUuids; - } - - @Override - public String[] getFolderNames() { - return folderNames; - } - - public void setFolderNames(String[] folderNames) { - this.folderNames = folderNames; - } -} diff --git a/src/com/fsck/k9/activity/AccountList.java b/src/com/fsck/k9/activity/AccountList.java index 52c64dbe3..9c17ffd42 100644 --- a/src/com/fsck/k9/activity/AccountList.java +++ b/src/com/fsck/k9/activity/AccountList.java @@ -21,7 +21,7 @@ import com.fsck.k9.FontSizes; import com.fsck.k9.K9; import com.fsck.k9.Preferences; import com.fsck.k9.R; -import com.fsck.k9.SearchAccount; +import com.fsck.k9.search.SearchAccount; /** diff --git a/src/com/fsck/k9/activity/FolderList.java b/src/com/fsck/k9/activity/FolderList.java index dc034c4ba..e4c2a3e2a 100644 --- a/src/com/fsck/k9/activity/FolderList.java +++ b/src/com/fsck/k9/activity/FolderList.java @@ -67,6 +67,7 @@ import com.fsck.k9.mail.Folder; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.store.LocalStore.LocalFolder; +import com.fsck.k9.search.SearchModifier; import com.fsck.k9.search.SearchSpecification; import com.fsck.k9.service.MailService; diff --git a/src/com/fsck/k9/provider/MessageProvider.java b/src/com/fsck/k9/provider/MessageProvider.java index 1e351d057..05428b6cb 100644 --- a/src/com/fsck/k9/provider/MessageProvider.java +++ b/src/com/fsck/k9/provider/MessageProvider.java @@ -21,7 +21,6 @@ import com.fsck.k9.Account; import com.fsck.k9.AccountStats; import com.fsck.k9.K9; import com.fsck.k9.Preferences; -import com.fsck.k9.SearchAccount; import com.fsck.k9.activity.FolderInfoHolder; import com.fsck.k9.activity.MessageInfoHolder; import com.fsck.k9.activity.MessageList; @@ -34,6 +33,7 @@ import com.fsck.k9.mail.Folder; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.store.LocalStore; +import com.fsck.k9.search.SearchAccount; import java.lang.ref.WeakReference; import java.util.ArrayList; diff --git a/src/com/fsck/k9/search/SearchAccount.java b/src/com/fsck/k9/search/SearchAccount.java new file mode 100644 index 000000000..d58c62de1 --- /dev/null +++ b/src/com/fsck/k9/search/SearchAccount.java @@ -0,0 +1,66 @@ +package com.fsck.k9.search; + +import java.util.UUID; + +import com.fsck.k9.BaseAccount; + +/** + * This class is basically a wrapper around a LocalSearch. It allows to expose it as + * an account. This is a meta-account containing all the e-mail that matches the search. + */ +public class SearchAccount implements BaseAccount { + + private String mEmail = null; + private String mDescription = null; + private LocalSearch mSearch = null; + private String mFakeUuid = null; + + public SearchAccount(LocalSearch search, String description, String email) throws IllegalArgumentException{ + if (search == null) { + throw new IllegalArgumentException("Provided LocalSearch was null"); + } + + this.mSearch = search; + this.mDescription = description; + this.mEmail = email; + } + + @Override + public synchronized String getEmail() { + return mEmail; + } + + @Override + public synchronized void setEmail(String email) { + this.mEmail = email; + } + + @Override + public String getDescription() { + return mDescription; + } + + @Override + public void setDescription(String description) { + this.mDescription = description; + } + + public LocalSearch getRelatedSearch() { + return mSearch; + } + + @Override + /* + * This will only be used when accessed as an Account. If that + * is the case we don't want to return the uuid of a real account since + * this is posing as a fake meta-account. If this object is accesed as + * a Search then methods from LocalSearch will be called which do handle + * things nice. + */ + public String getUuid() { + if (mFakeUuid == null){ + mFakeUuid = UUID.randomUUID().toString(); + } + return mFakeUuid; + } +} diff --git a/src/com/fsck/k9/activity/SearchModifier.java b/src/com/fsck/k9/search/SearchModifier.java similarity index 90% rename from src/com/fsck/k9/activity/SearchModifier.java rename to src/com/fsck/k9/search/SearchModifier.java index 8b610ff6e..536fee51a 100644 --- a/src/com/fsck/k9/activity/SearchModifier.java +++ b/src/com/fsck/k9/search/SearchModifier.java @@ -1,10 +1,10 @@ -package com.fsck.k9.activity; +package com.fsck.k9.search; import com.fsck.k9.R; import com.fsck.k9.mail.Flag; /** - * This enum represents filtering parameters used by {@link com.fsck.k9.SearchAccount}. + * This enum represents filtering parameters used by {@link com.fsck.k9.search.SearchAccount}. */ enum SearchModifier { FLAGGED(R.string.flagged_modifier, new Flag[]{Flag.FLAGGED}, null),