1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-11 12:05:06 -05:00

Add new SearchAccount class and move it together with SearchModifier to the search package ( refactor ).

This commit is contained in:
Sander Bogaert 2012-10-13 14:03:40 -04:00
parent 235e1f913b
commit f550aaefb5
6 changed files with 71 additions and 157 deletions

View File

@ -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;
}
}

View File

@ -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;
/**

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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),